SkillAgentSearch skills...

Cersei

The Rust SDK for building coding agents. Tool execution, LLM streaming, graph memory, sub-agent orchestration, MCP — as composable library functions.

Install / Use

/learn @pacifio/Cersei
About this skill

Quality Score

0/100

Supported Platforms

Claude Code
Claude Desktop
OpenAI Codex
Cursor

README

Cersei

The complete Rust SDK for building coding agents.

Cersei gives you every building block of a production coding agent — tool execution, LLM streaming, sub-agent orchestration, persistent memory, skills, MCP integration — as composable library functions. Build a Claude Code replacement, embed an agent in your app, or create something entirely new.

use cersei::prelude::*;

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let output = Agent::builder()
        .provider(Anthropic::from_env()?)
        .tools(cersei::tools::coding())
        .permission_policy(AllowAll)
        .run_with("Fix the failing tests in src/")
        .await?;

    println!("{}", output.text());
    Ok(())
}

MIT License | Built by Adib Mohsin | Docs | GitHub


Why Cersei

| | Claude Code | OpenCode | Cersei SDK | Abstract CLI | |---|---|---|---|---| | Form factor | CLI app | CLI app | Library | CLI app | | Embeddable | No | No | Yes | No (uses SDK) | | Provider | Anthropic only | Multi-provider | Multi-provider | Multi-provider | | Language | TypeScript | TypeScript | Rust | Rust | | Custom tools | Plugins | Plugins | impl Tool / #[derive(Tool)] | Via SDK | | Startup | ~269ms | ~300ms | N/A (library) | ~34ms | | Binary / RSS | 174MB / 330MB | — | N/A | 5.8MB / 4.9MB | | Memory | File-based | SQLite | File + Graph | File + Graph | | Skills | .claude/commands/ | .claude/skills/ | Both formats | Both formats |

Cersei is built from the architecture of Claude Code (reverse-engineered Rust port) and designed so that anyone can build a complete, drop-in replacement for Claude Code, OpenCode, or any coding agent — as a library call.


Abstract — The CLI

Abstract is a complete CLI coding agent built on Cersei. One binary, zero runtime dependencies, graph memory by default.

# Install
cargo install --path crates/abstract-cli

# Use
abstract                           # Interactive REPL
abstract "fix the failing tests"   # Single-shot
abstract --resume                  # Resume last session
abstract --model opus --max        # Opus with max thinking
abstract --no-permissions --json   # CI mode with NDJSON output

Abstract vs Claude Code

All numbers from run_tool_bench.sh --full.

| Metric | Abstract | Claude Code | Winner | |--------|----------|-------------|--------| | Startup (warm) | 32ms | 266ms | Abstract (8.2x) | | Binary size | 6.0 MB | 174 MB | Abstract (29x) | | Memory (RSS) | 4.9 MB | 333 MB | Abstract (68x) | | Tool dispatch | 0.02-17ms | 5-265ms+ | Abstract | | Memory recall | 98us (graph) | 7,545ms (LLM) | Abstract (77,000x) | | Memory write | 30us (graph) | 20,687ms (agent) | Abstract (689,000x) | | MEMORY.md load | 9.6us | 17.1ms | Abstract (1,781x) | | Sequential throughput | 906ms/req | 12,079ms/req | Abstract (13.3x) | | System prompt tokens | ~2,200 | ~8,000+ | Abstract (3.6x fewer) | | LLM call for recall | Not needed | Required (Sonnet) | Abstract |

Claude Code's memory recall calls Sonnet every turn to rank the top 5 files by relevance (7.5s measured). Abstract's graph does indexed lookups in 98 microseconds — same capability, no LLM call, no API cost.

Full benchmark: crates/abstract-cli/benchmarks/REPORT.md

Features

  • 34 built-in tools (file, shell, web, planning, orchestration, scheduling)
  • Multi-provider: Anthropic + OpenAI (+ Ollama, Azure, vLLM)
  • Graph memory (Grafeo) on by default
  • Auto-compact, auto-dream, effort levels (Low/Medium/High/Max)
  • MCP server support
  • Session persistence (Claude Code-compatible JSONL)
  • Interactive permissions with session caching
  • 12 slash commands (/help, /commit, /review, /memory, /model, /diff, etc.)
  • Streaming markdown rendering with syntax highlighting
  • TOML config: ~/.abstract/config.toml + .abstract/config.toml
  • JSON output mode for piping (--json)

Install

[dependencies]
cersei = { git = "https://github.com/pacifio/cersei" }
tokio = { version = "1", features = ["full"] }
anyhow = "1"

For graph-backed memory (optional):

cersei-memory = { git = "https://github.com/pacifio/cersei", features = ["graph"] }

Architecture

cersei                    Facade crate — use cersei::prelude::*;
  cersei-types            Provider-agnostic messages, errors, stream events
  cersei-provider         Provider trait + Anthropic/OpenAI implementations
  cersei-tools            30+ tools, permissions, bash classifier, skills, git utils
  cersei-tools-derive     #[derive(Tool)] proc macro
  cersei-agent            Agent builder, agentic loop, compact, coordinator, effort
  cersei-memory           Memory trait, memdir, CLAUDE.md, sessions, Grafeo graph
  cersei-hooks            Hook/middleware system
  cersei-mcp              MCP client (JSON-RPC 2.0, stdio transport)
abstract-cli              CLI coding agent ("abstract") — REPL, commands, config, permissions

Core Concepts

Provider

Any LLM backend. Built-in: Anthropic (with OAuth), OpenAI (compatible with Ollama, Azure, vLLM).

Agent::builder().provider(Anthropic::from_env()?)           // Anthropic API key
Agent::builder().provider(OpenAi::builder()
    .base_url("http://localhost:11434/v1")                   // Ollama
    .model("llama3.1:70b").api_key("ollama").build()?)
Agent::builder().provider(MyCustomProvider)                  // impl Provider

Tools (30+)

Every tool a coding agent needs, organized into sets:

cersei::tools::all()           // 30+ tools
cersei::tools::coding()        // filesystem + shell + web
cersei::tools::filesystem()    // Read, Write, Edit, Glob, Grep, NotebookEdit
cersei::tools::shell()         // Bash, PowerShell
cersei::tools::web()           // WebFetch, WebSearch
cersei::tools::planning()      // EnterPlanMode, ExitPlanMode, TodoWrite
cersei::tools::scheduling()    // CronCreate/List/Delete, Sleep, RemoteTrigger
cersei::tools::orchestration() // SendMessage, Tasks (6 tools), Worktree

Custom tools in 10 lines:

#[derive(Tool)]
#[tool(name = "search", description = "Search docs", permission = "read_only")]
struct SearchTool;

#[async_trait]
impl ToolExecute for SearchTool {
    type Input = SearchInput; // derives Deserialize + JsonSchema
    async fn run(&self, input: SearchInput, ctx: &ToolContext) -> ToolResult {
        ToolResult::success(format!("Found: {}", input.query))
    }
}

Sub-Agent Orchestration

Spawn parallel workers, coordinate tasks, pass messages between agents:

// AgentTool — model spawns sub-agents autonomously
Agent::builder()
    .tool(AgentTool::new(|| Box::new(Anthropic::from_env()?), cersei::tools::coding()))

// Coordinator mode — orchestrate parallel workers
Agent::builder()
    .tools(cersei::tools::all())  // includes Agent, Tasks, SendMessage
    // Workers get filtered tools (no Agent — prevents recursion)

// Task system
// TaskCreate → TaskUpdate → TaskGet → TaskList → TaskStop → TaskOutput

Memory (Three-Tier)

use cersei::memory::manager::MemoryManager;

let mm = MemoryManager::new(project_root)
    .with_graph(Path::new("./memory.grafeo"))?;  // optional graph layer

// Tier 1: Flat files (~/.claude/projects/<root>/memory/)
let metas = mm.scan();                    // scan .md files with frontmatter
let content = mm.build_context();         // build system prompt injection

// Tier 2: CLAUDE.md hierarchy (managed > user > project > local)
// Automatically merged into build_context()

// Tier 3: Graph memory (Grafeo, optional)
let id = mm.store_memory("User prefers Rust", MemoryType::User, 0.9)?;
mm.tag_memory(&id, "preferences");
let results = mm.recall("Rust", 5);       // graph query with fallback to text match

// Session persistence (JSONL, append-only, tombstone soft-delete)
mm.write_user_message("session-1", Message::user("Hello"))?;
let messages = mm.load_session_messages("session-1")?;

Skills (Claude Code + OpenCode Compatible)

// Auto-discovers skills from:
//   .claude/commands/*.md      (Claude Code format)
//   .claude/skills/*/SKILL.md  (OpenCode format)
//   ~/.claude/commands/*.md    (user-level)
//   Bundled skills             (simplify, debug, commit, verify, stuck, remember, loop)

let skill_tool = SkillTool::new().with_project_root(".");
// skill="list" → lists all available skills
// skill="debug" args="tests are flaky" → expands $ARGUMENTS template

Realtime Events

Three observation mechanisms:

// 1. Callback
Agent::builder().on_event(|e| match e {
    AgentEvent::TextDelta(t) => print!("{}", t),
    AgentEvent::ToolStart { name, .. } => eprintln!("[{}]", name),
    _ => {}
})

// 2. Broadcast (multi-consumer)
let agent = Agent::builder().enable_broadcast(256).build()?;
let mut rx = agent.subscribe().unwrap();
tokio::spawn(async move { while let Ok(e) = rx.recv().await { /* ... */ } });

// 3. Stream (bidirectional control)
let mut stream = agent.run_stream("Deploy");
while let Some(e) = stream.next().await {
    if let AgentEvent::PermissionRequired(req) = e {
        stream.respond_permission(req.id, PermissionDecision::Allow);
    }
}

Context Management

Agent::builder()
    .auto_compact(true)          // summarize old messages at 90% context usage
    .compact_threshold(0.9)      // trigger threshold
    .tool_result_budget(50_000)  // truncate oldest tool results above 50K chars
    .thinking_budget(8192)       // extended thinking tokens
    .effort(EffortLevel::High)   // Low/Medium/High/Max

MCP (Model Context Protocol)

let mcp = McpManager::connect(&[
    McpServerConfig::stdio("db", "npx", &["-y", "@my/db-mcp"]),
    McpServerConfig::sse("docs", "https://mcp.example.com"),
]).await?;

Ag

Related Skills

View on GitHub
GitHub Stars153
CategoryDevelopment
Updated5m ago
Forks42

Languages

Rust

Security Score

100/100

Audited on Apr 3, 2026

No findings