Skip to main content

rig_compose/
lib.rs

1//! # rig-compose
2//!
3//! Composable agent kernel for [`rig`](https://github.com/0xplaygrounds/rig)
4//! (and any rig-shaped tool surface): stateless skills, transport-agnostic
5//! tools, registry-driven agents, and a signal-routing coordinator.
6//!
7//! Originally extracted from [Azrael](https://github.com/ForeverAngry/azrael)'s
8//! threat-detection kernel, this crate is now domain-neutral and can wrap
9//! any tool/agent stack.
10//!
11//! ## Composability rules
12//! 1. [`Skill`] is stateless. Any skill can be assigned to any [`Agent`].
13//! 2. [`Tool`] is the only side-effectful interface. Local impls and
14//!    remote transports (see `rig-mcp`) share the trait; skills cannot
15//!    tell them apart.
16//! 3. [`Agent`] holds a slice of the global registries — it never
17//!    hard-codes skill or tool names.
18//! 4. [`Workflow`] composes agents.
19//!
20//! ## Two paths for agent-to-agent delegation
21//!
22//! rig-compose ships **two complementary delegation primitives**. Pick
23//! the one that matches who should decide *when* a peer agent is invoked.
24//!
25//! **Default — [`delegate::DelegateTool`] (model-driven, agentic).**
26//! A child agent is exposed as a normal [`Tool`]. The parent agent's
27//! model decides when to call it, just like any other tool. This is the
28//! recommended path for autonomous agent-to-agent collaboration, because
29//! the topology stays open and transport-symmetric: the same tool call
30//! works whether the peer runs in-process via
31//! [`delegate::InProcessAgentDelegate`] or behind an MCP server via
32//! `rig_mcp::McpTool`.
33//!
34//! **Optional — [`coordinator::CoordinatorAgent`] (deterministic, host-driven).**
35//! A signal-tag router that hops to the first matching specialist with
36//! no model in the loop. Reach for it only when the routing topology is
37//! fixed up-front and you specifically want a free dispatch hop —
38//! typical use is an overseer that fans one specialist out per partition
39//! before any LLM has loaded. Not a substitute for `DelegateTool` when
40//! you want the *agents* to choose how they cooperate.
41
42pub mod agent;
43pub mod budget;
44pub mod context;
45/// Deterministic, no-LLM signal-tag router. See the crate-level
46/// "Two paths for agent-to-agent delegation" section: prefer
47/// [`delegate::DelegateTool`] for model-driven peer collaboration and
48/// reach for [`coordinator::CoordinatorAgent`] only when the topology
49/// is fixed and a free dispatch hop matters.
50pub mod coordinator;
51/// Model-driven, transport-agnostic agent delegation. The default path
52/// for autonomous agent-to-agent collaboration. See the crate-level
53/// "Two paths for agent-to-agent delegation" section.
54pub mod delegate;
55pub mod instructions;
56#[cfg(feature = "manifest")]
57pub mod manifest;
58pub mod registry;
59pub mod skill;
60pub mod tool;
61pub mod workflow;
62
63pub use agent::{Agent, AgentId, AgentStepResult, GenericAgent, GenericAgentBuilder};
64pub use budget::{
65    AtomicBudget, AtomicTokenBudget, BudgetError, BudgetGuard, TokenBudget, TokenRefund,
66    TokenReservation,
67};
68pub use context::{Evidence, InvestigationContext, NextAction, Signal};
69pub use coordinator::{CoordinatorAgent, CoordinatorBuilder, RoutingRule};
70pub use delegate::{
71    DelegateExecutor, DelegateName, DelegateRegistry, DelegateTool, InProcessAgentDelegate,
72};
73pub use instructions::Instructions;
74#[cfg(feature = "manifest")]
75pub use manifest::{
76    AgentManifest, DelegateKind, DelegateSpec, InstructionsSpec, KnowledgeSpec, ManifestError,
77    McpServerSpec, ModelSpec, ToolSpec, delegate_stub, materialize_local_and_delegate_tools,
78    materialize_local_and_delegate_tools_with_delegates,
79};
80pub use registry::{KernelError, SkillRegistry, ToolRegistry};
81pub use skill::{Skill, SkillId, SkillOutcome};
82pub use tool::{LocalTool, Tool, ToolName, ToolSchema};
83pub use workflow::Workflow;