agents_sdk/
lib.rs

1//! # Rust Deep Agents SDK
2//!
3//! High-performance Rust framework for composing reusable "deep" AI agents with custom tools,
4//! sub-agents, and prompts.
5//!
6//! ## Quick Start
7//!
8//! ```toml
9//! [dependencies]
10//! agents-sdk = "0.0.1"  # Includes toolkit by default
11//! ```
12//!
13//! ```rust,no_run
14//! # #[cfg(feature = "toolkit")]
15//! # {
16//! use agents_sdk::{ConfigurableAgentBuilder, get_default_model, create_tool};
17//! use serde_json::Value;
18//!
19//! # async fn example() -> anyhow::Result<()> {
20//!     // Create a simple tool
21//!     let my_tool = create_tool(
22//!         "greet",
23//!         "Greets a person by name",
24//!         |args: Value| async move {
25//!             let name = args.get("name")
26//!                 .and_then(|v| v.as_str())
27//!                 .unwrap_or("World");
28//!             Ok(format!("Hello, {}!", name))
29//!         }
30//!     );
31//!
32//!     // Build an agent with the default model
33//!     let agent = ConfigurableAgentBuilder::new("You are a helpful assistant.")
34//!         .with_model(get_default_model()?)
35//!         .with_tool(my_tool)
36//!         .build()?;
37//!
38//!     // Use the agent
39//!     use agents_sdk::state::AgentStateSnapshot;
40//!     use std::sync::Arc;
41//!
42//!     let response = agent.handle_message(
43//!         "Please greet Alice using the greet tool",
44//!         Arc::new(AgentStateSnapshot::default())
45//!     ).await?;
46//!     println!("{:?}", response);
47//! # Ok(())
48//! # }
49//! # }
50//! ```
51//!
52//! ## Features
53//!
54//! - `toolkit` (default): Includes agents-toolkit with built-in tools
55//! - `aws`: Includes AWS integrations
56//! - `redis`: Redis-backed state persistence
57//! - `postgres`: PostgreSQL-backed state persistence
58//! - `dynamodb`: DynamoDB-backed state persistence (AWS)
59//! - `persistence`: Grouped feature for Redis + PostgreSQL
60//! - `aws-full`: Grouped feature for AWS + DynamoDB
61//! - `full`: Includes all features
62//!
63//! ## Installation Options
64//!
65//! ```toml
66//! # Default installation with toolkit
67//! agents-sdk = "0.0.1"
68//!
69//! # Core only (minimal installation)
70//! agents-sdk = { version = "0.0.1", default-features = false }
71//!
72//! # With specific persistence backend
73//! agents-sdk = { version = "0.0.1", features = ["redis"] }
74//! agents-sdk = { version = "0.0.1", features = ["postgres"] }
75//! agents-sdk = { version = "0.0.1", features = ["dynamodb"] }
76//!
77//! # With AWS integrations
78//! agents-sdk = { version = "0.0.1", features = ["aws-full"] }
79//!
80//! # Everything included
81//! agents-sdk = { version = "0.0.1", features = ["full"] }
82//! ```
83//!
84//! ## Persistence Examples
85//!
86//! ### Redis Checkpointer
87//!
88//! ```rust,no_run
89//! # #[cfg(feature = "redis")]
90//! # {
91//! use agents_sdk::{RedisCheckpointer, ConfigurableAgentBuilder};
92//! use std::sync::Arc;
93//!
94//! # async fn example() -> anyhow::Result<()> {
95//! let checkpointer = Arc::new(
96//!     RedisCheckpointer::new("redis://127.0.0.1:6379").await?
97//! );
98//!
99//! let agent = ConfigurableAgentBuilder::new("You are a helpful assistant")
100//!     .with_checkpointer(checkpointer)
101//!     .build()?;
102//! # Ok(())
103//! # }
104//! # }
105//! ```
106//!
107//! ### PostgreSQL Checkpointer
108//!
109//! ```rust,no_run
110//! # #[cfg(feature = "postgres")]
111//! # {
112//! use agents_sdk::{PostgresCheckpointer, ConfigurableAgentBuilder};
113//! use std::sync::Arc;
114//!
115//! # async fn example() -> anyhow::Result<()> {
116//! let checkpointer = Arc::new(
117//!     PostgresCheckpointer::new("postgresql://user:pass@localhost/agents").await?
118//! );
119//!
120//! let agent = ConfigurableAgentBuilder::new("You are a helpful assistant")
121//!     .with_checkpointer(checkpointer)
122//!     .build()?;
123//! # Ok(())
124//! # }
125//! # }
126//! ```
127//!
128//! ### DynamoDB Checkpointer
129//!
130//! ```rust,no_run
131//! # #[cfg(feature = "dynamodb")]
132//! # {
133//! use agents_sdk::{DynamoDbCheckpointer, ConfigurableAgentBuilder};
134//! use std::sync::Arc;
135//!
136//! # async fn example() -> anyhow::Result<()> {
137//! let checkpointer = Arc::new(
138//!     DynamoDbCheckpointer::new("agent-checkpoints").await?
139//! );
140//!
141//! let agent = ConfigurableAgentBuilder::new("You are a helpful assistant")
142//!     .with_checkpointer(checkpointer)
143//!     .build()?;
144//! # Ok(())
145//! # }
146//! # }
147//! ```
148
149#![deny(missing_docs)]
150#![cfg_attr(docsrs, feature(doc_cfg))]
151
152// Re-export core functionality (always available)
153pub use agents_core::agent::{AgentHandle, AgentStream};
154pub use agents_core::llm::{ChunkStream, StreamChunk};
155pub use agents_core::tools::{
156    Tool, ToolBox, ToolContext, ToolParameterSchema, ToolRegistry, ToolResult, ToolSchema,
157};
158pub use agents_core::{agent, hitl, llm, messaging, persistence, state, tools};
159pub use agents_runtime::{
160    create_async_deep_agent,
161    create_deep_agent,
162    get_default_model,
163    // Provider configurations and models
164    AnthropicConfig,
165    AnthropicMessagesModel,
166    ConfigurableAgentBuilder,
167    DeepAgent,
168    GeminiChatModel,
169    GeminiConfig,
170    OpenAiChatModel,
171    OpenAiConfig,
172    SubAgentConfig,
173    SummarizationConfig,
174};
175
176// Re-export toolkit functionality (when toolkit feature is enabled)
177#[cfg(feature = "toolkit")]
178#[cfg_attr(docsrs, doc(cfg(feature = "toolkit")))]
179pub use agents_toolkit::*;
180
181// Re-export procedural macros from toolkit
182#[cfg(feature = "toolkit")]
183pub use agents_macros::tool;
184
185// Re-export AWS functionality (when aws feature is enabled)
186#[cfg(feature = "aws")]
187#[cfg_attr(docsrs, doc(cfg(feature = "aws")))]
188pub use agents_aws::*;
189
190// Re-export persistence functionality (when persistence features are enabled)
191#[cfg(feature = "redis")]
192#[cfg_attr(docsrs, doc(cfg(feature = "redis")))]
193pub use agents_persistence::RedisCheckpointer;
194
195#[cfg(feature = "postgres")]
196#[cfg_attr(docsrs, doc(cfg(feature = "postgres")))]
197pub use agents_persistence::PostgresCheckpointer;
198
199/// Prelude module for common imports
200///
201/// ```rust
202/// use agents_sdk::prelude::*;
203/// ```
204pub mod prelude {
205
206    // Core types
207    pub use agents_core::agent::{AgentHandle, PlannerHandle};
208    pub use agents_core::messaging::{AgentMessage, MessageContent, MessageRole, ToolInvocation};
209    pub use agents_core::persistence::{Checkpointer, ThreadId};
210    pub use agents_core::state::AgentStateSnapshot;
211
212    // Runtime essentials
213    pub use agents_runtime::{get_default_model, ConfigurableAgentBuilder};
214
215    // Toolkit utilities (when available)
216    #[cfg(feature = "toolkit")]
217    pub use agents_toolkit::{tool, tool_sync, ToolBuilder};
218}
219
220// Convenience re-exports for the most commonly used items already handled above
221
222#[cfg(feature = "toolkit")]
223pub use agents_toolkit::{tool_sync, ToolBuilder};