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