HandoffStrategy trait you can implement for your own. The orchestrator handles the boring parts (input routing, output capture, error propagation); you decide how the agents talk to each other.
What it is
strategy is a value (not a string or enum), which means each strategy is its own type with its own configuration knobs.
Pick a strategy
- Sequential
- Supervisor
- ParallelVote
- RoundRobin
Each agent receives the previous agent’s output. Useful for pipelines where one specialist hands off to the next.Source:
examples/v2/08_ollama_multi_agent.rs.How it works
- Each strategy is a struct that implements
HandoffStrategy. That trait has one required async method:run(&self, agents, input, bus) -> Result<AgentResponse>. The strategy decides everything that happens between the user’s input and the final response. - Agents inside the orchestrator are still
Agents. Each runs its own loop with its own memory, tools, and middleware. The orchestrator only decides who runs next. - Errors propagate. If an agent inside the orchestrator returns
Err, the orchestrator returnsErr. Wrap a sub-agent’s client withwith_fallbackif you want graceful degradation. - The orchestrator returns an
AgentResponse. Same shape as a single agent — drop-in callers don’t change. - Other strategies in the box. Beyond the four covered above,
cognis::multi_agentalso shipsHierarchical(manager → workers tree) andConsensus(quorum-based voting).
Custom handoff
ImplementHandoffStrategy for full control:
AgentBus and AgentEventBus
For looser coupling than orchestration — broadcast / subscribe between agents — Cognis has two pub/sub primitives:AgentBus— generic typed pub/sub. AnyT: Clone + Send + Sync + 'staticcan be a topic value.AgentEventBus— pre-typed forAgentEvents emitted during the loop (request started, tool called, response produced, …).
See also
Patterns → Multi-agent debate
A worked propose-critique-revise loop.
Patterns → Research assistant
Sequential planner → researcher → writer.
Middleware
SubagentMiddleware for inline subagent spawning from a single parent loop.