//! Multi-agent coordination for Common Agent Runtime.
//!
//! Provides six coordination patterns:
//!
//! | Pattern | Description |
//! |---------|-------------|
//! | **Swarm** | N agents on the same problem (parallel, sequential, or debate) |
//! | **Pipeline** | Linear chain — each agent's output feeds the next |
//! | **Supervisor** | One agent reviews workers, iterates until approval |
//! | **Delegator** | Main agent spawns specialists mid-run via a tool |
//! | **MapReduce** | Fan-out to N mappers, reduce into a single result |
//! | **Vote** | N agents answer independently, majority wins |
//!
//! ## How agents communicate
//!
//! Agents communicate through three mechanisms:
//!
//! 1. **Shared state** — all agents in a coordination group share the same
//!    `Arc<StateStore>` and `Arc<EventLog>` via `SharedInfra`. Agents can read
//!    each other's state writes.
//!
//! 2. **Task enrichment** — orchestrators pass prior agents' outputs into the
//!    next agent's task prompt (e.g., sequential swarm, supervisor feedback).
//!
//! 3. **Mailbox** — async channel-based messaging for real-time inter-agent
//!    communication during execution.
//!
//! ## The AgentRunner trait
//!
//! Since the runtime doesn't own the model, the caller implements `AgentRunner`
//! to drive the model loop. `car-multi` orchestrates *when* and *how* agents run;
//! the caller decides *what* each agent does.
//!
//! ```rust,ignore
//! use car_multi::{AgentRunner, AgentSpec, AgentOutput, Mailbox, MultiError};
//! use car_engine::Runtime;
//!
//! struct MyRunner { /* OpenAI client, etc. */ }
//!
//! #[async_trait::async_trait]
//! impl AgentRunner for MyRunner {
//!     async fn run(
//!         &self,
//!         spec: &AgentSpec,
//!         task: &str,
//!         runtime: &Runtime,
//!         mailbox: &Mailbox,
//!     ) -> Result<AgentOutput, MultiError> {
//!         // 1. Call your LLM with spec.system_prompt + task
//!         // 2. Parse response into ActionProposal
//!         // 3. runtime.execute(&proposal).await
//!         // 4. Return AgentOutput
//!         todo!()
//!     }
//! }
//! ```

pub mod error;
pub mod mailbox;
pub mod patterns;
pub mod runner;
pub mod shared;
pub mod task_context;
pub mod types;

// Re-exports for convenience
pub use error::MultiError;
pub use mailbox::Mailbox;
pub use runner::AgentRunner;
pub use shared::SharedInfra;
pub use task_context::{AgentContext, TaskScope};
pub use types::{AgentOutput, AgentSpec, Message, MessageKind};

pub use patterns::delegator::{Delegator, DelegatorResult};
pub use patterns::fleet::{Fleet, FleetResult};
pub use patterns::map_reduce::{MapReduce, MapReduceResult};
pub use patterns::pipeline::{Pipeline, PipelineResult};
pub use patterns::supervisor::{Supervisor, SupervisorResult};
pub use patterns::swarm::{Swarm, SwarmMode, SwarmResult};
pub use patterns::vote::{Vote, VoteResult};

// === Umbrella re-exports (car#205) ===
//
// car-multi re-exports the built-in commodity agents from
// car-agents so external Rust consumers (tokhn) can construct a
// coordinated agent system from a single crate dep. car-agents
// stays in the workspace as a separate compile unit; this is a
// publish-set boundary, not a workspace boundary.

pub use car_agents::{
    coordinator::{CoordinationPlan, Pattern},
    Coordinator, PlannerAgent, Researcher, Summarizer, Verifier,
};
