Skip to main content

agent_io/
lib.rs

1//! # Agent IO
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, and OpenAI-compatible providers)
8//! - Tool/function calling with the built-in `#[tool]` macro or manual builders
9//! - Streaming responses with event-based architecture
10//! - Context compaction for long-running conversations
11//! - Token usage tracking and cost calculation
12//! - In-memory memory by default, with optional LanceDB persistence via `memory-lancedb`
13//!
14//! ## Quick Start
15//!
16//! ```rust,no_run
17//! use std::sync::Arc;
18//! use agent_io::{Agent, llm::ChatOpenAI, tools::FunctionTool};
19//!
20//! #[tokio::main]
21//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
22//!     let llm = ChatOpenAI::new("gpt-4o")?;
23//!     let agent = Agent::builder()
24//!         .with_llm(Arc::new(llm))
25//!         .build()?;
26//!     
27//!     let response = agent.query("Hello!").await?;
28//!     println!("{}", response);
29//!     Ok(())
30//! }
31//! ```
32
33pub mod agent;
34pub mod llm;
35pub mod memory;
36pub mod observability;
37pub mod tokens;
38pub mod tools;
39
40/// Re-exports needed by the `#[tool]` proc-macro. Not part of the public API.
41#[doc(hidden)]
42pub mod __macro_support {
43    pub use async_trait::async_trait;
44    pub use serde;
45    pub use serde_json;
46}
47
48// Re-export the `#[tool]` attribute macro
49pub use agent_io_macros::tool;
50
51pub use agent::{Agent, AgentEvent};
52pub use llm::BaseChatModel;
53pub use memory::{EmbeddingProvider, InMemoryStore, MemoryManager, MemoryStore};
54pub use observability::*;
55pub use tokens::TokenCost;
56pub use tools::Tool;
57
58/// Result type alias for SDK operations
59pub type Result<T> = std::result::Result<T, Error>;
60
61/// Error types for the SDK
62#[derive(Debug, thiserror::Error)]
63pub enum Error {
64    #[error("LLM error: {0}")]
65    Llm(#[from] llm::LlmError),
66
67    #[error("Tool error: {0}")]
68    Tool(String),
69
70    #[error("Serialization error: {0}")]
71    Serialization(#[from] serde_json::Error),
72
73    #[error("HTTP error: {0}")]
74    Http(#[from] reqwest::Error),
75
76    #[error("Configuration error: {0}")]
77    Config(String),
78
79    #[error("Agent error: {0}")]
80    Agent(String),
81
82    #[error("Max iterations exceeded")]
83    MaxIterationsExceeded,
84}