Skip to main content

CapabilityResolver

Struct CapabilityResolver 

Source
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

Source

pub fn new() -> Self

Creates an empty resolver that allows nothing.

Source

pub fn from_lists<M, T>(models: M, tools: T) -> Self
where M: IntoIterator<Item = String>, T: IntoIterator<Item = String>,

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.

Source

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.

Source

pub fn allow_model(self, name: impl Into<String>) -> Self

Allows an additional model name. Returns self for chaining.

Source

pub fn allow_tool(self, name: impl Into<String>) -> Self

Allows an additional tool name. Returns self for chaining.

Source

pub fn allow_subgraph(self, name: impl Into<String>) -> Self

Allows an additional subgraph (graph blueprint) name. Returns self.

Source

pub fn allow_router(self, name: impl Into<String>) -> Self

Allows an additional router name. Returns self for chaining.

Source

pub fn allow_reducer(self, name: impl Into<String>) -> Self

Allows an additional reducer name. Returns self for chaining.

Source

pub fn allow_agent(self, name: impl Into<String>) -> Self

Allows an additional agent name (for subagent nodes). Returns self.

Source

pub fn allow_script(self, name: impl Into<String>) -> Self

Allows an additional REPL script name (for repl_agent nodes). Returns self.

Source

pub fn with_node_kinds<I, S>(self, kinds: I) -> Self
where I: IntoIterator<Item = S>, S: Into<String>,

Replaces the set of allowed node kinds. Passing a non-empty set enables node-kind validation in the strict binding path. Returns self.

Source

pub fn model_allowed(&self, name: &str) -> bool

Returns true if name is an allowed model.

Source

pub fn tool_allowed(&self, name: &str) -> bool

Returns true if name is an allowed tool.

Source

pub fn subgraph_allowed(&self, name: &str) -> bool

Returns true if name is an allowed subgraph (graph blueprint).

Source

pub fn router_allowed(&self, name: &str) -> bool

Returns true if name is an allowed router.

Source

pub fn reducer_allowed(&self, name: &str) -> bool

Returns true if name is an allowed reducer.

Source

pub fn agent_allowed(&self, name: &str) -> bool

Returns true if name is an allowed agent (for subagent nodes).

Source

pub fn script_allowed(&self, name: &str) -> bool

Returns true if name is an allowed REPL script (for repl_agent nodes).

Source

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.

Source

pub fn reference_allowed(&self, class: ReferenceClass, target: &str) -> bool

Returns true when target is allowed for the given reference class.

Source

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).

Source

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 kind is in the resolver’s node-kind allowlist (a TinyAgentsError::Compile error otherwise);
  • subgraph/graph node references resolve to a registered subgraph, router node references to a registered router, subagent node references to a registered agent, repl_agent node references to a registered script, and all other nodes’ model references to a registered model (via the shared classify_reference policy);
  • every channel reducer 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

Source§

fn clone(&self) -> CapabilityResolver

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CapabilityResolver

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for CapabilityResolver

Source§

fn default() -> CapabilityResolver

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more