Skip to main content

lellm_agent/
lib.rs

1//! lellm-agent — Agent 运行时。
2//!
3//! 提供完整的 Agent 运行时能力:工具系统、Agent Loop、
4//! 循环检测、重试策略、Fallback 降级等。
5
6pub mod hook;
7pub mod runtime;
8
9// Re-export schemars & serde so derive(Tool) / #[tool] macros can reference them.
10pub use schemars;
11pub use serde;
12
13pub use hook::{AgentHook, AgentHookContext, AgentHookSnapshot, NoOpAgentHook, TracingAgentHook};
14pub use runtime::{
15    AgentBuilder, AgentEvent, AgentFlowNode, AgentStream, BackoffStrategy, BatchExecutionResult,
16    CompactionResult, CompositeCatalog, ContextBudget, ContextCompactor, DefaultFallback,
17    FallbackAction, FallbackContext, FallbackStrategy, IntoToolError, IntoToolResult,
18    LocalCompactor, ParallelSafety, ResolvedModel, ResolvedRound, RetryPolicy, StaticCatalog,
19    StopReason, ToolArgs, ToolCatalog, ToolCategory, ToolError, ToolErrorKind, ToolExecutor,
20    ToolRegistration, ToolResult, ToolSnapshot, ToolUseConfig, ToolUseDeps, ToolUseLoop,
21    ToolUseResult, estimate_message, estimate_tokens, execute_batch_with,
22};
23
24// ─── 糖衣 API(第三层原型) ───
25
26/// 便捷创建 Agent — 生态包糖衣 API 原型。
27///
28/// 这是未来 `lellm-openai` / `lellm-anthropic` 等生态包中
29/// `create_agent()` 的简化版本。
30///
31/// # 示例
32/// ```ignore
33/// use lellm_agent::{create_agent, ToolRegistration};
34///
35/// // 无工具的简单 Agent
36/// let agent = create_agent(model);
37///
38/// // 带工具的 Agent
39/// let agent = create_agent_with_tools(model, vec![search, weather]);
40/// ```
41///
42/// 快速创建一个无工具的 Agent。
43pub fn create_agent(model: ResolvedModel) -> ToolUseLoop {
44    AgentBuilder::new(model).build()
45}
46
47/// 快速创建带工具的 Agent。
48pub fn create_agent_with_tools(
49    model: ResolvedModel,
50    tools: impl IntoIterator<Item = ToolRegistration>,
51) -> ToolUseLoop {
52    AgentBuilder::new(model).tools(tools).build()
53}
54
55/// 快速创建带系统提示的 Agent。
56pub fn create_agent_with_system(model: ResolvedModel, system_prompt: String) -> ToolUseLoop {
57    AgentBuilder::new(model)
58        .system_prompt(system_prompt)
59        .build()
60}
61
62/// 完整配置的便捷创建。
63pub fn create_agent_full(
64    model: ResolvedModel,
65    system_prompt: String,
66    tools: impl IntoIterator<Item = ToolRegistration>,
67    max_iterations: usize,
68) -> ToolUseLoop {
69    AgentBuilder::new(model)
70        .system_prompt(system_prompt)
71        .tools(tools)
72        .max_iterations(max_iterations)
73        .build()
74}