Class: Phronomy::Agent::Runner
- Inherits:
-
Object
- Object
- Phronomy::Agent::Runner
- Defined in:
- lib/phronomy/agent/runner.rb
Overview
Orchestrates a multi-agent conversation by routing between agents based on handoff tool calls detected in each agent's conversation history.
Runner configures handoff tools on source agent instances at construction time, then coordinates invocations: after each agent turn it inspects the returned messages for a handoff sentinel and routes accordingly.
Constant Summary collapse
- MAX_HANDOFFS =
Maximum number of agent handoffs allowed per invoke call.
20
Instance Attribute Summary collapse
-
#agents ⇒ Object
readonly
Returns the value of attribute agents.
Instance Method Summary collapse
-
#initialize(agents:, routes: {}) ⇒ Runner
constructor
A new instance of Runner.
-
#invoke(input, config: {}) ⇒ Hash
Invokes the runner with the given input, routing between agents as needed.
Constructor Details
#initialize(agents:, routes: {}) ⇒ Runner
Returns a new instance of Runner.
33 34 35 36 37 38 39 40 |
# File 'lib/phronomy/agent/runner.rb', line 33 def initialize(agents:, routes: {}) @agents = Array(agents) raise ArgumentError, "At least one agent is required" if @agents.empty? @entry_agent = @agents.first @sentinel_map = {} build_handoffs(routes) end |
Instance Attribute Details
#agents ⇒ Object (readonly)
Returns the value of attribute agents.
26 27 28 |
# File 'lib/phronomy/agent/runner.rb', line 26 def agents @agents end |
Instance Method Details
#invoke(input, config: {}) ⇒ Hash
Invokes the runner with the given input, routing between agents as needed. Stops when an agent's turn produces no handoff signal, or when MAX_HANDOFFS is reached (raises HandoffError in that case).
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/phronomy/agent/runner.rb', line 50 def invoke(input, config: {}) current = @entry_agent handoffs_taken = 0 loop do result = current.invoke(input, config: config) target = find_handoff_target(result[:messages]) return result.merge(agent: current) unless target if handoffs_taken >= MAX_HANDOFFS raise Phronomy::HandoffError, "Exceeded maximum handoffs (#{MAX_HANDOFFS})" end current = target handoffs_taken += 1 end end |