Class: Flunky::Agent
- Inherits:
-
Object
- Object
- Flunky::Agent
- Defined in:
- lib/flunky/agent.rb
Overview
Optional observe/decide/act loop. The model is injected and must respond to #call(messages:, tools:) returning { text:, tool_calls: [{ id:, name:, arguments: }] }. Keeping the contract vendor-neutral is the whole point: the gem never talks to a model vendor, the caller’s adapter does.
Instance Method Summary collapse
-
#initialize(session, model:) ⇒ Agent
constructor
A new instance of Agent.
-
#run(goal, max_steps: 10) ⇒ Object
Drive toward
goal, stopping when the model stops asking for tools or the step budget runs out.
Constructor Details
Instance Method Details
#run(goal, max_steps: 10) ⇒ Object
Drive toward goal, stopping when the model stops asking for tools or the step budget runs out. Returns the transcript of messages exchanged.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/flunky/agent.rb', line 17 def run(goal, max_steps: 10) = [{ role: "user", content: seed_prompt(goal) }] max_steps.times do response = @model.call(messages: , tools: @tools.definitions) << { role: "assistant", content: response[:text], tool_calls: response[:tool_calls] } calls = response[:tool_calls] || [] break if calls.empty? results = calls.map { |call| run_tool(call) } << { role: "tool", content: results } end end |