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//!     .hooks(ReadOnly)
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()` to handle each event as it happens
27//! - **Internal Loop**: Tool execution handled automatically
28//! - **Trait-based Hooks**: Intercept operations at compile time
29//! - **Context Management**: One policy, a cache-aware window, async compaction
30//! - **Generic over LLM**: Works with any `LanguageModel` implementation
31//!
32//! The crate carries no product policy: no default system prompt, no terminal
33//! tool and no built-in subagent types. The embedder supplies its own
34//! instructions, tools and policies.
35
36// Core modules
37mod agent;
38mod builder;
39mod cache_stats;
40mod checkpoint;
41mod clock;
42mod compaction_state;
43mod config;
44mod connectivity;
45pub mod context;
46mod context_window;
47mod effort;
48mod error;
49mod event;
50mod fork;
51mod hook;
52#[cfg(test)]
53mod midstream_retry_tests;
54mod model_group;
55mod request_parameters;
56mod subagent;
57mod tools;
58mod warmth;
59
60// Re-export tool crates
61#[cfg(feature = "command")]
62pub use aither_command as command;
63#[cfg(feature = "filesystem")]
64pub use aither_fs as filesystem;
65#[cfg(feature = "webfetch")]
66pub use aither_webfetch as webfetch;
67#[cfg(feature = "websearch")]
68pub use aither_websearch as websearch;
69
70// Public API
71pub use agent::{Agent, CancelHandle, CompactResult, Run};
72pub use builder::AgentBuilder;
73pub use cache_stats::CacheStats;
74pub use checkpoint::{AgentCheckpoint, Checkpoints};
75pub use clock::{AnyClock, Clock, Instant, ManualClock, SystemClock};
76pub use config::AgentConfig;
77pub use context::{
78    AnyContextSource, AnyFileReferences, AnyLiveSource, AttachmentCatalogEntry, AttachmentRef,
79    Block, CompactionError, CompletedCompaction, Context, ContextBlock, ContextBudget,
80    ContextCheckpoint, ContextFile, ContextItem, ContextPolicy, ContextSource, ExternalContent,
81    ExternalSlot, FileReferences, Handoff, HandoffDocument, HandoffPrompt, HandoffSchema,
82    InstructionSlot, InvalidHandoff, KeptAttachment, LineRange, LiveChange, LiveContent,
83    LiveSource, LiveUpdate, Moment, Placement, PrefixBlock, PrefixChain, PrefixRewrites,
84    PromptCache, PromptPrefix, ReassemblyReport, Restoration, SkillCatalogEntry, SourceId, Sourced,
85    SourcedSlot, SystemLayout,
86};
87pub use context_window::{ContextWindowMetrics, ContextWindowPhase, ContextWindowSnapshot};
88pub use error::{AgentError, ToolPanic};
89pub use event::{
90    AgentEvent, AgentPath, BlockId, CheckpointReason, CompactionOutcome, CompactionTrigger,
91    InjectionKind, OutputKind, PauseId, RequestId, RequestOutcome, RunId, RunOutcome, RunPause,
92    TimedEvent, ToolOrigin, ToolVerdict,
93};
94pub use fork::{ForkSnapshot, ForkSource};
95pub use hook::{
96    AfterTool, Hooks, RequestCx, StopCx, StopDecision, ToolDecision, ToolInvocation, ToolOutcome,
97    TurnBoundaryAction, TurnBoundaryContext,
98};
99pub use subagent::{ChildAgent, ChildEvents, SubagentRun, SubagentRunInfo, SubagentRuns};
100pub use tools::AgentTools;
101pub use warmth::{CacheState, CacheWarmth};
102
103// Model groups for budget tracking and fallback
104pub use model_group::{Budget, BudgetedModel, ModelGroup, ModelGroupError};
105
106// Re-export core tool trait for convenience
107pub use aither_attachments::{CacheEntry, FileCache};
108pub use aither_core::llm::Tool;