Class: LanguageOperator::Agent::MetadataCollector
- Inherits:
-
Object
- Object
- LanguageOperator::Agent::MetadataCollector
- Includes:
- Loggable
- Defined in:
- lib/language_operator/agent/metadata_collector.rb
Overview
Agent Metadata Collector
Collects runtime and configuration metadata about an agent for use in persona-driven system prompts and conversation context.
Provides information about:
- Agent identity (name, description, persona)
- Runtime environment (cluster, namespace, mode)
- Operational state (uptime, workspace, status)
- Configuration details (capabilities, constraints)
Instance Attribute Summary collapse
-
#agent ⇒ Object
readonly
Returns the value of attribute agent.
-
#start_time ⇒ Object
readonly
Returns the value of attribute start_time.
Instance Method Summary collapse
-
#collect ⇒ Hash
Collect all available metadata.
-
#collect_capabilities ⇒ Hash
Collect agent capabilities and constraints.
-
#collect_environment ⇒ Hash
Collect deployment environment information.
-
#collect_identity ⇒ Hash
Collect basic identity information.
-
#collect_operational ⇒ Hash
Collect operational state information.
-
#collect_runtime ⇒ Hash
Collect runtime environment information.
-
#initialize(agent) ⇒ MetadataCollector
constructor
Initialize metadata collector.
-
#summary_for_prompt ⇒ Hash
Get formatted summary suitable for system prompts.
Methods included from Loggable
Constructor Details
#initialize(agent) ⇒ MetadataCollector
Initialize metadata collector
31 32 33 34 35 |
# File 'lib/language_operator/agent/metadata_collector.rb', line 31 def initialize(agent) @agent = agent @start_time = Time.now @logger = logger end |
Instance Attribute Details
#agent ⇒ Object (readonly)
Returns the value of attribute agent.
26 27 28 |
# File 'lib/language_operator/agent/metadata_collector.rb', line 26 def agent @agent end |
#start_time ⇒ Object (readonly)
Returns the value of attribute start_time.
26 27 28 |
# File 'lib/language_operator/agent/metadata_collector.rb', line 26 def start_time @start_time end |
Instance Method Details
#collect ⇒ Hash
Collect all available metadata
40 41 42 43 44 45 46 47 48 |
# File 'lib/language_operator/agent/metadata_collector.rb', line 40 def collect { identity: collect_identity, runtime: collect_runtime, environment: collect_environment, operational: collect_operational, capabilities: collect_capabilities } end |
#collect_capabilities ⇒ Hash
Collect agent capabilities and constraints
113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'lib/language_operator/agent/metadata_collector.rb', line 113 def collect_capabilities config = @agent.config || {} # Extract MCP server tools if available tools = [] if @agent.respond_to?(:servers_info) @agent.servers_info.each do |server| tools << { server: server[:name], tool_count: server[:tool_count] || 0 } end end # Extract constraints if configured constraints = config.dig('constraints') || {} { tools: tools, total_tools: tools.sum { |t| t[:tool_count] }, constraints: constraints.empty? ? nil : constraints, llm_provider: config.dig('llm', 'provider') || ENV.fetch('LLM_PROVIDER', 'unknown'), llm_model: config.dig('llm', 'model') || ENV.fetch('MODEL', 'unknown') } end |
#collect_environment ⇒ Hash
Collect deployment environment information
82 83 84 85 86 87 88 89 90 |
# File 'lib/language_operator/agent/metadata_collector.rb', line 82 def collect_environment { cluster: ENV.fetch('AGENT_CLUSTER', nil), namespace: ENV.fetch('AGENT_NAMESPACE', ENV.fetch('KUBERNETES_NAMESPACE', nil)), workspace_path: @agent.workspace_path, kubernetes_enabled: !ENV.fetch('KUBERNETES_SERVICE_HOST', nil).nil?, telemetry_enabled: !ENV.fetch('OTEL_EXPORTER_OTLP_ENDPOINT', nil).nil? } end |
#collect_identity ⇒ Hash
Collect basic identity information
53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/language_operator/agent/metadata_collector.rb', line 53 def collect_identity config = @agent.config || {} agent_config = config.dig('agent') || {} { name: ENV.fetch('AGENT_NAME', agent_config['name'] || 'unknown'), description: agent_config['instructions'] || agent_config['description'] || 'AI Agent', persona: agent_config['persona'] || ENV.fetch('PERSONA_NAME', nil), mode: @agent.mode || 'unknown', version: LanguageOperator::VERSION } end |
#collect_operational ⇒ Hash
Collect operational state information
95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/language_operator/agent/metadata_collector.rb', line 95 def collect_operational status = determine_agent_status { status: status, ready: status == 'ready', mode: @agent.mode, workspace: { path: @agent.workspace_path, available: @agent.workspace_available?, writable: workspace_writable? } } end |
#collect_runtime ⇒ Hash
Collect runtime environment information
69 70 71 72 73 74 75 76 77 |
# File 'lib/language_operator/agent/metadata_collector.rb', line 69 def collect_runtime { uptime: calculate_uptime, started_at: @start_time.iso8601, process_id: Process.pid, workspace_available: @agent.workspace_available?, mcp_servers_connected: @agent.respond_to?(:servers_info) ? @agent.servers_info.length : 0 } end |
#summary_for_prompt ⇒ Hash
Get formatted summary suitable for system prompts
142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/language_operator/agent/metadata_collector.rb', line 142 def summary_for_prompt = collect identity = [:identity] runtime = [:runtime] environment = [:environment] operational = [:operational] capabilities = [:capabilities] { agent_name: identity[:name], agent_description: identity[:description], agent_mode: identity[:mode], uptime: runtime[:uptime], cluster: environment[:cluster], namespace: environment[:namespace], status: operational[:status], workspace_available: operational[:ready], tool_count: capabilities[:total_tools], llm_model: capabilities[:llm_model] } end |