Class: Chorus::Orchestrator
- Inherits:
-
Object
- Object
- Chorus::Orchestrator
- Defined in:
- lib/chorus/orchestrator.rb
Overview
Main entry point of Chorus. Ties together the Router, Context and Agents: for every incoming user message it picks an agent, builds that agent's context slice, calls it, and records the response.
Instance Attribute Summary collapse
-
#context ⇒ Chorus::Context
readonly
The shared conversation state.
Instance Method Summary collapse
-
#handle(user_message) ⇒ Hash
{agent: Symbol, response: String}. -
#initialize(client: Chorus::Client.new, router: Chorus::Router.new, context: Chorus::Context.new, agents: nil) ⇒ Orchestrator
constructor
A new instance of Orchestrator.
Constructor Details
#initialize(client: Chorus::Client.new, router: Chorus::Router.new, context: Chorus::Context.new, agents: nil) ⇒ Orchestrator
Returns a new instance of Orchestrator.
20 21 22 23 24 25 |
# File 'lib/chorus/orchestrator.rb', line 20 def initialize(client: Chorus::Client.new, router: Chorus::Router.new, context: Chorus::Context.new, agents: nil) @client = client @router = router @context = context @agents = agents || default_agents end |
Instance Attribute Details
#context ⇒ Chorus::Context (readonly)
Returns the shared conversation state.
14 15 16 |
# File 'lib/chorus/orchestrator.rb', line 14 def context @context end |
Instance Method Details
#handle(user_message) ⇒ Hash
Returns {agent: Symbol, response: String}.
29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/chorus/orchestrator.rb', line 29 def handle() agent_name = @router.route() agent = @agents.fetch(agent_name) { raise ArgumentError, "Unknown agent: #{agent_name}" } @context.(role: :user, content: ) context_slice = @context.slice_for(agent_name, ) response = agent.call(context_slice) @context.(role: :assistant, content: response, agent: agent_name) { agent: agent_name, response: response } end |