Skip to main content

ToolRegistry

Struct ToolRegistry 

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

NOTE: Clone shares Arc state with all tools. Use fork() for isolation.

Implementations§

Source§

impl ToolRegistry

Source

pub async fn invoke(&self, name: &str, arguments: Value) -> Result<String>

Source

pub async fn invoke_with_audit( &self, name: &str, arguments: Value, ) -> ToolDispatch

Invoke a tool and return both its result and a populated AuditMeta. Callers that need to persist audit data should use this method; callers that don’t can call invoke which discards the audit half.

Source§

impl ToolRegistry

Source

pub fn new(transport: Arc<dyn ToolTransport>) -> Self

Source

pub fn local() -> Self

Create a registry with the default local transport.

Source

pub fn transport(&self) -> &Arc<dyn ToolTransport> ⓘ

Returns a reference to the transport layer.

Source

pub fn with_same_transport(&self) -> Self

Create a new empty registry that shares the same transport.

Source

pub fn fork(&self) -> Self

Create an isolated copy of this registry.

Unlike clone(), fork() calls tool.fork() on each registered tool so that tools with internal state (e.g. scratchpad, memory) get independent copies rather than shared Arc references.

Tools that do not implement fork() (stateless tools) are simply cloned as usual.

For now, this is equivalent to clone() — a full fork requires per-tool fork support. This method exists as a named extension point so call sites can opt in to isolation semantics explicitly.

Source

pub fn with_permission_hook(self, hook: Arc<dyn PermissionHook>) -> Self

Attach a PermissionHook (Goal 161). When set, ask_permission is called before every tool invocation; returning false causes invoke to return Error::PermissionDenied without running the tool.

Source

pub fn set_permission_hook(&mut self, hook: Arc<dyn PermissionHook>)

Attach a permission hook via mutable reference. Equivalent to [with_permission_hook] but usable on existing registries.

Source

pub fn clear_permission_hook(&mut self)

Remove any previously attached permission hook.

Source

pub fn with_policy(self, policy: PolicyConfig) -> Self

Attach an L1 policy config. The registry stores the policy so that individual tools (e.g. run_shell) can query it via registry.policy() at call time.

Source

pub fn set_policy(&mut self, policy: PolicyConfig)

Set the L1 policy config via mutable reference.

Source

pub fn policy(&self) -> Option<&PolicyConfig>

Return the attached policy config, if any.

Source

pub fn with_headless(self, headless: bool) -> Self

Enable headless mode (Goal 199): interactive tools go through external hooks instead of waiting for terminal input.

Source

pub fn set_headless(&mut self, headless: bool)

Set headless mode via mutable reference.

Source

pub fn with_hook_runner(self, hook_runner: ExternalHookRunner) -> Self

Attach an [ExternalHookRunner] for headless permission checks.

Source

pub fn set_hook_runner(&mut self, hook_runner: ExternalHookRunner)

Set the external hook runner via mutable reference.

Source

pub fn with_permissions(self, permissions: PermissionsConfig) -> Self

Set the permissions configuration for this registry.

Source

pub fn with_shared_permissions(self, sp: SharedPermissions) -> Self

Attach a SharedPermissions reference for runtime rule updates.

Unlike [with_permissions], this accepts an already-constructed Arc<RwLock<LayeredPermissionsConfig>> so that multiple components can share the same mutable config. Changes made via add_session_rule / remove_session_rule on the shared config are immediately visible through this registry.

Source

pub fn with_auto_classifier(self, classifier: AutoClassifier) -> Self

Attach an AutoClassifier for PermissionMode::Auto.

When the registry’s permission mode is Auto, each tool call is sent to the classifier before execution. The classifier is wrapped in Arc<Mutex<...>> so it can be shared across clones of the registry.

Source

pub fn permission_mode(&self) -> PermissionMode

Return the current permission mode.

Source

pub fn set_permission_mode(&mut self, mode: PermissionMode)

Update the permission mode at runtime (Claude set_permission_mode).

Writes through to the shared [LayeredPermissionsConfig] so invoke_with_audit sees the new mode. If no shared config is attached yet, one is created with the given mode and empty rule layers.

Source

pub fn shared_permissions(&self) -> Option<SharedPermissions>

Shared permissions handle for mid-run control updates, if any.

Source

pub fn permissions_config(&self) -> Option<PermissionsConfig>

Return a reference to the current permissions config, if any. Return a cloned snapshot of the current permissions config.

Uses try_read() — returns None if the lock is held for writing (which is rare and brief). Callers that need a guaranteed read should use [invoke_with_audit] which does an async .read().await.

Source

pub fn is_plan_mode(&self, tool_name: &str) -> bool

Check whether a tool requires plan mode according to the current permissions configuration.

Source

pub fn with_touched_files(self, slot: Arc<Mutex<TouchedFiles>>) -> Self

Attach a TouchedFiles collector. Tool invocations on structured filesystem tools will record their path arguments onto the shared collector. Used by AgentRuntime to assemble per-turn checkpoint metadata.

Source

pub fn clear_touched_files(&mut self)

Detach any previously attached collector.

Source

pub fn touched_files(&self) -> Option<Arc<Mutex<TouchedFiles>>>

Return the currently attached touched-files collector, if any.

Source

pub fn with_read_file_state(self, slot: Arc<Mutex<ReadFileState>>) -> Self

Attach shared ReadFileState so ReadFile records reads and EditTool can enforce the partial-read guard.

Source

pub fn read_file_state(&self) -> Option<Arc<Mutex<ReadFileState>>>

Return the currently attached read-file state, if any.

Source

pub fn with_session_roots(self, roots: SharedSandboxRoots) -> Self

Attach a shared sandbox-roots slot for mid-run expansion.

Source

pub fn session_roots(&self) -> Option<SharedSandboxRoots>

Return the shared sandbox-roots slot, if any.

Source

pub fn with_elicitation_slot(self, slot: SharedElicitationHandler) -> Self

Attach a shared MCP elicitation-handler slot.

Source

pub fn elicitation_slot(&self) -> Option<SharedElicitationHandler>

Return the shared elicitation-handler slot, if any.

Source

pub fn register(self, tool: Arc<dyn Tool>) -> Self

Source

pub fn register_with_aliases( self, tool: Arc<dyn Tool>, aliases: &[&str], ) -> Self

Register a tool and associate one or more aliases with it.

Aliases are not sent to the LLM — they are only used by [find_by_name] so sandboxed replacements can be looked up under the original name the model knows.

Source

pub fn register_mut(&mut self, tool: Arc<dyn Tool>)

Register a tool via mutable reference (for use with shared registries).

Source

pub fn register_mut_with_aliases( &mut self, tool: Arc<dyn Tool>, aliases: &[&str], )

Register a tool with aliases via mutable reference.

Source

pub fn find_by_name(&self, name: &str) -> Option<Arc<dyn Tool>>

Find a registered tool by its primary name or any alias.

This is the preferred lookup path. invoke delegates to this so that sandboxed tool replacements can be reached under the original name.

Source

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

Source

pub fn specs_partitioned(&self) -> (Vec<ToolSpec>, Vec<ToolSpec>)

Return (eager_specs, deferred_specs). Eager tools are sent to the LLM with full schemas. Deferred tools are not — their names appear in <available-deferred-tools> so the model can call ToolSearchTool.

Source

pub fn retain_tools(&mut self, allow: &[String])

Restrict the registry to only the named tools, removing all others. Tool names are matched case-insensitively. Aliases for removed tools are also dropped. Used by --allow-tools to give agents a limited tool set (e.g. read-only review agents).

Source

pub fn split_eager_deferred(&self) -> (Vec<SpecWithHint>, Vec<SpecWithHint>)

Split the registry’s tools into eager and deferred partitions.

Returns (eager, deferred) where each element is a (ToolSpec, optional_search_hint) pair. Eager tools carry their full schema; deferred tools carry only the name (the full schema is returned on demand when the model calls ToolSearch). The search hint is the first sentence of the tool’s description, suitable for injection into the deferred tool list so the model knows what is available without the full schema.

Source

pub fn is_deferred_spec(&self, spec: &ToolSpec) -> bool

Check whether a spec is deferred by looking up the tool in the registry.

Source

pub fn freeze_deferred_specs(&mut self)

Finalize deferred tool support: collect all deferred tool specs into a shared catalog and register a ToolSearchTool backed by that catalog.

Call this once after all other tools have been registered. If there are no deferred tools, this is a no-op (ToolSearchTool is not registered).

Source

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

Source

pub fn get(&self, name: &str) -> Option<Arc<dyn Tool>>

Source

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

Check if a tool is read-only (no side effects).

Source

pub fn build_kind_map(&self) -> HashMap<String, ToolKind>

Build a HashMap<String, ToolKind> mapping every registered tool name to its ACP ToolKind (Sprint 3). Used by AcpBridge to populate the kind field in tool_call notifications.

Source

pub fn is_readonly_for_call(&self, name: &str, args: &Value) -> bool

Like is_readonly but passes call-time arguments to the tool so it can make an argument-specific decision (e.g. sub_agent checking subagent_type: "explore").

Trait Implementations§

Source§

impl Clone for ToolRegistry

Source§

fn clone(&self) -> Self

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 Default for ToolRegistry

Source§

fn default() -> Self

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> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
Source§

impl<A, B, T> HttpServerConnExec<A, B> for T
where B: Body,

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> IntoMaybeUndefined<T> for T

Source§

fn into_maybe_undefined(self) -> MaybeUndefined<T>

Converts this value into a three-state builder argument.
Source§

impl<T> IntoOption<T> for T

Source§

fn into_option(self) -> Option<T>

Converts this value into an optional builder argument.
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 = !

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