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//! memory orchestration, and typed extraction.
15//!
16//! Portable contracts are available through [`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//!
21//! ```
22//! use rig_agent::core::{DynModel, operation::Completion};
23//! use rig_agent::{Agent, AgentBuilder};
24//! fn assistant(model: impl Into<DynModel<Completion>>) -> Agent {
25//!     AgentBuilder::new(model).preamble("Be concise.").build()
26//! }
27//! ```
28
29extern crate self as rig;
30
31/// Portable provider, data, memory, and tool contracts, also used as the expansion
32/// root for portable `#[rig_tool]` functions. These exports are not forwarded to
33/// the `rig_agent` crate root.
34///
35/// ```
36/// use rig_agent::core::Embed;
37/// fn accepts_embeddings<T: Embed>() {}
38/// ```
39pub mod core {
40    pub use rig_core::*;
41}
42
43pub mod agent;
44pub mod bus;
45pub mod completion;
46pub mod extractor;
47/// Ready-made integrations: the CLI chatbot.
48pub mod integrations;
49pub(crate) use rig_core::json_utils;
50pub mod prelude;
51pub mod run;
52pub mod streaming;
53pub(crate) mod sync;
54#[cfg(any(test, feature = "test-utils"))]
55#[cfg_attr(docsrs, doc(cfg(feature = "test-utils")))]
56pub mod test_utils;
57pub mod tool;
58
59pub use agent::TypedPromptResponse;
60pub use agent::{
61    Agent, AgentBuilder, AgentHook, AgentRun, AgentRunner, HookContext, ModelHandle, ModelRef,
62    ModelSelection, ModelSelectionAction,
63};
64
65#[cfg(feature = "derive")]
66#[cfg_attr(docsrs, doc(cfg(feature = "derive")))]
67pub use rig_derive::rig_tool;
68
69// Compile-time thread-safety contract: the agent surface must be safe to hold
70// in shared host state (worker pools, ECS resources) on native targets.
71#[cfg(not(target_family = "wasm"))]
72const _: fn() = || {
73    fn assert_send_sync_static<T: Send + Sync + 'static>() {}
74    assert_send_sync_static::<Agent>();
75    assert_send_sync_static::<AgentRunner>();
76    assert_send_sync_static::<ModelHandle>();
77    assert_send_sync_static::<agent::MultiTurnStreamItem>();
78    assert_send_sync_static::<agent::RunEvents>();
79    assert_send_sync_static::<agent::PromptResponse>();
80    assert_send_sync_static::<tool::server::ToolServerHandle>();
81    assert_send_sync_static::<tool::ToolSet>();
82    assert_send_sync_static::<tool::ToolCatalog>();
83};