Skip to main content

agent_io/
lib.rs

1//! # BU Agent SDK
2//!
3//! A Rust SDK for building AI agents with multi-provider LLM support.
4//!
5//! ## Features
6//!
7//! - Multi-provider LLM support (OpenAI, Anthropic, Google Gemini)
8//! - Tool/function calling with dependency injection
9//! - Streaming responses with event-based architecture
10//! - Context compaction for long-running conversations
11//! - Token usage tracking and cost calculation
12//!
13//! ## Quick Start
14//!
15//! ```rust,no_run
16//! use std::sync::Arc;
17//! use agent_io::{Agent, llm::ChatOpenAI, tools::FunctionTool};
18//!
19//! #[tokio::main]
20//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
21//!     let llm = ChatOpenAI::new("gpt-4o")?;
22//!     let agent = Agent::builder()
23//!         .with_llm(Arc::new(llm))
24//!         .build()?;
25//!     
26//!     let response = agent.query("Hello!").await?;
27//!     println!("{}", response);
28//!     Ok(())
29//! }
30//! ```
31
32pub mod agent;
33pub mod llm;
34pub mod memory;
35pub mod observability;
36pub mod tokens;
37pub mod tools;
38
39pub use agent::{Agent, AgentEvent};
40pub use llm::BaseChatModel;
41pub use memory::{EmbeddingProvider, InMemoryStore, MemoryManager, MemoryStore};
42pub use observability::*;
43pub use tokens::TokenCost;
44pub use tools::Tool;
45
46/// Result type alias for SDK operations
47pub type Result<T> = std::result::Result<T, Error>;
48
49/// Error types for the SDK
50#[derive(Debug, thiserror::Error)]
51pub enum Error {
52    #[error("LLM error: {0}")]
53    Llm(#[from] llm::LlmError),
54
55    #[error("Tool error: {0}")]
56    Tool(String),
57
58    #[error("Serialization error: {0}")]
59    Serialization(#[from] serde_json::Error),
60
61    #[error("HTTP error: {0}")]
62    Http(#[from] reqwest::Error),
63
64    #[error("Configuration error: {0}")]
65    Config(String),
66
67    #[error("Agent error: {0}")]
68    Agent(String),
69
70    #[error("Max iterations exceeded")]
71    MaxIterationsExceeded,
72}