Class: Kreator::AgentLoop
- Inherits:
-
Object
- Object
- Kreator::AgentLoop
- Defined in:
- lib/kreator/agent_loop.rb
Defined Under Namespace
Classes: Error
Constant Summary collapse
- DEFAULT_SYSTEM_PROMPT =
"You are Kreator, a concise and practical coding assistant."- DEFAULT_MAX_TOOL_ITERATIONS =
16
Instance Attribute Summary collapse
-
#context ⇒ Object
readonly
Returns the value of attribute context.
-
#event_bus ⇒ Object
readonly
Returns the value of attribute event_bus.
-
#last_messages ⇒ Object
readonly
Returns the value of attribute last_messages.
-
#last_usage ⇒ Object
readonly
Returns the value of attribute last_usage.
-
#model ⇒ Object
readonly
Returns the value of attribute model.
-
#provider ⇒ Object
readonly
Returns the value of attribute provider.
-
#system_prompt ⇒ Object
readonly
Returns the value of attribute system_prompt.
-
#tool_registry ⇒ Object
readonly
Returns the value of attribute tool_registry.
-
#tools ⇒ Object
readonly
Returns the value of attribute tools.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ AgentLoop
constructor
A new instance of AgentLoop.
- #run(prompt:, messages: [], signal: nil) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ AgentLoop
Returns a new instance of AgentLoop.
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/kreator/agent_loop.rb', line 10 def initialize( = {}) @provider = .fetch(:provider) @event_bus = .fetch(:event_bus, EventBus.new) @system_prompt = .fetch(:system_prompt, DEFAULT_SYSTEM_PROMPT) @model = .fetch(:model, nil) @tool_registry = normalize_tools(.fetch(:tools, nil)) @tools = @tool_registry.to_a @context = .fetch(:context, ToolContext.new) @max_tool_iterations = .fetch(:max_tool_iterations, DEFAULT_MAX_TOOL_ITERATIONS) @last_usage = nil end |
Instance Attribute Details
#context ⇒ Object (readonly)
Returns the value of attribute context.
8 9 10 |
# File 'lib/kreator/agent_loop.rb', line 8 def context @context end |
#event_bus ⇒ Object (readonly)
Returns the value of attribute event_bus.
8 9 10 |
# File 'lib/kreator/agent_loop.rb', line 8 def event_bus @event_bus end |
#last_messages ⇒ Object (readonly)
Returns the value of attribute last_messages.
8 9 10 |
# File 'lib/kreator/agent_loop.rb', line 8 def @last_messages end |
#last_usage ⇒ Object (readonly)
Returns the value of attribute last_usage.
8 9 10 |
# File 'lib/kreator/agent_loop.rb', line 8 def last_usage @last_usage end |
#model ⇒ Object (readonly)
Returns the value of attribute model.
8 9 10 |
# File 'lib/kreator/agent_loop.rb', line 8 def model @model end |
#provider ⇒ Object (readonly)
Returns the value of attribute provider.
8 9 10 |
# File 'lib/kreator/agent_loop.rb', line 8 def provider @provider end |
#system_prompt ⇒ Object (readonly)
Returns the value of attribute system_prompt.
8 9 10 |
# File 'lib/kreator/agent_loop.rb', line 8 def system_prompt @system_prompt end |
#tool_registry ⇒ Object (readonly)
Returns the value of attribute tool_registry.
8 9 10 |
# File 'lib/kreator/agent_loop.rb', line 8 def tool_registry @tool_registry end |
#tools ⇒ Object (readonly)
Returns the value of attribute tools.
8 9 10 |
# File 'lib/kreator/agent_loop.rb', line 8 def tools @tools end |
Instance Method Details
#run(prompt:, messages: [], signal: nil) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/kreator/agent_loop.rb', line 22 def run(prompt:, messages: [], signal: nil) = .map { || () } << Message.user(prompt) @last_usage = nil publish("agent_start", model: model, provider: provider_name, capabilities: provider_capabilities) = run_until_complete(, signal: signal) publish("turn_end", message: .to_h) publish("agent_end", message: .to_h) @last_messages = rescue StandardError => e publish("agent_end", error: error_hash(e)) raise end |