Skip to main content

car_multi/
runner.rs

1//! AgentRunner trait — the caller's model loop abstraction.
2//!
3//! Since the runtime doesn't own the model, the caller implements this trait
4//! to drive the model loop (call LLM, parse response, submit proposals, repeat).
5//! car-multi orchestrates *when* and *how* agents run, but the caller decides
6//! *what* each agent does.
7
8use crate::error::MultiError;
9use crate::mailbox::Mailbox;
10use crate::types::{AgentOutput, AgentSpec};
11use car_engine::Runtime;
12
13/// Trait for running an agent to completion.
14///
15/// Implement this with your model loop. For example:
16/// 1. Initialize chat with `spec.system_prompt`
17/// 2. Send `task` to the model
18/// 3. Parse response into `ActionProposal`
19/// 4. Call `runtime.execute(&proposal)`
20/// 5. Format results back to model
21/// 6. Repeat until model says "done"
22/// 7. Return `AgentOutput`
23#[async_trait::async_trait]
24pub trait AgentRunner: Send + Sync {
25    async fn run(
26        &self,
27        spec: &AgentSpec,
28        task: &str,
29        runtime: &Runtime,
30        mailbox: &Mailbox,
31    ) -> Result<AgentOutput, MultiError>;
32}