Skip to main content

rig_agent/
lib.rs

1#![cfg_attr(docsrs, feature(doc_cfg))]
2#![cfg_attr(
3    test,
4    allow(
5        clippy::expect_used,
6        clippy::indexing_slicing,
7        clippy::panic,
8        clippy::unwrap_used,
9        clippy::unreachable
10    )
11)]
12//! Rig's classic agent runtime.
13//!
14//! This crate owns the mature builder, run state machine, typed hook system,
15//! contextual tool registry, memory orchestration, extraction, and shared
16//! blocking/streaming driver. Portable provider, message, tool, and storage
17//! contracts remain in [`rig_core`] and are reachable here through the
18//! explicit [`core`] namespace; this crate's root deliberately exports only
19//! runtime-owned items. The comprehensive end-user facade is the root `rig`
20//! crate.
21//!
22//! # Target support
23//!
24//! Native targets are fully supported. `wasm32-unknown-unknown` (browser) is
25//! supported with no feature flags to set — the relaxed async bounds follow
26//! from the target alone.
27//!
28//! The `rmcp` feature is unavailable on wasm: rmcp's `ClientHandler` requires
29//! `Send + Sync` unconditionally, which this crate's wasm tool registry cannot
30//! satisfy, so asking for it there raises a targeted `compile_error!`. WASI
31//! (`wasm32-wasip1`/`wasip2`) is **not supported**: the dependency graph does
32//! not build for it. See the crate README for the full matrix and the
33//! reasoning.
34
35extern crate self as rig;
36
37/// Direct access to portable provider, data, memory, and tool contracts.
38///
39/// This explicit namespace is also the stable expansion root for portable
40/// `#[rig_tool]` functions in crates that depend on `rig-agent` without a
41/// separate direct `rig-core` dependency.
42///
43/// Portable `rig-core` root items are reachable here, but deliberately *not*
44/// at the `rig_agent` crate root — adding a root export to `rig-core` must not
45/// silently add one to `rig-agent`. A stable `rig-core` root export
46/// ([`rig_core::OneOrMany`]) demonstrates both halves of that invariant (the
47/// two doctests below enforce it):
48///
49/// ```
50/// // Reachable through the explicit `core` namespace.
51/// use rig_agent::core::OneOrMany;
52/// let _reachable: Option<OneOrMany<u8>> = None;
53/// ```
54///
55/// ```compile_fail
56/// // NOT reachable at the `rig_agent` crate root.
57/// use rig_agent::OneOrMany as _;
58/// ```
59pub mod core {
60    pub use rig_core::*;
61}
62
63pub mod agent;
64pub mod client;
65pub mod completion;
66pub mod extractor;
67pub mod integrations;
68// Shared JSON helpers live in rig-core; re-export so call sites stay
69// `json_utils::merge` / `json_utils::serialize_json_value`.
70pub(crate) use rig_core::json_utils;
71pub mod prelude;
72pub mod streaming;
73#[cfg(any(test, feature = "test-utils"))]
74#[cfg_attr(docsrs, doc(cfg(feature = "test-utils")))]
75pub mod test_utils;
76pub mod tool;
77
78pub use agent::{Agent, AgentBuilder, AgentRun, AgentRunner};
79pub use extractor::ExtractionResponse;
80
81#[cfg(feature = "derive")]
82#[cfg_attr(docsrs, doc(cfg(feature = "derive")))]
83pub use rig_derive::rig_tool;
84#[cfg(feature = "derive")]
85#[cfg_attr(docsrs, doc(cfg(feature = "derive")))]
86pub use rig_derive::rig_tool as tool_macro;