mixtape_core/lib.rs
1//! # Mixtape
2//!
3//! A Rust SDK for building AI agents with tool use, streaming, and multi-provider support.
4//!
5//! Mixtape provides a high-level API for creating conversational AI agents that can use tools,
6//! stream responses, and work with multiple LLM providers (AWS Bedrock, Anthropic API).
7//!
8//! ## Quick Start
9//!
10//! ```ignore
11//! use mixtape_core::{Agent, ClaudeSonnet4_5};
12//!
13//! #[tokio::main]
14//! async fn main() -> mixtape_core::Result<()> {
15//! // Create an agent with Bedrock provider
16//! let agent = Agent::builder()
17//! .bedrock(ClaudeSonnet4_5)
18//! .with_system_prompt("You are a helpful assistant.")
19//! .build()
20//! .await?;
21//!
22//! // Run a conversation
23//! let response = agent.run("What is 2 + 2?").await?;
24//! println!("{}", response);
25//!
26//! Ok(())
27//! }
28//! ```
29//!
30//! ## Features
31//!
32//! - **Multiple Providers**: Support for AWS Bedrock and Anthropic API
33//! - **Tool Use**: Define custom tools with automatic JSON schema generation
34//! - **Streaming**: Real-time response streaming with event hooks
35//! - **Session Management**: Persist conversations across runs (optional)
36//! - **MCP Support**: Connect to Model Context Protocol servers (optional)
37//! - **Extended Thinking**: Enable Claude's reasoning capabilities
38//!
39//! ## Creating Agents
40//!
41//! Use the builder pattern to create agents:
42//!
43//! ```ignore
44//! use mixtape_core::{Agent, ClaudeSonnet4_5};
45//!
46//! # async fn example() -> mixtape_core::Result<()> {
47//! // Using AWS Bedrock
48//! let agent = Agent::builder()
49//! .bedrock(ClaudeSonnet4_5)
50//! .build()
51//! .await?;
52//!
53//! // Using Anthropic API directly
54//! let agent = Agent::builder()
55//! .anthropic(ClaudeSonnet4_5, "sk-ant-api-key")
56//! .build()
57//! .await?;
58//! # Ok(())
59//! # }
60//! ```
61//!
62//! ## Adding Tools
63//!
64//! Implement the [`Tool`] trait to create custom tools:
65//!
66//! ```ignore
67//! use mixtape_core::{Tool, ToolError, ToolResult};
68//! use schemars::JsonSchema;
69//! use serde::{Deserialize, Serialize};
70//!
71//! #[derive(Debug, Deserialize, Serialize, JsonSchema)]
72//! struct CalculatorInput {
73//! expression: String,
74//! }
75//!
76//! struct Calculator;
77//!
78//! impl Tool for Calculator {
79//! type Input = CalculatorInput;
80//!
81//! fn name(&self) -> &str { "calculator" }
82//! fn description(&self) -> &str { "Evaluate a math expression" }
83//!
84//! async fn execute(&self, input: Self::Input) -> Result<ToolResult, ToolError> {
85//! // Parse and evaluate the expression
86//! Ok(ToolResult::text("42"))
87//! }
88//! }
89//! ```
90//!
91//! Add tools to an agent with `add_tool()` or `add_tools()`:
92//!
93//! ```ignore
94//! use mixtape_core::{Agent, box_tools, ClaudeSonnet4};
95//!
96//! // Single tool
97//! let agent = Agent::builder()
98//! .bedrock(ClaudeSonnet4)
99//! .add_tool(Calculator)
100//! .build()
101//! .await?;
102//!
103//! // Multiple heterogeneous tools with the box_tools! macro
104//! let agent = Agent::builder()
105//! .bedrock(ClaudeSonnet4)
106//! .add_tools(box_tools![Calculator, WeatherLookup, FileReader])
107//! .build()
108//! .await?;
109//!
110//! // Tool groups from mixtape-tools
111//! use mixtape_tools::sqlite;
112//!
113//! let agent = Agent::builder()
114//! .bedrock(ClaudeSonnet4)
115//! .add_tools(sqlite::read_only_tools())
116//! .build()
117//! .await?;
118//! ```
119//!
120//! ## Feature Flags
121//!
122//! - `bedrock` - AWS Bedrock provider support (enabled by default)
123//! - `anthropic` - Anthropic API provider support
124//! - `session` - Session persistence for multi-turn conversations
125//! - `mcp` - Model Context Protocol server integration
126
127pub mod agent;
128pub mod conversation;
129pub mod error;
130pub mod events;
131pub mod model;
132pub mod models;
133pub mod permission;
134pub mod presentation;
135pub mod provider;
136pub mod tokenizer;
137pub mod tool;
138pub mod types;
139
140#[cfg(feature = "mcp")]
141pub mod mcp;
142
143#[cfg(feature = "session")]
144pub mod session;
145
146pub use agent::{
147 Agent, AgentBuilder, AgentError, AgentResponse, ContextConfig, ContextError, ContextLoadResult,
148 ContextSource, PermissionError, TokenUsageStats, ToolCallInfo, ToolInfo,
149 DEFAULT_MAX_CONCURRENT_TOOLS, DEFAULT_PERMISSION_TIMEOUT,
150};
151pub use conversation::{
152 BoxedConversationManager, ContextLimits, ContextUsage, ConversationManager,
153 NoOpConversationManager, SimpleConversationManager, SlidingWindowConversationManager,
154 TokenEstimator,
155};
156pub use error::{Error, Result};
157pub use events::{AgentEvent, AgentHook, TokenUsage};
158
159pub use model::{
160 AnthropicModel, BedrockModel, InferenceProfile, Model, ModelRequest, ModelResponse,
161};
162
163// Permission system
164pub use permission::{
165 hash_params, Authorization, AuthorizationResponse, FileGrantStore, Grant, GrantStore,
166 GrantStoreError, MemoryGrantStore, Scope, ToolAuthorizationPolicy, ToolCallAuthorizer,
167};
168pub use presentation::Display;
169
170// Providers - core types always available
171pub use provider::{ModelProvider, ProviderError, RetryConfig, RetryInfo, StreamEvent};
172
173// Provider implementations - feature-gated
174#[cfg(feature = "anthropic")]
175pub use provider::AnthropicProvider;
176#[cfg(feature = "bedrock")]
177pub use provider::BedrockProvider;
178
179// Models (organized by vendor)
180pub use models::{
181 // Anthropic Claude
182 Claude3_7Sonnet,
183 ClaudeHaiku4_5,
184 ClaudeOpus4,
185 ClaudeOpus4_5,
186 ClaudeSonnet4,
187 ClaudeSonnet4_5,
188 // Cohere
189 CohereCommandRPlus,
190 // DeepSeek
191 DeepSeekR1,
192 DeepSeekV3,
193 // Google
194 Gemma3_27B,
195 // Moonshot Kimi
196 KimiK2Thinking,
197 // Meta Llama
198 Llama3_1_405B,
199 Llama3_1_70B,
200 Llama3_1_8B,
201 Llama3_2_11B,
202 Llama3_2_1B,
203 Llama3_2_3B,
204 Llama3_2_90B,
205 Llama3_3_70B,
206 Llama4Maverick17B,
207 Llama4Scout17B,
208 // Mistral
209 MagistralSmall,
210 MistralLarge3,
211 // Amazon Nova
212 Nova2Lite,
213 NovaLite,
214 NovaMicro,
215 NovaPremier,
216 NovaPro,
217 // Alibaba Qwen
218 Qwen3Coder480B,
219 Qwen3_235B,
220};
221
222pub use tokenizer::CharacterTokenizer;
223pub use tool::{box_tool, DocumentFormat, DynTool, ImageFormat, Tool, ToolError, ToolResult};
224pub use types::{
225 ContentBlock, Message, Role, StopReason, ThinkingConfig, ToolDefinition, ToolResultBlock,
226 ToolResultStatus, ToolUseBlock,
227};
228
229#[cfg(feature = "session")]
230pub use agent::SessionInfo;
231
232#[cfg(feature = "session")]
233pub use session::{
234 MessageRole, Session, SessionError, SessionMessage, SessionStore, SessionSummary, ToolCall,
235 ToolResult as SessionToolResult,
236};