Skip to main content

ToolRegistry

Struct ToolRegistry 

Source
pub struct ToolRegistry { /* private fields */ }

Implementations§

Source§

impl ToolRegistry

Source

pub fn new(max_output_bytes: usize) -> Self

Source

pub fn with_deferral_policies(self, cfg: &ToolsConfig) -> Self

Take the deferral tools’ policies from the config. Separate from from_config_full because the policies are only used if something is deferred, which defer decides much later — once plugin tools have names.

Source

pub fn with_hooks(self, hooks: Hooks) -> Self

Attach plugin hooks to every tool call.

Source

pub fn hooks(&self) -> &Hooks

Source

pub fn max_output_bytes(&self) -> usize

The cap for what the model reads. Public because the runtime applies it after the loop hooks — redaction has to see whole tokens (#414).

Source

pub fn from_config(cfg: &ToolsConfig, workspace_root: PathBuf) -> Self

Registry with the built-in tools, gated by cfg and confined to workspace_root.

Source

pub fn from_config_with( cfg: &ToolsConfig, workspace_root: PathBuf, skill_roots: Vec<Root>, ) -> Self

As Self::from_config, and shell may also be given a cwd inside a skill’s directory, for the skills found under skill_roots.

Source

pub fn from_config_full( cfg: &ToolsConfig, workspace_root: PathBuf, skill_roots: Vec<Root>, scripts_dir: Option<PathBuf>, ) -> Self

As Self::from_config_with, and with a scripts directory: the script tool is registered over it. None — no config directory could be worked out — means no script tool, the same way there is no skill_manage without a directory to write.

Source

pub fn register(&mut self, tool: Arc<dyn Tool>, policy: Policy)

Register a built-in (or runtime-provided) tool.

Source

pub fn register_with_source( &mut self, tool: Arc<dyn Tool>, policy: Policy, source: ToolSource, )

Register a tool and say who added it. Plugins use this so that tools list can point at the directory to look at when something is wrong.

Source

pub fn disable(&mut self, names: &[String]) -> Vec<String>

Remove tools named in [tools] disabled, returning the names that matched nothing.

Called once after everything is registered — built-ins, plugin tools, the memory tool — because a plugin tool can only be found after plugins load. The unknown names come back instead of being ignored: a typo in this list is a tool the operator believes is off.

Source

pub fn defer(&mut self, patterns: &[String]) -> Vec<String>

Withhold tools from the request without removing them: they stay registered and runnable, and the three tools that reach them are registered here — but only if something was actually deferred, because a config that defers nothing should not spend prompt tokens on three tools with nothing to reach.

Called once, after everything is registered, for the same reason as Self::disable: a plugin’s name is only known once plugins have loaded. Returns the patterns that matched nothing, so a typo is reported rather than silently doing nothing.

Defer by name or by source (#351).

A pattern is matched against a tool’s name and against its source label — builtin, plugin:<name>, plugin:mcp:<server> — because that is the only way to say “every MCP tool” without renaming them. MCP tools keep the name the server published (the #373 rule), so mcp_* would match nothing; plugin:mcp:* is the spelling that says what it means, and it is the shipped default.

A source filter that matches nothing is not a typo: plugin:mcp:* on a box with no MCP server is a filter over an empty set, and warning on every run would train the reader to ignore the warning. Source labels are the patterns that carry a : (plugin:mcp:*, plugin:greeter); a plain name pattern that matches nothing — note_*, shellish — is still a mistake in the file and is still reported.

Source

pub fn descriptors(&self) -> Vec<ToolDescriptor>

Every registered tool, advertised or not, in name order.

Source

pub fn advertised_names(&self) -> Vec<String>

Names the model is offered, in name order.

Source

pub fn schema_document(&self) -> Value

One JSON Schema document describing every tool call this registry allows.

A call is {"name": …, "arguments": {…}}; oneOf gives one branch per advertised tool, pinning name with const and validating arguments against the tool’s parameters schema in $defs. $defs carries every registered tool’s schema, including ones this configuration does not offer, so an external client can validate a call it got hold of even after the policy changed.

Source

pub fn names(&self) -> Vec<String>

Source

pub fn only(&self, names: &[&str]) -> ToolRegistry

A copy of this registry holding only names, for an agent whose capabilities are declared rather than subtracted (#548).

The counterpart of without, and the direction that stays true: a denylist is correct only until something new is registered — a plugin tool, an MCP server’s tool, a tool added next release — and every one of those arrives granted. A flare is read-only, so what it holds is written down, and everything else is absent from its registry and therefore unreachable through a tool_call bridge.

Source

pub fn without(&self, names: &[&str]) -> ToolRegistry

A copy of this registry with names removed, for an agent that must not be able to reach them at all (#171).

Not disable: a disabled tool is still registered, still dispatchable by a tool_call that names it, and only withheld from the request. A flare is declared read-only, so the write tools are not in its registry — the bridge cannot reach what is not there, which is a claim a duplicated policy cannot make.

The rest is kept as it is, policies included: what a flare may read is decided by the parent’s own configuration, not by a second set of rules.

Source

pub fn specs(&self) -> Vec<ToolSpec>

Specs for every tool the model is offered, derived from Self::descriptors.

Source

pub async fn dispatch( &self, name: &str, raw_args: &str, approver: &dyn Approver, ) -> ToolOutcome

Run a tool call as produced by a model. Never panics or errors: every failure becomes an is_error outcome so it can be fed back to the model.

Plugin hooks see call_id: null here: this form is for a caller that is not the loop and has no model-issued call to name. The loop uses [dispatch_call].

Source

pub fn summary_of(&self, name: &str, raw_args: &str) -> String

The one-liner an approval prompt would show for this call, without asking anyone. Used by the loop when it records a call nobody answered: the row it writes has to read like the question a person would have been asked, months later in eclipse approve --list.

Source

pub async fn dispatch_call( &self, name: &str, raw_args: &str, approver: &dyn Approver, call_id: Option<&str>, ) -> ToolOutcome

dispatch, telling the plugin hooks which tool call this is. With [tools] concurrency above 1 several calls are in flight at once and their before_tool / after_tool payloads interleave, so the id is how a hook tells them apart — and how an after_tool rewrite is matched to the call it belongs to.

Source

pub async fn dispatch_scoped( &self, name: &str, raw_args: &str, approver: &dyn Approver, call_id: Option<&str>, run: &RunScope, ) -> ToolOutcome

dispatch_call for a call made by a run: run is that run’s scope, which a tool that starts children reads through Tool::call_scoped.

Trait Implementations§

Source§

impl Default for ToolRegistry

Source§

fn default() -> Self

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

Auto Trait Implementations§

§

impl !RefUnwindSafe for ToolRegistry

§

impl !UnwindSafe for ToolRegistry

§

impl Forget for ToolRegistry

§

impl Freeze for ToolRegistry
where *const LeafNode<String, Entry> is !null: Freeze, PhantomData<(Owned, LeafOrInternal)>: Freeze, PhantomData<Box<(String, Entry)>>: Freeze, *const u8 is !null: Freeze, PhantomData<Arc<Hook>>: Freeze, PhantomData<u8>: Freeze,

§

impl Move for ToolRegistry

§

impl Send for ToolRegistry
where NodeRef<Owned, String, Entry, LeafOrInternal>: Send, BoxRaw<(String, Entry)>: Send, RawVecInner: Send, Arc<Hook>: Send,

§

impl Sync for ToolRegistry
where NodeRef<Owned, String, Entry, LeafOrInternal>: Sync, BoxRaw<(String, Entry)>: Sync, RawVecInner: Sync, Arc<Hook>: Sync,

§

impl Unpin for ToolRegistry
where *const LeafNode<String, Entry> is !null: Unpin, Box<(String, Entry)>: Unpin, *const u8 is !null: Unpin, Arc<Hook>: Unpin,

§

impl UnsafeUnpin for ToolRegistry
where *const LeafNode<String, Entry> is !null: UnsafeUnpin, PhantomData<(Owned, LeafOrInternal)>: UnsafeUnpin, PhantomData<Box<(String, Entry)>>: UnsafeUnpin, *const u8 is !null: UnsafeUnpin, PhantomData<Arc<Hook>>: UnsafeUnpin, PhantomData<u8>: UnsafeUnpin,

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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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