Skip to main content

rig_agent/
lib.rs

1#![cfg_attr(docsrs, feature(doc_cfg))]
2#![deny(missing_docs)]
3#![cfg_attr(
4    test,
5    allow(
6        clippy::expect_used,
7        clippy::indexing_slicing,
8        clippy::panic,
9        clippy::unwrap_used,
10        clippy::unreachable
11    )
12)]
13//! Rig's classic agent runtime: builders, serializable run state, hooks, tools,
14//! and typed extraction.
15//!
16//! Portable contracts live in `rig_core`; recording accepts
17//! [`rig_core::serve::Recorder`], with concrete replay adapters in `rig-cassette`.
18//! Native and browser WASM targets are supported; WASI is not. MCP integration
19//! is provided by the native-only `rig-rmcp` crate.
20
21extern crate self as rig;
22
23#[doc(hidden)]
24pub use rig_core as __core;
25
26pub mod agent;
27pub mod completion;
28pub mod extractor;
29pub mod handlers;
30/// Ready-made integrations: the CLI chatbot.
31pub mod integrations;
32pub(crate) use rig_core::json_utils;
33
34/// Lock `mutex`, taking the guard even if a panicking holder poisoned it.
35pub(crate) fn lock<T>(mutex: &std::sync::Mutex<T>) -> std::sync::MutexGuard<'_, T> {
36    mutex
37        .lock()
38        .unwrap_or_else(std::sync::PoisonError::into_inner)
39}
40pub mod prelude;
41pub mod run;
42pub mod streaming;
43#[cfg(any(test, feature = "test-utils"))]
44#[cfg_attr(docsrs, doc(cfg(feature = "test-utils")))]
45pub mod test_utils;
46pub mod tool;
47
48pub use agent::TypedPromptResponse;
49pub use agent::{
50    Agent, AgentBuilder, AgentHook, AgentRun, AgentRunner, HookContext, ModelHandle, ModelRef,
51    ModelSelection, ModelSelectionAction,
52};
53
54#[cfg(feature = "derive")]
55#[cfg_attr(docsrs, doc(cfg(feature = "derive")))]
56pub use rig_derive::rig_tool;
57
58// Compile-time thread-safety contract: the agent surface must be safe to hold
59// in shared host state (worker pools, ECS resources) on native targets.
60#[cfg(not(target_family = "wasm"))]
61const _: fn() = || {
62    fn assert_send_sync_static<T: Send + Sync + 'static>() {}
63    assert_send_sync_static::<Agent>();
64    assert_send_sync_static::<AgentRunner>();
65    assert_send_sync_static::<ModelHandle>();
66    assert_send_sync_static::<agent::MultiTurnStreamItem>();
67    assert_send_sync_static::<agent::RunEvents>();
68    assert_send_sync_static::<agent::PromptResponse>();
69    assert_send_sync_static::<tool::server::ToolServerHandle>();
70    assert_send_sync_static::<tool::ToolSet>();
71    assert_send_sync_static::<tool::ToolCatalog>();
72};