Skip to main content

rustic_ai/
lib.rs

1//! # RusticAI
2//!
3//! A Rust-native agent framework with tool calling, streaming, and multi-provider
4//! support for OpenAI, Anthropic, Gemini, and Grok.
5//!
6//! ## Quick Start
7//!
8//! ```rust,no_run
9//! use rustic_ai::{Agent, RunInput, UsageLimits, UserContent, infer_model, infer_provider};
10//!
11//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
12//! let model = infer_model("openai:gpt-4o-mini", infer_provider)?;
13//! let agent = Agent::new(model)
14//!     .system_prompt("You are a helpful assistant.");
15//!
16//! let input = RunInput::new(
17//!     vec![UserContent::Text("Hello!".to_string())],
18//!     vec![],
19//!     (),
20//!     UsageLimits::default(),
21//! );
22//!
23//! let result = agent.run(input).await?;
24//! println!("{}", result.output);
25//! # Ok(())
26//! # }
27//! ```
28//!
29//! Type-state builder:
30//!
31//! ```rust,no_run
32//! use rustic_ai::{RunInput, UsageLimits};
33//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
34//! let input = RunInput::builder(())
35//!     .user_text("Hello!")
36//!     .usage_limits(UsageLimits::default())
37//!     .build();
38//! # let _ = input;
39//! # Ok(())
40//! # }
41//! ```
42//!
43//! Typed structured output:
44//!
45//! ```rust,no_run
46//! use rustic_ai::{Agent, RunInput, UsageLimits, UserContent, infer_model, infer_provider};
47//! use schemars::JsonSchema;
48//! use serde::Deserialize;
49//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
50//! #[derive(Deserialize, JsonSchema)]
51//! struct Answer {
52//!     answer: String,
53//! }
54//! let model = infer_model("openai:gpt-4o-mini", infer_provider)?;
55//! let agent = Agent::new(model).output_schema_for::<Answer>();
56//! let input = RunInput::new(
57//!     vec![UserContent::Text("Respond with {\"answer\": \"ok\"}".to_string())],
58//!     vec![],
59//!     (),
60//!     UsageLimits::default(),
61//! );
62//! let _ = agent.run(input).await?;
63//! # Ok(())
64//! # }
65//! ```
66//!
67//! ## Features
68//!
69//! - **Agent orchestration** with tool calling, usage limits, and message history
70//! - **Multi-provider support** for OpenAI, Gemini, Anthropic, and Grok
71//! - **Streaming** with structured events
72//! - **Structured output** validation via JSON schema
73//! - **Deferred tools** for approval flows
74//! - **MCP toolsets** for remote tool integration
75//! - **Instrumentation hooks** with tracing/OpenTelemetry support
76//!
77//! ## Optional Features
78//!
79//! - `telemetry-otel` - OpenTelemetry/OTLP exporter support
80//! - `telemetry-datadog` - Datadog exporter support
81
82#![forbid(unsafe_code)]
83
84pub mod agent;
85pub mod error;
86pub mod failover;
87pub mod instrumentation;
88mod json_schema;
89pub mod mcp;
90pub mod messages;
91pub mod model;
92pub mod model_config;
93pub mod providers;
94pub mod realtime;
95#[cfg(any(feature = "telemetry-otel", feature = "telemetry-datadog"))]
96pub mod telemetry;
97pub mod tools;
98pub mod usage;
99
100pub use agent::{
101    Agent, AgentEventStream, AgentRunResult, AgentRunState, AgentStreamEvent, DeferredToolCall,
102    RunInput, RunInputBuilder,
103};
104pub use error::AgentError;
105pub use failover::{
106    FailoverResult, classify_error_kind, run_with_config, run_with_config_and_classifier,
107    run_with_failover, run_with_failover_with_classifier, run_with_utility_failover,
108    run_with_utility_failover_with_classifier,
109};
110pub use instrumentation::{Instrumenter, NoopInstrumenter, TracingInstrumenter};
111pub use messages::{
112    AudioUrl, BinaryContent, DocumentUrl, ImageUrl, ModelMessage, ModelRequest, ModelRequestPart,
113    ModelResponse, ModelResponsePart, ProviderItemPart, RetryPromptPart, SystemPromptPart,
114    TextPart, ToolCallPart, ToolReturnPart, UserContent, UserPromptPart, VideoUrl,
115};
116pub use model::{
117    Model, ModelError, ModelRequestParameters, ModelSettings, ModelStream, OutputMode, StreamChunk,
118};
119pub use model_config::{
120    CircuitBreakerConfig, InMemoryResolver, ModelConfigEntry, ModelConfigResolver,
121    ResolvedModelConfig,
122};
123pub use providers::{Provider, ProviderError, infer_model, infer_provider};
124pub use realtime::grok::{
125    GrokClient as GrokRealtimeClient, GrokSender as GrokRealtimeSender,
126    ServerEvent as GrokRealtimeEvent, SessionConfig as GrokSessionConfig,
127};
128pub use tools::ToolError;
129pub use tools::{FunctionTool, RunContext, Tool, ToolDefinition, ToolKind, Toolset};
130pub use usage::{RequestUsage, RunUsage, UsageError, UsageLimits};