Skip to main content

lc_agents/
lib.rs

1#![warn(missing_docs)]
2// lc-agents/src/lib.rs
3//! Agent system for building autonomous LLM applications.
4//!
5//! Provides core abstractions and implementations for agents.
6//!
7//! # Core Concepts
8//!
9//! - **Agent**: Responsible for planning, deciding what action to execute next.
10//! - **AgentExecutor**: Responsible for execution loop (plan -> act -> observe).
11//! - **Tool**: Callable tools that agents can invoke.
12//!
13//! # Execution Flow
14//!
15//! ```text
16//! Input question
17//!     |
18//! Agent.plan() -> AgentAction or AgentFinish
19//!     |
20//! If Action: execute tool -> get observation
21//!     |
22//! Add to intermediate_steps
23//!     |
24//! Loop until AgentFinish returned
25//! ```
26
27pub mod adapter;
28pub mod adaptive_rag;
29/// Approval gate (§4.2): asynchronous approval gate before tool execution.
30/// Implement [`ApprovalHandler`] and inject it via [`AgentExecutor::with_approval`];
31/// off by default.
32pub mod approval;
33pub mod executor;
34/// Module alias preserving the historical `lc_agents::base` path.
35pub use executor as base;
36pub mod builder;
37pub mod cache;
38pub mod crag;
39pub mod deep_research;
40/// Function calling based agent module.
41pub mod function_calling;
42pub mod handoffs;
43pub mod hooks;
44/// B4 (v0.22.4): LLM-backed semantic-memory extractor turning a completed turn
45/// into durable [`lc_memory::MemoryItem`]s.
46pub mod memory_extractor;
47pub mod metrics;
48pub mod orchestrator;
49/// Module alias preserving the historical `lc_agents::orchestration` path.
50pub use orchestrator as orchestration;
51pub mod plan_execute;
52pub mod policy;
53pub mod react;
54/// Cross-process resume (§4.2 approval/budget gate): suspend-state persistence +
55/// recovery. The framework writes/clears checkpoints ([`ResumeStore`]) around
56/// approvals; a new process inspects via [`AgentExecutor::pending_approval`] and
57/// resumes via [`AgentExecutor::resume`]. Off by default (no [`ResumeStore`] ⇒ no
58/// serialization; existing behavior unchanged).
59pub mod resume;
60pub mod retry;
61pub mod streaming;
62mod structured;
63pub mod task;
64pub mod types;
65
66pub use adapter::{AgentEventRunnable, AgentRunnable, OrchestratorRunnable};
67pub use adaptive_rag::{AdaptiveRAG, AdaptiveRAGError, AdaptiveRAGResult, RagDecision};
68pub use approval::{AllowAll, ApprovalDecision, ApprovalHandler};
69pub use builder::AgentBuilder;
70pub use cache::{MemoryCache, ResponseCache};
71pub use crag::{CRAGError, CRAGResult, CorrectiveRAGAgent};
72pub use deep_research::{Citation, DeepResearchAgent, ResearchError, ResearchReport};
73pub use executor::{
74    estimate_step_tokens, AgentError, AgentExecutor, BaseAgent, BudgetConfig, BudgetExceeded,
75    CompactionConfig, CompactionStrategy, CompactionTrigger,
76};
77pub use function_calling::FunctionCallingAgent;
78pub use handoffs::HandoffManager;
79pub use hooks::{
80    AgentHook, ApprovalHook, CompletionAction, CompletionContext, CompletionResult,
81    ContentFilterHook, ErrorAction, HookError, LoggingHook, PromptInjectionHook, StreamAction,
82    TokenBudgetHook, ToolCallAction, ToolCallContext, ToolResultContext,
83};
84pub use memory_extractor::LlmMemoryExtractor;
85pub use metrics::AgentMetrics;
86pub use orchestrator::{
87    parse_review_verdict, review_envelope, task_adapter, FanOutFanIn, Orchestrator,
88    ReviewOrchestrator, ReviewVerdict, RunContext, SequentialPipeline, TaskAdapter,
89};
90pub use plan_execute::{PlanExecuteAgent, PlanExecuteError};
91pub use policy::{ToolPolicy, ToolRisk};
92pub use react::ReActAgent;
93pub use resume::{FileResumeStore, MemoryResumeStore, PendingApproval, ResumeError, ResumeStore};
94pub use retry::RetryConfig;
95// B8 (v0.22.4): framework-neutral SSE framing is always exported; the axum
96// serving pieces come in under the `sse-server` feature.
97pub use streaming::{
98    agent_sse_frames, encode_sse_frame, sse_event_name, sse_event_payload, AgentEventStream,
99    AgentSseRequest, AgentStreamEvent, SseFrame, SseOptions, StreamingFunctionCallingAgent,
100    ToolCallState,
101};
102#[cfg(feature = "sse-server")]
103pub use streaming::{
104    agent_sse_get_handler, agent_sse_handler, agent_sse_router, agent_sse_router_with,
105    serve_agent_sse, serve_agent_sse_on, AgentSseQuery, AgentSseServerConfig, AgentSseState,
106    AgentStreamFactory, AgentStreamFuture, DEFAULT_SSE_HEARTBEAT,
107};
108pub use task::AgentTask;
109pub use types::{AgentAction, AgentFinish, AgentOutput, AgentStep, ToolInput};