car-agents 0.55.0

Built-in commodity agents for Common Agent Runtime
Documentation
//! Built-in commodity agents for Common Agent Runtime.
//!
//! These are the agents every workflow needs but nobody should have to build.
//! They compose with car-multi's coordination patterns (swarm, pipeline,
//! supervisor) and use car-inference for model calls.
//!
//! ## Built-in Agents
//!
//! - **Researcher**: Search, read, gather → structured findings
//! - **Planner**: Goal → ordered action steps
//! - **Verifier**: Output + spec → pass/fail with reasons
//! - **Summarizer**: Long context → compressed handoff
//! - **Coordinator**: Goal → which agents + which pattern

pub mod coordinator;
pub mod planner;
pub mod researcher;
pub mod summarizer;
pub mod verifier;

pub use coordinator::Coordinator;
pub use planner::PlannerAgent;
pub use researcher::Researcher;
pub use summarizer::Summarizer;
pub use verifier::Verifier;

pub use car_search::indexer;
/// Compatibility re-export: `ReferenceMiner` / `Indexer` moved to the
/// dedicated `car-search` crate. This alias keeps callers that imported
/// `car_agents::reference_miner::*` working for one release. New code
/// should import from `car_search` directly.
pub use car_search::reference_miner;
pub use car_search::{
    CodeReference, IndexReport, Indexer, MiningError, MiningFilters, MiningQuery, MiningScope,
    ReferenceMiner,
};

use car_inference::{GenerateRequest, InferenceEngine, InferenceError, InferenceResult};
use std::future::Future;
use std::pin::Pin;
use std::sync::Arc;

/// Future returned by an injected built-in-agent generator.
pub type AgentGenerationFuture =
    Pin<Box<dyn Future<Output = Result<InferenceResult, InferenceError>> + Send>>;

/// Injectable generation boundary used by built-in agents.
///
/// Production contexts normally call [`InferenceEngine::generate_tracked`].
/// Tests and embedders can supply a deterministic implementation to inspect
/// prompt assembly and exercise orchestration without network or model access.
pub type AgentGenerator = dyn Fn(GenerateRequest) -> AgentGenerationFuture + Send + Sync;

/// Shared context for built-in agents.
#[derive(Clone)]
pub struct AgentContext {
    pub inference: Arc<InferenceEngine>,
}

pub(crate) async fn generate_with(
    context: &AgentContext,
    generator: Option<&Arc<AgentGenerator>>,
    request: GenerateRequest,
) -> Result<InferenceResult, InferenceError> {
    match generator {
        Some(generator) => generator(request).await,
        None => context.inference.generate_tracked(request).await,
    }
}

/// Result from any built-in agent.
#[derive(Debug, Clone, serde::Serialize, serde::Deserialize)]
pub struct AgentResult {
    pub agent: String,
    pub output: String,
    pub confidence: f64,
    pub model_used: String,
    pub latency_ms: u64,
}