Skip to main content

ToolRegistry

Struct ToolRegistry 

Source
pub struct ToolRegistry {
    pub headless: bool,
    pub hook_runner: ExternalHookRunner,
    pub auto_classifier: Option<Arc<Mutex<AutoClassifier>>>,
    /* private fields */
}

Fields§

§headless: bool

Goal-199: headless mode — interactive tools go through external hooks instead of waiting for terminal input.

§hook_runner: ExternalHookRunner

Goal-199: external hook runner for headless permission checks.

§auto_classifier: Option<Arc<Mutex<AutoClassifier>>>

Goal-200: optional auto classifier for PermissionMode::Auto. When Some, each tool call in Auto mode is classified by the LLM before execution. Wrapped in a Mutex (tokio) because classify() takes &mut self (it updates the denial tracker).

Implementations§

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

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.

Trait Implementations§

Source§

impl Clone for ToolRegistry

Source§

fn clone(&self) -> ToolRegistry

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

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: 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: 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> 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