Skip to main content

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};
165
166// Permission system
167pub use permission::{
168    hash_params, Authorization, AuthorizationResponse, FileGrantStore, Grant, GrantStore,
169    GrantStoreError, MemoryGrantStore, Scope, ToolAuthorizationPolicy, ToolCallAuthorizer,
170};
171pub use presentation::Display;
172
173// Providers - core types always available
174pub use provider::{ModelProvider, ProviderError, RetryConfig, RetryInfo, StreamEvent};
175
176// Provider implementations - feature-gated
177#[cfg(feature = "anthropic")]
178pub use provider::AnthropicProvider;
179#[cfg(feature = "bedrock")]
180pub use provider::BedrockProvider;
181
182// Models — separate `pub use` blocks per vendor so cargo fmt sorts within each
183// block independently rather than merging across vendor boundaries.
184
185// Anthropic Claude
186pub use models::{
187    Claude3_7Sonnet, ClaudeHaiku4_5, ClaudeOpus4, ClaudeOpus4_1, ClaudeOpus4_5, ClaudeOpus4_6,
188    ClaudeSonnet4, ClaudeSonnet4_5,
189};
190// Amazon Nova
191pub use models::{Nova2Lite, Nova2Sonic, NovaLite, NovaMicro, NovaPremier, NovaPro};
192// Cohere
193pub use models::CohereCommandRPlus;
194// DeepSeek
195pub use models::{DeepSeekR1, DeepSeekV3_1, DeepSeekV3_2};
196// Google
197pub use models::{Gemma3_12B, Gemma3_27B, Gemma3_4B};
198// Meta Llama
199pub use models::{
200    Llama3_1_405B, Llama3_1_70B, Llama3_1_8B, Llama3_2_11B, Llama3_2_1B, Llama3_2_3B, Llama3_2_90B,
201    Llama3_3_70B, Llama4Maverick17B, Llama4Scout17B,
202};
203// Mistral
204pub use models::{
205    MagistralSmall, Ministral14B, Ministral3B, Ministral8B, MistralLarge3, PixtralLarge,
206    VoxtralMini3B, VoxtralSmall24B,
207};
208// Moonshot Kimi
209pub use models::{KimiK2Thinking, KimiK2_5};
210// Alibaba Qwen
211pub use models::{Qwen3Coder30B, Qwen3Coder480B, Qwen3Next80B, Qwen3VL235B, Qwen3_235B, Qwen3_32B};
212
213pub use tokenizer::CharacterTokenizer;
214pub use tool::{box_tool, DocumentFormat, DynTool, ImageFormat, Tool, ToolError, ToolResult};
215pub use types::{
216    ContentBlock, Message, Role, StopReason, ThinkingConfig, ToolDefinition, ToolResultBlock,
217    ToolResultStatus, ToolUseBlock,
218};
219
220#[cfg(feature = "session")]
221pub use agent::SessionInfo;
222
223#[cfg(feature = "session")]
224pub use session::{
225    MessageRole, Session, SessionError, SessionMessage, SessionStore, SessionSummary, ToolCall,
226    ToolResult as SessionToolResult,
227};