Class: Aiko::Agent
- Inherits:
-
Object
- Object
- Aiko::Agent
- Defined in:
- lib/aiko/agent.rb
Constant Summary collapse
- MAX_ITERATIONS_MESSAGE =
"(最大ループ回数に達したため処理を打ち切りました)"
Instance Attribute Summary collapse
-
#conversation ⇒ Object
readonly
Returns the value of attribute conversation.
Instance Method Summary collapse
-
#initialize(llm:, registry:, callbacks:, conversation:, max_iterations: 20) ⇒ Agent
constructor
A new instance of Agent.
- #run(user_input) ⇒ Object
Constructor Details
#initialize(llm:, registry:, callbacks:, conversation:, max_iterations: 20) ⇒ Agent
Returns a new instance of Agent.
9 10 11 12 13 14 15 |
# File 'lib/aiko/agent.rb', line 9 def initialize(llm:, registry:, callbacks:, conversation:, max_iterations: 20) @llm = llm @registry = registry @callbacks = callbacks @conversation = conversation @max_iterations = max_iterations end |
Instance Attribute Details
#conversation ⇒ Object (readonly)
Returns the value of attribute conversation.
7 8 9 |
# File 'lib/aiko/agent.rb', line 7 def conversation @conversation end |
Instance Method Details
#run(user_input) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/aiko/agent.rb', line 17 def run(user_input) @conversation.add_user(user_input) @max_iterations.times do response = request_completion return final_answer(response) unless response.tool_calls? report_progress(response) execute_tool_calls(response.tool_calls) end @callbacks.on_assistant_text(MAX_ITERATIONS_MESSAGE) MAX_ITERATIONS_MESSAGE end |