Skip to main content

agent_code_lib/
lib.rs

1//! # agent-code-lib
2//!
3//! The complete AI coding agent engine as a reusable library.
4//!
5//! This crate contains everything needed to build an AI coding agent:
6//! LLM providers, tools, the query engine, memory, permissions, and
7//! all supporting services. The `agent` CLI binary is a thin wrapper
8//! over this library.
9//!
10//! ## Modules
11//!
12//! | Module | Purpose |
13//! |--------|---------|
14//! | [`config`] | Configuration loading and schema (TOML, layered merge) |
15//! | [`error`] | Unified error types (`LlmError`, `ToolError`, `ConfigError`) |
16//! | [`hooks`] | Lifecycle hooks (pre/post tool use, session events) |
17//! | [`llm`] | LLM communication: streaming client, message types, providers, retry |
18//! | [`memory`] | Persistent context: project (AGENTS.md) and user memory |
19//! | [`permissions`] | Permission system: rules, modes, protected directories |
20//! | [`query`] | Agent loop: call LLM → execute tools → compact → repeat |
21//! | [`services`] | Cross-cutting: tokens, compaction, sessions, git, MCP, plugins, diagnostics |
22//! | [`skills`] | Custom workflow loading from markdown files |
23//! | [`state`] | Session state: messages, usage tracking, cost |
24//! | [`tools`] | 32 built-in tools and the `Tool` trait for custom tools |
25//!
26//! ## Quick Example
27//!
28//! ```rust,no_run
29//! use agent_code_lib::config::Config;
30//! use agent_code_lib::tools::registry::ToolRegistry;
31//! use agent_code_lib::state::AppState;
32//!
33//! let config = Config::default();
34//! let tools = ToolRegistry::default_tools();
35//! let state = AppState::new(config);
36//! // state.messages, state.total_cost_usd, etc. are now available
37//! ```
38//!
39//! ## Adding a Custom Tool
40//!
41//! Implement the [`tools::Tool`] trait:
42//!
43//! ```rust,ignore
44//! use async_trait::async_trait;
45//! use agent_code_lib::tools::{Tool, ToolContext, ToolResult};
46//!
47//! struct MyTool;
48//!
49//! #[async_trait]
50//! impl Tool for MyTool {
51//!     fn name(&self) -> &'static str { "MyTool" }
52//!     fn description(&self) -> &'static str { "Does something useful" }
53//!     fn input_schema(&self) -> serde_json::Value {
54//!         serde_json::json!({"type": "object", "properties": {}})
55//!     }
56//!     fn is_read_only(&self) -> bool { true }
57//!     async fn call(
58//!         &self,
59//!         input: serde_json::Value,
60//!         ctx: &ToolContext,
61//!     ) -> Result<ToolResult, agent_code_lib::error::ToolError> {
62//!         Ok(ToolResult { content: "done".into(), is_error: false })
63//!     }
64//! }
65//! ```
66//!
67//! Then register it: `registry.register(Arc::new(MyTool));`
68
69#![allow(dead_code, clippy::new_without_default, clippy::len_without_is_empty)]
70
71pub mod config;
72pub mod error;
73pub mod hooks;
74pub mod llm;
75pub mod memory;
76pub mod permissions;
77pub mod query;
78pub mod services;
79pub mod skills;
80pub mod state;
81pub mod tools;