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
39/// Re-exports needed by the `#[tool]` proc-macro. Not part of the public API.
40#[doc(hidden)]
41pub mod __macro_support {
42    pub use async_trait::async_trait;
43    pub use serde;
44    pub use serde_json;
45}
46
47// Re-export the `#[tool]` attribute macro
48pub use agent_io_macros::tool;
49
50pub use agent::{Agent, AgentEvent};
51pub use llm::BaseChatModel;
52pub use memory::{EmbeddingProvider, InMemoryStore, MemoryManager, MemoryStore};
53pub use observability::*;
54pub use tokens::TokenCost;
55pub use tools::Tool;
56
57/// Result type alias for SDK operations
58pub type Result<T> = std::result::Result<T, Error>;
59
60/// Error types for the SDK
61#[derive(Debug, thiserror::Error)]
62pub enum Error {
63    #[error("LLM error: {0}")]
64    Llm(#[from] llm::LlmError),
65
66    #[error("Tool error: {0}")]
67    Tool(String),
68
69    #[error("Serialization error: {0}")]
70    Serialization(#[from] serde_json::Error),
71
72    #[error("HTTP error: {0}")]
73    Http(#[from] reqwest::Error),
74
75    #[error("Configuration error: {0}")]
76    Config(String),
77
78    #[error("Agent error: {0}")]
79    Agent(String),
80
81    #[error("Max iterations exceeded")]
82    MaxIterationsExceeded,
83}