Class: Soka::Agent
- Inherits:
-
Object
- Object
- Soka::Agent
- Includes:
- Soka::Agents::DSLMethods, Soka::Agents::HookManager, Soka::Agents::LLMBuilder, Soka::Agents::RetryHandler, Soka::Agents::ToolBuilder
- Defined in:
- lib/soka/agent.rb
Overview
Base class for AI agents that use ReAct pattern
Instance Attribute Summary collapse
-
#engine ⇒ Object
readonly
Returns the value of attribute engine.
-
#instructions ⇒ Object
readonly
Returns the value of attribute instructions.
-
#llm ⇒ Object
readonly
Returns the value of attribute llm.
-
#memory ⇒ Object
readonly
Returns the value of attribute memory.
-
#think_in ⇒ Object
readonly
Returns the value of attribute think_in.
-
#thoughts_memory ⇒ Object
readonly
Returns the value of attribute thoughts_memory.
-
#tools ⇒ Object
readonly
Returns the value of attribute tools.
Instance Method Summary collapse
-
#apply_behavior_config(options) ⇒ Object
Apply behavior-related configuration.
-
#apply_configuration(options) ⇒ Object
Apply configuration options with defaults.
-
#apply_performance_config(options) ⇒ Object
Apply performance-related configuration.
-
#initialize(memory: nil, engine: Engines::React, **options) ⇒ Agent
constructor
Initialize a new Agent instance.
-
#run(input) {|event| ... } ⇒ Result
Run the agent with the given input.
Methods included from Soka::Agents::DSLMethods
Constructor Details
#initialize(memory: nil, engine: Engines::React, **options) ⇒ Agent
Initialize a new Agent instance
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/soka/agent.rb', line 23 def initialize(memory: nil, engine: Engines::React, **) @memory = initialize_memory(memory) @thoughts_memory = ThoughtsMemory.new @engine = engine # Initialize components @llm = build_llm() @tools = build_tools # Apply configuration with clear defaults apply_configuration() end |
Instance Attribute Details
#engine ⇒ Object (readonly)
Returns the value of attribute engine.
12 13 14 |
# File 'lib/soka/agent.rb', line 12 def engine @engine end |
#instructions ⇒ Object (readonly)
Returns the value of attribute instructions.
12 13 14 |
# File 'lib/soka/agent.rb', line 12 def instructions @instructions end |
#llm ⇒ Object (readonly)
Returns the value of attribute llm.
12 13 14 |
# File 'lib/soka/agent.rb', line 12 def llm @llm end |
#memory ⇒ Object (readonly)
Returns the value of attribute memory.
12 13 14 |
# File 'lib/soka/agent.rb', line 12 def memory @memory end |
#think_in ⇒ Object (readonly)
Returns the value of attribute think_in.
12 13 14 |
# File 'lib/soka/agent.rb', line 12 def think_in @think_in end |
#thoughts_memory ⇒ Object (readonly)
Returns the value of attribute thoughts_memory.
12 13 14 |
# File 'lib/soka/agent.rb', line 12 def thoughts_memory @thoughts_memory end |
#tools ⇒ Object (readonly)
Returns the value of attribute tools.
12 13 14 |
# File 'lib/soka/agent.rb', line 12 def tools @tools end |
Instance Method Details
#apply_behavior_config(options) ⇒ Object
Apply behavior-related configuration
53 54 55 56 |
# File 'lib/soka/agent.rb', line 53 def apply_behavior_config() @instructions = .fetch(:instructions) { resolve_instructions } @think_in = .fetch(:think_in) { self.class._think_in } || 'en' end |
#apply_configuration(options) ⇒ Object
Apply configuration options with defaults
38 39 40 41 |
# File 'lib/soka/agent.rb', line 38 def apply_configuration() apply_performance_config() apply_behavior_config() end |
#apply_performance_config(options) ⇒ Object
Apply performance-related configuration
45 46 47 48 49 |
# File 'lib/soka/agent.rb', line 45 def apply_performance_config() @max_iterations = .fetch(:max_iterations) do self.class._max_iterations || Soka.configuration.performance.max_iterations end end |
#run(input) {|event| ... } ⇒ Result
Run the agent with the given input
62 63 64 65 66 67 68 69 |
# File 'lib/soka/agent.rb', line 62 def run(input, &) validate_input(input) execute_reasoning(input, &) rescue ArgumentError raise # Re-raise ArgumentError without handling rescue StandardError => e handle_error(e, input) end |