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