Skip to main content

car_multi/
lib.rs

1//! Multi-agent coordination for Common Agent Runtime.
2//!
3//! Provides six coordination patterns:
4//!
5//! | Pattern | Description |
6//! |---------|-------------|
7//! | **Swarm** | N agents on the same problem (parallel, sequential, or debate) |
8//! | **Pipeline** | Linear chain — each agent's output feeds the next |
9//! | **Supervisor** | One agent reviews workers, iterates until approval |
10//! | **Delegator** | Main agent spawns specialists mid-run via a tool |
11//! | **MapReduce** | Fan-out to N mappers, reduce into a single result |
12//! | **Vote** | N agents answer independently, majority wins |
13//!
14//! ## How agents communicate
15//!
16//! Agents communicate through three mechanisms:
17//!
18//! 1. **Shared state** — all agents in a coordination group share the same
19//!    `Arc<StateStore>` and `Arc<EventLog>` via `SharedInfra`. Agents can read
20//!    each other's state writes.
21//!
22//! 2. **Task enrichment** — orchestrators pass prior agents' outputs into the
23//!    next agent's task prompt (e.g., sequential swarm, supervisor feedback).
24//!
25//! 3. **Mailbox** — async channel-based messaging for real-time inter-agent
26//!    communication during execution.
27//!
28//! ## The AgentRunner trait
29//!
30//! Since the runtime doesn't own the model, the caller implements `AgentRunner`
31//! to drive the model loop. `car-multi` orchestrates *when* and *how* agents run;
32//! the caller decides *what* each agent does.
33//!
34//! ```rust,ignore
35//! use car_multi::{AgentRunner, AgentSpec, AgentOutput, Mailbox, MultiError};
36//! use car_engine::Runtime;
37//!
38//! struct MyRunner { /* OpenAI client, etc. */ }
39//!
40//! #[async_trait::async_trait]
41//! impl AgentRunner for MyRunner {
42//!     async fn run(
43//!         &self,
44//!         spec: &AgentSpec,
45//!         task: &str,
46//!         runtime: &Runtime,
47//!         mailbox: &Mailbox,
48//!     ) -> Result<AgentOutput, MultiError> {
49//!         // 1. Call your LLM with spec.system_prompt + task
50//!         // 2. Parse response into ActionProposal
51//!         // 3. runtime.execute(&proposal).await
52//!         // 4. Return AgentOutput
53//!         todo!()
54//!     }
55//! }
56//! ```
57
58pub mod error;
59pub mod mailbox;
60pub mod patterns;
61pub mod runner;
62pub mod shared;
63pub mod task_context;
64pub mod types;
65
66// Re-exports for convenience
67pub use error::MultiError;
68pub use mailbox::Mailbox;
69pub use runner::AgentRunner;
70pub use shared::SharedInfra;
71pub use task_context::{AgentContext, TaskScope};
72pub use types::{AgentOutput, AgentSpec, Message, MessageKind};
73
74pub use patterns::delegator::{Delegator, DelegatorResult};
75pub use patterns::fleet::{Fleet, FleetResult};
76pub use patterns::map_reduce::{MapReduce, MapReduceResult};
77pub use patterns::pipeline::{Pipeline, PipelineResult};
78pub use patterns::supervisor::{Supervisor, SupervisorResult};
79pub use patterns::swarm::{Swarm, SwarmMode, SwarmResult};
80pub use patterns::vote::{Vote, VoteResult};
81
82// === Umbrella re-exports (car#205) ===
83//
84// car-multi re-exports the built-in commodity agents from
85// car-agents so external Rust consumers (tokhn) can construct a
86// coordinated agent system from a single crate dep. car-agents
87// stays in the workspace as a separate compile unit; this is a
88// publish-set boundary, not a workspace boundary.
89
90pub use car_agents::{
91    coordinator::{CoordinationPlan, Pattern},
92    Coordinator, PlannerAgent, Researcher, Summarizer, Verifier,
93};