cerebro 1.1.7

A blazing-fast AI memory layer that enables teams of specialized agents to collaborate through a shared cognitive architecture.
Documentation
use clap::{Parser, Subcommand};
use std::sync::Arc;

use cerebro::prelude::*;
use cerebro::swarm::prelude::*;

/// Cerebro Swarm CLI - Run AI multi-agent orchestration right from the terminal.
#[derive(Parser, Debug)]
#[command(author, version, about, long_about = None)]
struct Cli {
    #[command(subcommand)]
    command: Commands,
}

#[derive(Subcommand, Debug)]
enum Commands {
    /// Execute a quick sequential swarm pipeline
    Run {
        /// The input prompt or task
        #[arg(short, long)]
        input: String,

        /// Comma-separated list of agent IDs to run sequentially
        #[arg(short, long, default_value = "analyst,reviewer")]
        agents: String,
    },
    /// Start the HTTP/WebSocket Gateway
    Serve {
        #[arg(short, long, default_value = "3000")]
        port: u16,
    },
}

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let cli = Cli::parse();

    // Setup base engine (in-memory for CLI defaults, though could connect to PgVector)
    let engine = Arc::new(MemoryEngine::new(
        Arc::new(RecursiveCharacterChunker::new(512, 50)),
        Arc::new(MockEmbedder::new(1536)),
        Arc::new(MemoryVectorStore::new()),
    ));
    let memory = Arc::new(CerebroMemoryBus::new(
        engine,
        Arc::new(MemoryKVStore::new()),
    ));

    let mut swarm = SwarmOrchestrator::new(memory.clone());

    // Register some default agents
    swarm.register_agent(AgentConfig {
        id: "analyst".into(),
        name: "Data Analyst".into(),
        system_prompt:
            "You are an expert data analyst. Breakdown the user request and find key entities."
                .into(),
        model: LlmProvider::Ollama {
            model: "llama3".into(),
            base_url: "http://localhost:11434".into(),
        },
        tools: vec![],
        handoff_targets: vec![],
        max_steps: 10,
    });

    swarm.register_agent(AgentConfig {
        id: "reviewer".into(),
        name: "Security Reviewer".into(),
        system_prompt: "You review the previous analysis for security logic flaws and synthesize a final report.".into(),
        model: LlmProvider::Ollama { model: "llama3".into(), base_url: "http://localhost:11434".into() },
        tools: vec![],
        handoff_targets: vec![],
        max_steps: 10,
    });

    match &cli.command {
        Commands::Run { input, agents } => {
            let order: Vec<String> = agents.split(',').map(|s| s.trim().to_string()).collect();
            let pattern = SwarmPattern::Sequential { agent_order: order };
            let _res = swarm.execute(pattern, input).await?;
        }
        Commands::Serve { port } => {
            #[cfg(feature = "api")]
            {
                let app = cerebro::swarm::gateway::create_router(Arc::new(swarm));
                let addr = format!("0.0.0.0:{}", port);
                let listener = tokio::net::TcpListener::bind(&addr).await?;
                println!("🚀 Swarm Gateway running on http://{}", addr);
                axum::serve(listener, app).await?;
            }
            #[cfg(not(feature = "api"))]
            {
                eprintln!("Error: The 'api' feature is not enabled. Compile with --features api");
            }
        }
    }

    Ok(())
}