Skip to main content

aither_agent/
lib.rs

1//! Aither Agent Framework
2//!
3//! An ergonomic, minimal-core agent framework for building autonomous AI agents.
4//! The agent handles the tool-use loop internally with a simple API.
5//!
6//! # Quick Start
7//!
8//! ```rust,ignore
9//! use aither_agent::Agent;
10//!
11//! // Simple one-shot query
12//! let agent = Agent::new(llm);
13//! let response = agent.query("What is 2+2?").await?;
14//!
15//! // With tools and hooks
16//! let agent = Agent::builder(llm)
17//!     .tool(FileSystemTool::read_only("."))
18//!     .hook(LoggingHook)
19//!     .build();
20//!
21//! let response = agent.query("List all Rust files").await?;
22//! ```
23//!
24//! # Features
25//!
26//! - **Ergonomic API**: Simple `query()` for one-shot tasks, `run()` for streaming
27//! - **Internal Loop**: Tool execution handled automatically
28//! - **Trait-based Hooks**: Intercept operations at compile time
29//! - **Smart Compression**: Intelligent context management preserving critical info
30//! - **Generic over LLM**: Works with any `LanguageModel` implementation
31
32// Core modules
33mod agent;
34pub mod ask_user;
35mod browser_backend;
36mod builder;
37mod cache_stats;
38mod checkpoint;
39mod compression;
40mod config;
41mod context;
42mod context_window;
43mod error;
44mod event;
45mod fs_util;
46mod handoff;
47mod hook;
48mod model_group;
49mod stream;
50mod subagent_file;
51mod terminal_agent;
52mod todo;
53pub mod tool_request;
54mod tools;
55pub mod transcript;
56pub mod working_docs;
57pub mod workspace_request;
58
59// Specialized agents
60pub mod specialized;
61
62// File-based subagent definitions
63pub use subagent_file::{SubagentDefinition, builtin_subagents};
64
65// Re-export tool crates
66#[cfg(feature = "command")]
67pub use aither_command as command;
68#[cfg(feature = "filesystem")]
69pub use aither_fs as filesystem;
70#[cfg(feature = "webfetch")]
71pub use aither_webfetch as webfetch;
72#[cfg(feature = "websearch")]
73pub use aither_websearch as websearch;
74
75// Sandbox is always available (terminal-first design)
76pub use aither_sandbox as sandbox;
77
78// Public API
79pub use agent::{Agent, CompactResult};
80pub use browser_backend::{BrowserBackend, BrowserBackendError, StaticCdpBrowser};
81pub use builder::AgentBuilder;
82pub use cache_stats::CacheStats;
83pub use checkpoint::AgentCheckpoint;
84pub use compression::{
85    CompressionLevel, ContextStrategy, PreserveConfig, PreservedContent, SmartCompressionConfig,
86};
87pub use config::{AgentConfig, AgentKind, ContextAssemblerConfig};
88pub use context::{Context, ContextCheckpoint, ReassemblyReport};
89pub use context_window::{ContextWindowMetrics, ContextWindowPhase, ContextWindowSnapshot};
90pub use error::AgentError;
91pub use event::AgentEvent;
92pub use handoff::HandoffDocument;
93pub use hook::{
94    CheckpointContext, CheckpointReason, HCons, Hook, PostToolAction, PreToolAction, StopContext,
95    StopReason, ToolResultContext, ToolUseContext, TurnBoundaryAction, TurnBoundaryContext,
96};
97pub use stream::AgentStream;
98pub use terminal_agent::TerminalAgentBuilder;
99pub use todo::{TodoItem, TodoList, TodoStatus, TodoTool, TodoWriteArgs};
100pub use tools::AgentTools;
101
102// Model groups for budget tracking and fallback
103pub use model_group::{
104    Budget, BudgetedModel, ModelGroup, ModelGroupError, ModelTier, TieredModels,
105};
106
107// Re-export core tool trait for convenience
108pub use aither_attachments::{CacheEntry, FileCache};
109pub use aither_core::llm::Tool;
110
111/// Default system prompt for terminal-first agents.
112///
113/// This prompt teaches the LLM to use `terminal` as the primary tool interface,
114/// with all capabilities exposed as CLI commands that can be piped and composed.
115///
116/// # Example
117///
118/// ```rust,ignore
119/// use aither_agent::{Agent, TERMINAL_SYSTEM_PROMPT};
120///
121/// let agent = Agent::builder(llm)
122///     .system_prompt(TERMINAL_SYSTEM_PROMPT)
123///     .terminal(permission_handler, config, output_store)
124///     .build();
125/// ```
126pub const TERMINAL_SYSTEM_PROMPT: &str = include_str!("prompts/system.md");