agent-code-lib
The complete AI coding agent engine as a reusable library.
This crate contains everything needed to build an AI coding agent:
LLM providers, tools, the query engine, memory, permissions, and
all supporting services. The agent CLI binary is a thin wrapper
over this library.
Modules
| Module | Purpose |
|---|---|
[config] |
Configuration loading and schema (TOML, layered merge) |
[error] |
Unified error types (LlmError, ToolError, ConfigError) |
[hooks] |
Lifecycle hooks (pre/post tool use, session events) |
[llm] |
LLM communication: streaming client, message types, providers, retry |
[memory] |
Persistent context: project (AGENTS.md) and user memory |
[permissions] |
Permission system: rules, modes, protected directories |
[query] |
Agent loop: call LLM → execute tools → compact → repeat |
[services] |
Cross-cutting: tokens, compaction, sessions, git, MCP, plugins, diagnostics |
[skills] |
Custom workflow loading from markdown files |
[state] |
Session state: messages, usage tracking, cost |
[tools] |
32 built-in tools and the Tool trait for custom tools |
Quick Example
use Config;
use ToolRegistry;
use AppState;
let config = default;
let tools = default_tools;
let state = new;
// state.messages, state.total_cost_usd, etc. are now available
Adding a Custom Tool
Implement the [tools::Tool] trait:
use async_trait;
use ;
;
Then register it: registry.register(Arc::new(MyTool));