Skip to main content

oxi_agent/
lib.rs

1#![allow(unused_doc_comments)]
2#![warn(missing_docs)]
3// Relax two test-idiom lints under `cfg(test)` so `cargo clippy --all-targets`
4// stays clean without weakening the shipped library:
5//   - `clippy::unwrap_used` — `unwrap()`/`unwrap_err()` are idiomatic in tests;
6//     shipped (non-test) code still `warn`s on it (see the line below).
7//   - `clippy::field_reassign_with_default` — the `let mut x = X::default();
8//     x.f = ..;` test-setup pattern.
9#![warn(clippy::unwrap_used)]
10#![cfg_attr(test, allow(clippy::unwrap_used, clippy::field_reassign_with_default))]
11#![allow(unknown_lints)]
12
13//! oxi-agent: Agent runtime for oxi
14//!
15//! Provides the core agent loop, tool execution, state management,
16//! and streaming event pipeline for the oxi coding agent.
17
18/// Core agent implementation.
19pub mod agent;
20/// Agent definition file parsing and discovery.
21pub mod agent_definition;
22/// Agent loop – the main request/response cycle driver.
23pub mod agent_loop;
24/// Context compaction strategies and data types.
25pub mod compaction;
26/// Agent configuration types.
27pub mod config;
28/// Error types for agent operations.
29pub mod error;
30/// Event types emitted during the agent loop.
31pub mod events;
32/// MCP (Model Context Protocol) integration.
33pub mod mcp;
34/// Model identifier constants and helpers.
35pub mod model_id;
36/// Fault-recovery primitives (circuit breaker, fallback chains).
37pub mod recovery;
38/// Agent state machine and shared mutable state.
39pub mod state;
40/// Shared streaming retry logic.
41pub mod stream_retry;
42pub mod structured_output;
43/// Built-in tool implementations and registry.
44pub mod tools;
45/// Shared type aliases and helpers.
46pub mod types;
47
48pub use agent::Agent;
49pub use agent::ProviderResolver;
50pub use agent_definition::{
51    AgentDefinition, AgentDiscovery, AgentScope, DefaultContext, current_subagent_depth,
52    max_subagent_depth, validate_agent_name,
53};
54pub use agent_loop::{AgentLoop, AgentLoopConfig};
55
56/// Agent configuration, hooks, and tool execution mode.
57pub use config::{
58    AfterToolCallContext, AfterToolCallResult, AgentConfig, AgentHooks, BeforeToolCallContext,
59    BeforeToolCallResult, ShouldStopAfterTurnContext, ToolExecutionMode,
60};
61pub use error::AgentError;
62pub use events::{AgentEvent, ToolCallContext, VisitReason};
63pub use tools::browse::{BrowseProgress, BrowseProgressCallback};
64
65pub use agent_loop::config::CompactionHook;
66pub use compaction::{CompactedContext, CompactionEvent};
67pub use oxi_ai::{CompactionManager, CompactionStrategy};
68/// Fault-recovery primitives for resilient agent execution.
69pub use recovery::{
70    CircuitBreaker, CircuitBreakerConfig, CircuitOpenError as CircuitOpenErrorFromAi,
71    FallbackChain, PartialResponse,
72};
73// Also export the local circuit error type used by CircuitBreaker
74pub use recovery::CircuitOpenErrorLocal;
75pub use state::{AgentState, SharedState};
76pub use structured_output::{OutputMode, StructuredOutput, StructuredOutputError};
77
78pub use mcp::{McpConfig, McpManager, McpTool};
79pub use tools::ask::{AskBridge, AskTool};
80pub use tools::commit::{
81    CommitGroup, CommitTool, CommitType, ConventionalAnalysis, ConventionalDetail, NumstatEntry,
82    ScopeCandidate,
83};
84pub use tools::context7::{Context7QueryDocsTool, Context7ResolveLibraryIdTool};
85pub use tools::github::GitHubTool;
86pub use tools::github_search::GitHubSearchTool;
87pub use tools::memory_edit::MemoryEditTool;
88pub use tools::memory_recall::MemoryRecallTool;
89pub use tools::memory_reflect::MemoryReflectTool;
90pub use tools::memory_retain::MemoryRetainTool;
91pub use tools::search_cache::{GetSearchResultsTool, SearchCache};
92pub use tools::subagent::SubagentTool;
93pub use tools::web_search::WebSearchTool;
94/// Built-in tool implementations and registry.
95pub use tools::{
96    AgentTool, AgentToolResult, BashTool, EditTool, FindTool, GrepTool, LsTool, ReadTool,
97    ToolContext, ToolError, ToolRegistry, WriteTool,
98};
99
100pub use tools::TodoStateProvider;
101pub use tools::todo::{
102    InitListEntry, TodoCompletionTransition, TodoItem, TodoOp, TodoPhase, TodoStatus, TodoTool,
103    TodoUpdateResult,
104};
105
106pub use tools::{AgentHubStatus, AgentInfo, AgentKind, AgentPoolProvider};
107pub use tools::{LspAction, LspProvider};
108
109/// Standard imports for oxi-agent usage.
110pub mod prelude {
111    pub use crate::agent::Agent;
112    pub use crate::agent_loop::{AgentLoop, AgentLoopConfig, ToolExecutionMode};
113    pub use crate::compaction::{CompactedContext, CompactionEvent};
114    pub use crate::config::AgentConfig;
115    pub use crate::events::AgentEvent;
116    pub use crate::mcp::{McpConfig, McpManager, McpTool};
117    pub use crate::state::{AgentState, SharedState};
118    pub use crate::tools::ask::{AskBridge, AskTool};
119    pub use crate::tools::context7::{Context7QueryDocsTool, Context7ResolveLibraryIdTool};
120    pub use crate::tools::github::GitHubTool;
121    pub use crate::tools::github_search::GitHubSearchTool;
122    pub use crate::tools::search_cache::{GetSearchResultsTool, SearchCache};
123    pub use crate::tools::subagent::SubagentTool;
124    pub use crate::tools::web_search::WebSearchTool;
125    pub use crate::tools::{
126        AgentTool, AgentToolResult, BashTool, EditTool, FindTool, GrepTool, LsTool, ReadTool,
127        ToolContext, ToolRegistry, WriteTool,
128    };
129}
130
131#[cfg(test)]
132mod tests;