Skip to content
 
 

Repository files navigation

Ratel

Context engineering for AI agents — engineer the context your agent actually needs, on every turn.

DocsRoadmapDiscord

npm crates.io GitHub stars Discord license

Most agents stuff every tool, skill, and memory into the context window each turn — burning tokens, drifting on the long tail. Ratel sits between the agent and its catalog, and resolves only what matters for this turn.

What is Ratel

In-process context engineering platform for AI agents — a catalog, a retrieval engine, and an in-process runtime that decide what ends up in the model's context window on every turn.

  • Wedge today: tool selection. Register tools (or ingest an upstream MCP server) into a ToolCatalog; the model sees the handful that matter for the current turn, not the full list.
  • Same primitives extend to skills, memories, and message history as they land on the roadmap.
  • Stack: Rust core (ratel-ai-core) + TypeScript SDK + CLI that drops Ratel between an MCP host (Claude Code, Cursor, ChatGPT) and upstream MCP servers.
  • No vector DB. No embedding pipeline. No service to deploy.

See docs/overview.md for the thesis, docs/roadmap.md for what's coming.

Why Ratel

  • Retrieval, not stuffing. BM25 over a schema-aware text projection of every tool — deterministic, no embeddings, no inference cost on the retrieval path (ADR‑0004).
  • ~2 tools per turn. Replace-by-default tool injection (ADR‑0003): the agent's tool list at any turn is the top‑K hits. Less context, less drift, lower cost.
  • In-process, no infra. Pre-built native bindings for darwin / linux / win — no Rust toolchain to install.
  • Framework-agnostic. ToolCatalog returns generic ExecutableTool objects you wrap in a few lines (Vercel AI SDK example shipped in examples/ai-sdk, examples/mcp-chat). Or skip the framework and expose the catalog over MCP.

Where Ratel is most valuable today

your situation Ratel's value today
Local model + large catalog Critical. qwen3.5 at pool=100 goes from 8% → 77% — the baseline collapses, Ratel keeps it working.
Open-source cloud + large catalog Strong win. glm-5.1 at pool=180: +12 pp accuracy, -85% input tokens.
Frontier (Sonnet) + large catalog Cost-driven win. Sonnet 4.6 at pool=180: -82% input tokens, -68% $; -8 pp accuracy (closing).
Frontier (Opus) + large catalog Competitive win. Opus 4.6 pool=180: +8 pp accuracy and -72% tokens (discovery-tool arm). Opus 4.7 pool=180: ≈parity (-1.7 pp) with -81% tokens — Anthropic's own tool-search-tool loses -8 pp on the same setup.
Any model + tiny catalog (≤30) Skip Ratel — pool fits in the prompt cleanly.

Numbers from the MetaTool agent benchmark — full per-pool breakdown and methodology in ratel-ai/ratel-bench › RESULTS.md. The benchmark harness lives in its own public repo: ratel-ai/ratel-bench.

Choose your path

Three shapes, same Rust core. Pick one — or mix them:

Rust library TypeScript SDK CLI
For Rust agents and downstream SDKs TS / Node agents Migrating an existing Claude Code MCP setup into Ratel
Install cargo add ratel-ai-core pnpm add @ratel-ai/sdk pnpm add -g @ratel-ai/cli
Hero call ToolRegistry::search searchToolsTool(catalog) ratel mcp import
Reference src/core/lib/ src/sdk/ts/ src/integrations/cli/

The MCP-server library that powers the CLI's gateway lives in a sibling repo: ratel-ai/ratel-mcp. Python SDK and Rust HTTP server are on the roadmap, not yet shipped.

Quickstart

TypeScript SDK — embed Ratel in a TS / Node agent

pnpm add @ratel-ai/sdk
import { ToolCatalog, searchToolsTool, invokeToolTool } from "@ratel-ai/sdk";

const catalog = new ToolCatalog();
catalog.register({
  id: "read_file",
  name: "read_file",
  description: "Read a file from local disk.",
  inputSchema: { properties: { path: { type: "string" } } },
  outputSchema: { properties: { contents: { type: "string" } } },
  execute: async ({ path }) => ({ contents: await fs.readFile(path, "utf8") }),
});

// Hand these two tools to your agent loop.
// The full catalog stays out of the model's context — the agent reaches it via search_tools / invoke_tool.
const search = searchToolsTool(catalog);
const invoke = invokeToolTool(catalog);

MCP server — expose a catalog over MCP for Claude / Cursor / ChatGPT

The MCP-server library and its serve CLI live in a sibling repo: ratel-ai/ratel-mcp. The published @ratel-ai/mcp-server package on npm is unchanged; @ratel-ai/cli in this repo depends on it and exposes the same gateway via ratel serve.

CLI — migrate an existing Claude Code MCP setup into Ratel

pnpm add -g @ratel-ai/cli

ratel mcp import   # interactive: scans ~/.claude.json + per-project .mcp.json,
                   # cherry-pick which upstreams to move into Ratel,
                   # rewrites Claude Code to launch `ratel serve`.

ratel backup undo  # roll back any time — every change writes a timestamped backup under ~/.ratel/backups/.

ratel mcp add mirrors claude mcp add flag-for-flag. Three-scope hierarchy (user / project / local), OAuth flow, full verb reference: src/integrations/cli/README.md.

Rust library — direct, no JS in the loop

cargo add ratel-ai-core

In-process BM25 retrieval over a schema-aware text projection of each tool. See src/core/lib/README.md and docs.rs/ratel-ai-core.

How it works (today)

  • Tool selection is the v0.1.x shipping path. Ratel sits between agent and catalog.
  • Each turn, the agent either calls search_tools(query) or — in pre-filter mode — receives the top‑K hits resolved at message start. The full list never enters context.
  • The catalog holds local executables, upstream MCP servers' tools (via registerMcpServer), or both — the model sees a unified, ranked surface.
  • Under the hood: ratel-ai-core, a Rust BM25 index over a deterministic, schema-aware text projection of each tool. No embeddings, no vector DB, no inference latency on the retrieval path.

Longer take + skills / telemetry / memories / context graph: docs/overview.md.

Examples

Where this is going

Tool selection is the wedge, not the destination. Same catalog, same retrieval engine, same in-process runtime — widening into the rest of the agent's context surface:

  • v0.1.x — telemetry + UI inspector, JSON→TOON encoding, MCP tools/list_changed, first-class skills, LLM-driven catalog suggestions, multi-agent decomposition hints, semantic re-ranking over BM25, opt-in self-hosted trace server.
  • v0.2.x — chat management — store / compact / prune / navigate long histories.
  • v0.3.x — memories — prior decisions, preferences, and artifacts ranked into the current turn.
  • v0.4.x — context graph — unified tools-skills-memories substrate.
  • v0.5.x — Python SDK — second host language on the Rust core.

Dated milestones: docs/roadmap.md. Thesis: docs/overview.md.

Repo layout

src/
├── core/lib/                  # ratel-ai-core — Rust crate; BM25 retrieval engine
├── sdk/ts/                    # @ratel-ai/sdk — TypeScript SDK (NAPI-bound)
└── integrations/
    └── cli/                   # @ratel-ai/cli — `ratel` CLI
examples/                      # Runnable end-to-end examples
docs/                          # Overview, roadmap, ADRs

The benchmark harness lives in its own public repo: ratel-ai/ratel-bench.

Build & test

Prerequisites: Rust stable (pinned via rust-toolchain.toml), Node 24+, pnpm 10.28+.

# Rust
cargo build --workspace
cargo clippy --workspace --all-targets -- -D warnings
cargo fmt --check --all
cargo test --workspace

# TS
pnpm install
pnpm -r build
pnpm -r typecheck
pnpm -r lint
pnpm -r test

CI runs both pipelines on every PR (.github/workflows/{rust,ts}.yml).

Architecture decisions

Full record in docs/adr/. Cross-cutting locks worth knowing up front:

Contributing

License

Elastic License 2.0, with a grant making it free for OSI-approved open-source projects. Non-OSS / commercial production use requires a commercial license. See LICENSE.md.

About

The Context Engineering platform

Resources

Code of conduct

Contributing

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages