pub struct CapabilityResolver { /* private fields */ }Expand description
An allowlist of capability names referenced by the expressive language.
The expressive language can only reference capabilities by name; it can
never define them. bind_capabilities uses a resolver to ensure that
every referenced model and tool was already registered and allowed by Rust,
which is what makes agent-authored source safe to compile.
A resolver holds five name allowlists — models, tools, subgraphs (graph
blueprints), routers, and reducers — plus an optional set of allowed node
kind values. The minimal new / from_lists
constructors populate only models and tools and leave node_kinds empty, so
the legacy bind_capabilities gate keeps its original behaviour (model and
tool checks only). The richer checks — subgraph, router, and reducer
references plus node-kind validation — are opt-in through the
registry-backed path: from_registry and
bind_capabilities_with_registry.
Implementations§
Source§impl CapabilityResolver
impl CapabilityResolver
Sourcepub fn from_lists<M, T>(models: M, tools: T) -> Self
pub fn from_lists<M, T>(models: M, tools: T) -> Self
Builds a resolver from iterators of allowed model and tool names.
Subgraph, router, and reducer allowlists are left empty and node-kind
validation is disabled; use from_registry for a
fully populated, registry-backed resolver.
Sourcepub fn from_registry<State: Send + Sync>(
registry: &CapabilityRegistry<State>,
) -> Self
pub fn from_registry<State: Send + Sync>( registry: &CapabilityRegistry<State>, ) -> Self
Builds a fully populated resolver from a live CapabilityRegistry.
Every registered model, tool, graph blueprint, router, and reducer name
— including their aliases — is added to the corresponding allowlist, and
the node-kind allowlist is seeded with DEFAULT_NODE_KINDS. The
resulting resolver therefore validates .rag source against exactly what
Rust has registered, including subgraph/router/reducer references and
node kinds, when used with CapabilityResolver::bind_blueprint or
bind_capabilities_with_registry.
Sourcepub fn allow_model(self, name: impl Into<String>) -> Self
pub fn allow_model(self, name: impl Into<String>) -> Self
Allows an additional model name. Returns self for chaining.
Sourcepub fn allow_tool(self, name: impl Into<String>) -> Self
pub fn allow_tool(self, name: impl Into<String>) -> Self
Allows an additional tool name. Returns self for chaining.
Sourcepub fn allow_subgraph(self, name: impl Into<String>) -> Self
pub fn allow_subgraph(self, name: impl Into<String>) -> Self
Allows an additional subgraph (graph blueprint) name. Returns self.
Sourcepub fn allow_router(self, name: impl Into<String>) -> Self
pub fn allow_router(self, name: impl Into<String>) -> Self
Allows an additional router name. Returns self for chaining.
Sourcepub fn allow_reducer(self, name: impl Into<String>) -> Self
pub fn allow_reducer(self, name: impl Into<String>) -> Self
Allows an additional reducer name. Returns self for chaining.
Sourcepub fn allow_agent(self, name: impl Into<String>) -> Self
pub fn allow_agent(self, name: impl Into<String>) -> Self
Allows an additional agent name (for subagent nodes). Returns self.
Sourcepub fn allow_script(self, name: impl Into<String>) -> Self
pub fn allow_script(self, name: impl Into<String>) -> Self
Allows an additional REPL script name (for repl_agent nodes). Returns
self.
Sourcepub fn with_node_kinds<I, S>(self, kinds: I) -> Self
pub fn with_node_kinds<I, S>(self, kinds: I) -> Self
Replaces the set of allowed node kinds. Passing a non-empty set enables
node-kind validation in the strict binding path. Returns self.
Sourcepub fn model_allowed(&self, name: &str) -> bool
pub fn model_allowed(&self, name: &str) -> bool
Returns true if name is an allowed model.
Sourcepub fn tool_allowed(&self, name: &str) -> bool
pub fn tool_allowed(&self, name: &str) -> bool
Returns true if name is an allowed tool.
Sourcepub fn subgraph_allowed(&self, name: &str) -> bool
pub fn subgraph_allowed(&self, name: &str) -> bool
Returns true if name is an allowed subgraph (graph blueprint).
Sourcepub fn router_allowed(&self, name: &str) -> bool
pub fn router_allowed(&self, name: &str) -> bool
Returns true if name is an allowed router.
Sourcepub fn reducer_allowed(&self, name: &str) -> bool
pub fn reducer_allowed(&self, name: &str) -> bool
Returns true if name is an allowed reducer.
Sourcepub fn agent_allowed(&self, name: &str) -> bool
pub fn agent_allowed(&self, name: &str) -> bool
Returns true if name is an allowed agent (for subagent nodes).
Sourcepub fn script_allowed(&self, name: &str) -> bool
pub fn script_allowed(&self, name: &str) -> bool
Returns true if name is an allowed REPL script (for repl_agent
nodes).
Sourcepub fn classify_reference<'a>(
kind: &str,
model: Option<&'a str>,
subgraph: Option<&'a str>,
agent: Option<&'a str>,
script: Option<&'a str>,
) -> Option<PrimaryReference<'a>>
pub fn classify_reference<'a>( kind: &str, model: Option<&'a str>, subgraph: Option<&'a str>, agent: Option<&'a str>, script: Option<&'a str>, ) -> Option<PrimaryReference<'a>>
The single kind-to-reference policy every binding gate shares.
Given a node kind and the reference fields it carries, returns the
primary reference that must resolve and the allowlist class it resolves
against — or None when the node declares no primary reference. The
subgraph argument is the caller’s already-resolved subgraph target
(the dedicated graph field falling back to the legacy model field).
Centralising this mapping is what keeps
bind_blueprint and both
crate::language::resolver::Resolver paths from drifting: a new node
kind or a changed reference convention is edited here once.
Sourcepub fn reference_allowed(&self, class: ReferenceClass, target: &str) -> bool
pub fn reference_allowed(&self, class: ReferenceClass, target: &str) -> bool
Returns true when target is allowed for the given reference class.
Sourcepub fn node_kind_allowed(&self, kind: &str) -> bool
pub fn node_kind_allowed(&self, kind: &str) -> bool
Returns true if kind is an allowed node kind, or if node-kind
validation is disabled (the allowlist is empty).
Sourcepub fn bind_blueprint(&self, blueprint: &Blueprint) -> Result<()>
pub fn bind_blueprint(&self, blueprint: &Blueprint) -> Result<()>
Runs the full, strict capability binding for blueprint.
In addition to the model/tool checks performed by bind_capabilities,
this validates, per the conventions documented on DEFAULT_NODE_KINDS:
- each node
kindis in the resolver’s node-kind allowlist (aTinyAgentsError::Compileerror otherwise); subgraph/graphnode references resolve to a registered subgraph,routernode references to a registered router,subagentnode references to a registered agent,repl_agentnode references to a registered script, and all other nodes’modelreferences to a registered model (via the sharedclassify_referencepolicy);- every
channelreducer reference is registered.
§Errors
Returns TinyAgentsError::Compile for an unknown node kind, and
TinyAgentsError::Capability for the first unregistered model, tool,
subgraph, router, agent, script, or reducer reference.
Trait Implementations§
Source§impl Clone for CapabilityResolver
impl Clone for CapabilityResolver
Source§fn clone(&self) -> CapabilityResolver
fn clone(&self) -> CapabilityResolver
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more