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
146#[cfg(feature = "test-utils")]
147pub mod test_utils;
148
149pub use agent::{
150 Agent, AgentBuilder, AgentError, AgentResponse, ContextConfig, ContextError, ContextLoadResult,
151 ContextSource, PermissionError, TokenUsageStats, ToolCallInfo, ToolInfo,
152 DEFAULT_MAX_CONCURRENT_TOOLS, DEFAULT_PERMISSION_TIMEOUT,
153};
154pub use conversation::{
155 BoxedConversationManager, ContextLimits, ContextUsage, ConversationManager,
156 NoOpConversationManager, SimpleConversationManager, SlidingWindowConversationManager,
157 TokenEstimator,
158};
159pub use error::{Error, Result};
160pub use events::{AgentEvent, AgentHook, HookId, TokenUsage};
161
162pub use model::{
163 AnthropicModel, BedrockModel, InferenceProfile, Model, ModelRequest, ModelResponse,
164 RuntimeBedrockModel,
165};
166
167// Permission system
168pub use permission::{
169 hash_params, Authorization, AuthorizationResponse, FileGrantStore, Grant, GrantStore,
170 GrantStoreError, MemoryGrantStore, Scope, ToolAuthorizationPolicy, ToolCallAuthorizer,
171};
172pub use presentation::Display;
173
174// Providers - core types always available
175pub use provider::{ModelProvider, ProviderError, RetryConfig, RetryInfo, StreamEvent};
176
177// Provider implementations - feature-gated
178#[cfg(feature = "anthropic")]
179pub use provider::AnthropicProvider;
180#[cfg(feature = "bedrock")]
181pub use provider::{BedrockChatCompletionsProvider, BedrockProvider, BedrockResponsesProvider};
182
183// Models — separate `pub use` blocks per vendor so cargo fmt sorts within each
184// block independently rather than merging across vendor boundaries.
185
186// Anthropic Claude
187pub use models::{
188 Claude3_7Sonnet, ClaudeHaiku4_5, ClaudeOpus4, ClaudeOpus4_1, ClaudeOpus4_5, ClaudeOpus4_6,
189 ClaudeSonnet4, ClaudeSonnet4_5, ClaudeSonnet4_6,
190};
191// Amazon Nova
192pub use models::{Nova2Lite, Nova2Sonic, NovaLite, NovaMicro, NovaPremier, NovaPro};
193// Cohere
194pub use models::CohereCommandRPlus;
195// DeepSeek
196pub use models::{DeepSeekR1, DeepSeekV3_1, DeepSeekV3_2};
197// Z.AI GLM
198pub use models::{GLM4_7Flash, GLM4_7};
199// Google
200pub use models::{Gemma3_12B, Gemma3_27B, Gemma3_4B};
201// Meta Llama
202pub use models::{
203 Llama3_1_405B, Llama3_1_70B, Llama3_1_8B, Llama3_2_11B, Llama3_2_1B, Llama3_2_3B, Llama3_2_90B,
204 Llama3_3_70B, Llama4Maverick17B, Llama4Scout17B,
205};
206// MiniMax
207pub use models::MiniMaxM2_1;
208// Mistral
209pub use models::{
210 MagistralSmall, Ministral14B, Ministral3B, Ministral8B, MistralLarge3, PixtralLarge,
211 VoxtralMini3B, VoxtralSmall24B,
212};
213// Moonshot Kimi
214pub use models::{KimiK2Thinking, KimiK2_5};
215// Alibaba Qwen
216pub use models::{
217 Qwen3Coder30B, Qwen3Coder480B, Qwen3CoderNext, Qwen3Next80B, Qwen3VL235B, Qwen3_235B, Qwen3_32B,
218};
219
220pub use tokenizer::CharacterTokenizer;
221pub use tool::{box_tool, DocumentFormat, DynTool, ImageFormat, Tool, ToolError, ToolResult};
222pub use types::{
223 ContentBlock, Message, Role, StopReason, ThinkingConfig, ToolDefinition, ToolResultBlock,
224 ToolResultStatus, ToolUseBlock,
225};
226
227#[cfg(feature = "session")]
228pub use agent::SessionInfo;
229
230#[cfg(feature = "session")]
231pub use session::{
232 MessageRole, Session, SessionError, SessionMessage, SessionStore, SessionSummary, ToolCall,
233 ToolResult as SessionToolResult,
234};