Class: LanguageOperator::Agent::Base
- Inherits:
-
Client::Base
- Object
- Client::Base
- LanguageOperator::Agent::Base
- Includes:
- Instrumentation
- Defined in:
- lib/language_operator/agent/base.rb
Overview
Base Agent Class
Extends LanguageOperator::Client::Base with agent-specific functionality including:
- Workspace integration
- Goal-directed execution
- Autonomous operation modes
Constant Summary
Constants included from Client::CostCalculator
Client::CostCalculator::MODEL_PRICING
Constants included from Retryable
Retryable::DEFAULT_BASE_DELAY, Retryable::DEFAULT_MAX_ATTEMPTS, Retryable::DEFAULT_MAX_DELAY
Instance Attribute Summary collapse
-
#kubernetes_client ⇒ Object
readonly
Returns the value of attribute kubernetes_client.
-
#mode ⇒ Object
readonly
Returns the value of attribute mode.
-
#workspace_path ⇒ Object
readonly
Returns the value of attribute workspace_path.
Attributes inherited from Client::Base
Instance Method Summary collapse
-
#execute_goal(goal) ⇒ String
Execute a single goal.
-
#initialize(config) ⇒ Base
constructor
Initialize the agent.
-
#run ⇒ void
Run the agent in its configured mode.
-
#workspace_available? ⇒ Boolean
Check if workspace is available.
Methods inherited from Client::Base
#cleanup_connections, #clear_history!, #connect!, #connected?, #debug?, #send_message, #servers_info, #stream_message, #tools
Methods included from Client::CostCalculator
Methods included from Retryable
#with_retry, #with_retry_or_nil
Methods included from Loggable
Constructor Details
#initialize(config) ⇒ Base
Initialize the agent
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/language_operator/agent/base.rb', line 30 def initialize(config) super # Log version logger.info "Language Operator v#{LanguageOperator::VERSION}" # Initialize OpenTelemetry LanguageOperator::Agent::Telemetry.configure otel_enabled = !ENV.fetch('OTEL_EXPORTER_OTLP_ENDPOINT', nil).nil? logger.info "OpenTelemetry #{otel_enabled ? 'enabled' : 'disabled'}" @workspace_path = ENV.fetch('WORKSPACE_PATH', '/workspace') @mode = agent_mode_with_default @executor = nil # Initialize Kubernetes client for event emission (only in K8s environments) @kubernetes_client = begin LanguageOperator::Kubernetes::Client.instance if ENV.fetch('KUBERNETES_SERVICE_HOST', nil) rescue StandardError => e logger.warn('Failed to initialize Kubernetes client', error: e.) nil end end |
Instance Attribute Details
#kubernetes_client ⇒ Object (readonly)
Returns the value of attribute kubernetes_client.
25 26 27 |
# File 'lib/language_operator/agent/base.rb', line 25 def kubernetes_client @kubernetes_client end |
#mode ⇒ Object (readonly)
Returns the value of attribute mode.
25 26 27 |
# File 'lib/language_operator/agent/base.rb', line 25 def mode @mode end |
#workspace_path ⇒ Object (readonly)
Returns the value of attribute workspace_path.
25 26 27 |
# File 'lib/language_operator/agent/base.rb', line 25 def workspace_path @workspace_path end |
Instance Method Details
#execute_goal(goal) ⇒ String
Execute a single goal
88 89 90 91 |
# File 'lib/language_operator/agent/base.rb', line 88 def execute_goal(goal) @executor ||= Executor.new(self) @executor.execute(goal) end |
#run ⇒ void
This method returns an undefined value.
Run the agent in its configured mode
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/language_operator/agent/base.rb', line 57 def run # Normalize mode to canonical form normalized_mode = Constants.normalize_mode(@mode) with_span('agent.run', attributes: { 'agent.name' => ENV.fetch('AGENT_NAME', nil), 'agent.mode' => normalized_mode, 'agent.workspace_available' => workspace_available? }) do connect! case normalized_mode when 'autonomous' run_autonomous when 'scheduled' run_scheduled when 'reactive' run_reactive else raise "Unknown agent mode: #{normalized_mode}" end ensure # Flush telemetry for short-lived processes (scheduled mode) flush_telemetry if normalized_mode == 'scheduled' end end |
#workspace_available? ⇒ Boolean
Check if workspace is available
96 97 98 |
# File 'lib/language_operator/agent/base.rb', line 96 def workspace_available? File.directory?(@workspace_path) && File.writable?(@workspace_path) end |