LEAF is a lightweight AI development framework for the AI ecosystem, built with Rust. One set of Abilities serves Agent, MCP, CLI, Skill, Tools, and HTTP (and more).
It helps teams and individuals build secure, reliable, high-performance harnesses, personal assistants, in-house AI systems, tool gateways, and related applications.
The multi-protocol AI capability layer keeps the same capability organized, assembled, exposed, and governed, with Abilities enabling cross-app and cross-system scheduling.
Ability-to-Ability communication supports shared memory, multi-process, and cross-device networking models, so you can tune for performance, availability, and other requirements.
Experimental: DeepSeek harness plugins, Claude Mods, and similar ecosystem integrations ship at the edge via Abilities, with reference examples. See Ecosystem plugins.
The problem · Core model · Runtime · Features · Manual · Status · Contributing
Unlike traditional single-product designs, many AI application stacks split into sub-scenarios. Besides integrating legacy systems, sub-applications often need to coordinate—for example:
- Retrieval and ticketing triggered from a chat flow
- Chaining document understanding with command execution in one business path
- Handing collected data to other systems for analysis or content generation
In AI systems, a capability such as “recognize an image” or “run a command” often must appear in many places at once:
| Surface | Form |
|---|---|
| Agent | tool_calls |
| MCP | tools |
| CLI | commands |
| HTTP | APIs |
| Harness | internal dispatch entry points |
Some capabilities also need to surface as Skills on a unified agent entry. Writing a separate adapter for each surface leads to:
- Duplicated business logic
- Inconsistent behavior across protocols
- Auth, rate limits, and observability scattered everywhere
- Trimming a minimal runtime requires changing business code
- Adding a new protocol surface touches many call sites
LEAF’s design starting point: keep capability implementations protocol-agnostic; defer protocol mapping to assembly time.
| Concept | Role | Key point |
|---|---|---|
| Ability | Implements a capability | Protocol-agnostic—“what,” not how it is exposed |
| App | Assembly and governance | Chooses which Abilities load, which config binds, which protocol ports expose |
| Gateway | Unified invoke pipe | Every call is instance + method + args—one observability, auth, and rate-limit entry |
Ability is the stable atom, App is the variable assembly policy, Gateway is the single execution entry.
LEAF needs runtime control so capabilities are invoked, exposed, and governed the same way everywhere:
| Need | Why |
|---|---|
| Unified entry | As a library-only integration, callers can bypass the Gateway and call business functions directly, breaking unified observability and governance |
| Protocol projection | Serving MCP, CLI, and HTTP at once involves registries, routing, config loading, and process lifecycle |
| Assembly trimming | AbilityExpose and similar config decide load, disable, and parameter binding—assembly-time concerns |
| Declaration-driven layout | ability.yml, protocol info.yml, generated Providers, and src/logic/ layout are framework-level contracts |
The App owns assembly and governance; Abilities stay pure and reusable. The same Ability codebase can assemble into different runtime shapes:
AbilityExposegates Port visibility- Same-app
ctx.callis unrestricted - Cross-app calls require
open: true
See Catalog & expose.
LEAF scopes itself to the capability-layer runtime; the application main loop stays with you. Libraries and SDKs at the core and edge include:
Ability SDKGateway client- Protocol adapters
- Config parsers
- Code generators
Ability Guest SDK implementations (under SDK/, all speaking guest-protocol-1 stdio JSON lines):
| Language SDK | Directory | framework_version |
Project marker | Guest entry | manifest/methods/lifecycle | ctx.call/dep/catalog | local_get/set | emit/subscribe/handle/event_next | load/unload | feedback | chain_status/share | push_effect+undo | register_aspect |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Rust (wire-protocol lib) | SDK/ability-sdk |
rust@1 |
Cargo.toml |
— | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ (in-process) |
| Node | SDK/ability-sdk-ts |
node@1 (ts@1 alias) |
package.json |
src/serve.mjs |
✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ (rejected as Guest) |
| Python | SDK/ability-sdk-py |
python@1 (py@1 alias) |
pyproject.toml |
src/serve.py |
✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ (rejected as Guest) |
| Cangjie | SDK/ability-sdk-cj |
cangjie@1 (cj@1 alias) |
cjpm.toml |
src/serve.cj |
✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ (rejected as Guest) |
| Feature | Rust (wire lib) | Node | Python | Cangjie |
|---|---|---|---|---|
| stdout flush after each frame | ✅ | ✅ | ✅ | ✅ |
| clean exit on stdin EOF | ✅ | ✅ | ✅ | ✅ |
| long-task handle / poll | — (not required) | ✅ | ✅ | ✅ (pending + poll; work runs on a background thread) |
LEAF_ABILITY_ROOT |
— | ✅ | ✅ | ✅ (env first, then cwd walk-up) |
Legend: ✅ supported;
Guest vs in-process Rust: Guests do not support register_aspect (in-process aspects are Rust-runtime only). Protocol details: Guest wire protocol.
The Gateway is by default a single-process invocation facade; a distributed multi-process / cross-device Gateway is not a turnkey capability. The framework ships one optional connect-style implementation:
frame/port-http::RemoteHttpGateway: connects to another Leaf process's HTTP port (its/v1/abilitiesREST surface) and implements the localGatewaytrait — catalog prefetched at connect time, invoke forwarded live, errors restored via classification codes instead of degrading to a generic 5xx. See the crate docs andframe/port-http/tests/remote_gateway.rs.- Principle for app-built channels: any remote channel should land back on the unified
Gatewaytrait (invoke/catalog/get_entry), so ports, observability, and access control keep flowing through the same pipeline; transport and encoding are up to you (the HTTP and gRPC ports already provide the matching projections on both ends).
frame/port-http carries only the generic REST surface: /health, catalog, and invoke (the unified Gateway envelope). Complex domain REST belongs to the application: HttpPort::with_route_extension lets an app merge its own routes on top of the default surface — ability calls keep flowing through the unified Gateway face (same observability, access control, and error classification), while domain endpoints are defined and guarded by the app. The two narratives are not mixed: don't push thick domain logic into the default projection, and don't bypass the Gateway to reach abilities.
Unified governance where it matters, local reuse where it helps. Details: Architecture.
| Feature | Description |
|---|---|
| Implement once, project to many protocols | One Ability can assemble into MCP, CLI, HTTP, or agent tool calls; business logic stays in the capability layer |
| Unified Gateway invoke pipe | Calls use instance + method + args—one observability, auth, and rate-limit surface |
| Trim at assembly time | AbilityExpose controls load, disable, and binding per instance; one codebase, different feature sets and minimal runtimes |
| Declaration-driven codegen | ability.yml and protocol info.yml generate Providers; business logic lives in src/logic/ with less boilerplate and fewer adapter forks |
| Building blocks for AI systems | Sessions, multi-turn tool loops, Skills, OpenAI-compatible chat, and more; the agent is one consumer among many |
| Rust runtime | Workspace targets Rust edition 2024—memory safety, performance, and deployability |
| Optional monitoring | apps/monitor: call chains and lifecycle events, stats and graphs, plus CLI / live TUI / optional HTTP / in-process queries; leave the package out if you do not need it |
| Ecosystem at the edge | External compatibility via separate Abilities or assembly modules; core Abilities and the engine stay stable |
| Scenario | Description |
|---|---|
| Many protocol surfaces | Teams that must expose the same capabilities via Agent, MCP, CLI, HTTP, and more |
| Gateways and harnesses | Teams building MCP services, tool gateways, or harness runtimes |
| Unified governance | Platform teams converging auth, rate limits, observability, and assembly policy |
| Per-deployment trimming | Deployments that need different capability mixes |
| Early co-design | Rust / AI infrastructure engineers shaping an early runtime |
LEAF ships optional monitoring as apps/monitor (crate leaf-monitor). Add the dependency and a monitor.yml when you want it; leave them out when you do not.
Events and in-flight snapshots are meant for call graphs and lifecycle state diagrams, not only pass/fail logs:
- Call chains — a root call and its nested calls, enough to rebuild a call tree
- Timing and order — start/end times and sequence, so you can measure latency
- Lifecycle — Ability load/unload and state changes
- Queue stats — recent volume, queued depth, and drops (bounded queue; never blocks callers)
Rebuild a tree with leaf_monitor::graph::build_chain_graph, or use the graph query below.
| Interface | Entry |
|---|---|
| Async JSONL log | One event per line |
| Query CLI | Chains, events, log, stats, and graph; offline monitor log --tail N |
| Live TUI | cargo run -p leaf-monitor -- tui; Tab switches chains → events → graph |
| Optional HTTP | Off by default; local endpoints for the same views |
| In-process API | Query chains, events, stats, and graph in the same process |
See apps/monitor/README.md and skill SKILL/use-monitoring for details.
| English | 中文 | Contents |
|---|---|---|
| Getting started | 快速开始 | Create an app, invoke, subscribe |
| Catalog & expose | 清单与裁剪 | Protocol lists & expose filters |
| Writing abilities | 编写 Ability | Authoring Abilities |
| Architecture | 架构概览 | Public architecture model |
| Ecosystem plugins | 生态插件 | Claude Code Mods and DSH |
LEAF is in early preview:
| Dimension | Notes |
|---|---|
| Direction | Architecture is clear; APIs and layout may still change |
| Fit | Design evaluation, prototypes, contributions |
| Caution | Not for critical production paths without pinned versions and thorough testing |
Roadmap
- More first-class AI system features
- Library forms of Ability SDK and Gateway client
- Stronger protocol ports and assembly configuration
- Python, TypeScript, and other polyglot Abilities
- Observability, auth, and rate-limit governance
- More reusable App assembly examples
Reference apps: apps/agent-test (agent loop), apps/web-agent (web)
external/ is experimental—author SDKs and probes may still change.
- Capabilities stay protocol-agnostic — Abilities remain neutral
- Assembly defines shape — The App decides load, expose, and bind
- Calls converge on the Gateway — One entry, one governance model
- Business logic in Ability crates — The runtime kernel stays thin
- Ecosystem at the edge — External compatibility plugs in separately
- Clear boundaries first — Stabilize structure, then expand features
Early contributions are welcome. Read Architecture and Writing abilities first.
Focus areas
- Ability examples and best practices
- Protocol adapters
- Assembly config and governance policy
- Tests, docs, and benchmarks
- Polyglot Abilities
If you are building a multi-protocol AI capability layer—or disagree on what a “capability runtime” should be—open an Issue on trade-offs. The project cares about clear boundaries, converged governance, and verifiability in real scenarios.
See LICENSE in this repository (Apache License 2.0).