Class: Agentic::Agent
- Inherits:
-
Object
- Object
- Agentic::Agent
- Includes:
- FactoryMethods
- Defined in:
- lib/agentic/agent.rb
Class Method Summary collapse
-
.from_h(hash) ⇒ Agent
Creates an agent from a hash representation.
Instance Method Summary collapse
-
#add_capability(capability_name, version = nil) ⇒ Boolean
Adds a capability to the agent.
-
#capability_specification(capability_name) ⇒ CapabilitySpecification?
Gets the specification for a capability.
-
#execute(task) ⇒ Object
Executes a task using this agent.
-
#execute_capability(capability_name, inputs = {}) ⇒ Hash
Executes a capability.
-
#execute_with_schema(prompt, schema) ⇒ Object
Executes a prompt with structured output schema.
-
#has_capability?(capability_name) ⇒ Boolean
Checks if the agent has a capability.
-
#initialize ⇒ Agent
constructor
Initialize with default values.
-
#to_h ⇒ Hash
Converts the agent to a hash representation.
Methods included from FactoryMethods
Constructor Details
#initialize ⇒ Agent
Initialize with default values
13 14 15 16 17 |
# File 'lib/agentic/agent.rb', line 13 def initialize @capabilities = {} @tools = Set.new @llm_client = nil end |
Class Method Details
.from_h(hash) ⇒ Agent
Creates an agent from a hash representation
125 126 127 128 129 130 131 132 133 134 |
# File 'lib/agentic/agent.rb', line 125 def self.from_h(hash) new do |a| a.role = hash[:role] || hash["role"] a.purpose = hash[:purpose] || hash["purpose"] a.backstory = hash[:backstory] || hash["backstory"] end # Note: Capabilities need to be added separately after creation # since they require the registry to be available end |
Instance Method Details
#add_capability(capability_name, version = nil) ⇒ Boolean
Adds a capability to the agent
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/agentic/agent.rb', line 60 def add_capability(capability_name, version = nil) # Get the capability from the registry registry = AgentCapabilityRegistry.instance capability = registry.get(capability_name, version) raise "Capability not found: #{capability_name}" unless capability # Get the provider provider = registry.get_provider(capability_name, version) raise "Provider not found for capability: #{capability_name}" unless provider # Add to the agent's capabilities @capabilities[capability_name] = { specification: capability, provider: provider } # Also add to tools for backward compatibility @tools.add(capability_name.to_sym) true end |
#capability_specification(capability_name) ⇒ CapabilitySpecification?
Gets the specification for a capability
92 93 94 95 |
# File 'lib/agentic/agent.rb', line 92 def capability_specification(capability_name) return nil unless @capabilities[capability_name] @capabilities[capability_name][:specification] end |
#execute(task) ⇒ Object
Executes a task using this agent
22 23 24 25 26 27 28 29 30 |
# File 'lib/agentic/agent.rb', line 22 def execute(task) if task.is_a?(String) # Simple string prompt execute_prompt(task) else # Task object task.perform(self) end end |
#execute_capability(capability_name, inputs = {}) ⇒ Hash
Executes a capability
101 102 103 104 105 106 107 108 109 |
# File 'lib/agentic/agent.rb', line 101 def execute_capability(capability_name, inputs = {}) raise "Capability not available: #{capability_name}" unless @capabilities.key?(capability_name) # Get the provider provider = @capabilities[capability_name][:provider] # Execute the capability provider.execute(inputs) end |
#execute_with_schema(prompt, schema) ⇒ Object
Executes a prompt with structured output schema
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/agentic/agent.rb', line 36 def execute_with_schema(prompt, schema) # If the agent has a text_generation capability, use it if has_capability?("text_generation") # For now, text_generation capabilities don't support schemas # Fall back to regular execution execute_capability("text_generation", {prompt: prompt})[:response] elsif @llm_client # Use the configured LLM client with structured output response = @llm_client.complete((prompt), output_schema: schema) if response.successful? response.content else raise "LLM execution failed: #{response.error.}" end else # Fallback error - agent not properly configured raise "Agent not configured with LLM capabilities. Use DefaultAgentProvider or configure llm_client directly." end end |
#has_capability?(capability_name) ⇒ Boolean
Checks if the agent has a capability
85 86 87 |
# File 'lib/agentic/agent.rb', line 85 def has_capability?(capability_name) @capabilities.key?(capability_name) end |
#to_h ⇒ Hash
Converts the agent to a hash representation
113 114 115 116 117 118 119 120 |
# File 'lib/agentic/agent.rb', line 113 def to_h { role: @role, purpose: @purpose, backstory: @backstory, capability_names: @capabilities.keys } end |