Expand description
§Aquaregia
A provider-agnostic Rust toolkit for building AI applications and tool-using agents.
Aquaregia provides a unified API across OpenAI, Anthropic, Google, and OpenAI-compatible services, with first-class support for reasoning-aware output, streaming events, multi-step tool execution, and vision/image inputs.
§Features
- Unified Provider API: One
LlmClientbinds to one provider configuration with support for OpenAI, Anthropic, Google, and OpenAI-compatible endpoints. - Streaming & Non-Streaming: Both
generateandstreamAPIs with consistent event handling. - Reasoning Support: First-class reasoning content extraction and streaming events.
- Tool-Using Agents: Multi-step agent loops with configurable tool execution and error handling.
- Multimodal Vision: Send images to vision-capable models via URL, base64, or raw bytes.
- Cancellation: All requests and agent runs support cancellation via
CancellationToken. - Telemetry: Optional
tracingspans for generate, stream, and agent operations.
§Quick Start
use aquaregia::{GenerateTextRequest, LlmClient};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let client = LlmClient::openai_compatible("https://api.deepseek.com")
.api_key(std::env::var("DEEPSEEK_API_KEY")?)
.build()?;
let out = client
.generate(GenerateTextRequest::from_user_prompt(
"deepseek-chat",
"Explain Rust ownership in 3 bullet points.",
))
.await?;
println!("{}", out.output_text);
Ok(())
}§Crate Features
| Feature | Description |
|---|---|
openai | OpenAI adapter (default) |
anthropic | Anthropic adapter (default) |
telemetry | tracing spans for generate, stream, agent steps and tool calls |
axum | Axum SSE bridge for converting streams into SSE responses |
§Architecture
LlmClient: Entry point for creating provider-bound clients.BoundClient: Reusable client forgenerate,stream, and agent loops.Agent: Multi-step tool-using agent with configurable hooks.ModelAdapter: Trait for provider-specific request/response handling.Tool: Executable tool definitions with JSON Schema validation.
Re-exports§
pub use agent::Agent;pub use agent::AgentBuilder;pub use agent::AgentRunPlan;pub use client::BoundClient;pub use client::ClientBuilder;pub use client::LlmClient;pub use error::Error;pub use error::ErrorCode;pub use model_adapters::ModelAdapter;pub use model_adapters::anthropic::AnthropicAdapterSettings;pub use model_adapters::google::GoogleAdapterSettings;pub use model_adapters::openai::OpenAiAdapterSettings;pub use model_adapters::openai_compatible::OpenAiCompatibleAdapterSettings;pub use tool::IntoTool;pub use tool::Tool;pub use tool::ToolBuilder;pub use tool::ToolDescriptor;pub use tool::ToolExecError;pub use tool::ToolExecutor;pub use tool::ToolRegistry;pub use tool::tool;pub use types::AgentFinish;pub use types::AgentPrepareStep;pub use types::AgentPreparedStep;pub use types::AgentResponse;pub use types::AgentStart;pub use types::AgentStep;pub use types::AgentStepStart;pub use types::AgentToolCallFinish;pub use types::AgentToolCallStart;pub use types::Anthropic;pub use types::ContentPart;pub use types::FinishReason;pub use types::GenerateTextRequest;pub use types::GenerateTextResponse;pub use types::Google;pub use types::ImagePart;pub use types::IntoModelRef;pub use types::MediaData;pub use types::Message;pub use types::MessageRole;pub use types::ModelRef;pub use types::OpenAi;pub use types::OpenAiCompatible;pub use types::ProviderKind;pub use types::ProviderMarker;pub use types::ReasoningPart;pub use types::StreamEvent;pub use types::TextDeltaStream;pub use types::TextStream;pub use types::ToolCall;pub use types::ToolErrorPolicy;pub use types::ToolResult;pub use types::Usage;
Modules§
- agent
- Agent runtime and builder APIs. Agent runtime and builder APIs for Aquaregia.
- client
- Provider-bound client types and retry behavior. Provider-bound client types and retry behavior for Aquaregia.
- error
- Unified error types and HTTP-to-error mapping helpers. Unified error types and HTTP-to-error mapping helpers for Aquaregia.
- model_
adapters - Provider adapter traits and concrete provider implementations. Provider adapter traits and concrete provider implementations for Aquaregia.
- stream
- SSE frame parsing helpers used by streaming adapters. SSE (Server-Sent Events) frame parsing helpers for Aquaregia streaming.
- tool
- Tool definition, execution, and registry types. Tool definition, execution, and registry types for Aquaregia agents.
- types
- Shared request/response and event types. Shared request/response types and streaming events for Aquaregia.
Structs§
- Cancellation
Token - A token which can be used to signal a cancellation request to one or more tasks.
Functions§
- anthropic
- Creates a typed Anthropic model reference (
anthropic/<model>). - Creates a typed Google model reference (
google/<model>). - openai
- Creates a typed OpenAI model reference (
openai/<model>). - openai_
compatible - Creates a typed OpenAI-compatible model reference (
openai-compatible/<model>).