Skip to main content

ToolRegistry

Struct ToolRegistry 

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

Composable tool registry - stores and queries tool definitions.

Unlike the CLI’s registry which auto-registers all tools, this registry is empty by default. Callers compose it by registering tools from whichever modules they need.

§Example

use brainwires_tools::{ToolRegistry, BashTool, FileOpsTool, GitTool};

let mut registry = ToolRegistry::new();
registry.register_tools(BashTool::get_tools());
registry.register_tools(FileOpsTool::get_tools());
registry.register_tools(GitTool::get_tools());

Implementations§

Source§

impl ToolRegistry

Source

pub const CORE_TOOL_NAMES: &'static [&'static str]

Core tool names used for basic project exploration. Exposed so callers can extend the default set with extras from config without forking the list. Keep alphabetised so the serialised tools array is a stable prefix — that is what makes the Anthropic prompt cache break points in brainwires_providers::anthropic actually land cache hits.

Source

pub fn new() -> Self

Create an empty registry

Source

pub fn with_builtins() -> Self

Create a registry pre-populated with all built-in tools

Source

pub fn register(&mut self, tool: Tool)

Register a single tool

Source

pub fn register_tools(&mut self, tools: Vec<Tool>)

Register multiple tools at once

Source

pub fn get_all(&self) -> &[Tool]

Get all registered tools

Source

pub fn get_all_with_extra(&self, extra: &[Tool]) -> Vec<Tool>

Get all tools including additional external tools (e.g., MCP tools)

Source

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

Look up a tool by name

Source

pub fn get_initial_tools(&self) -> Vec<&Tool>

Get tools that should be loaded initially (defer_loading = false)

Source

pub fn get_deferred_tools(&self) -> Vec<&Tool>

Get only deferred tools (defer_loading = true)

Source

pub fn search_tools(&self, query: &str) -> Vec<&Tool>

Search tools by query string matching name and description

Source

pub fn get_by_category(&self, category: ToolCategory) -> Vec<&Tool>

Get tools by category

Source

pub fn get_all_with_mcp(&self, mcp_tools: &[Tool]) -> Vec<Tool>

Get all tools including MCP tools

Source

pub fn get_core(&self) -> Vec<&Tool>

Get core tools for basic project exploration, returned in the canonical order defined by CORE_TOOL_NAMES so the resulting tools array is byte-stable across turns.

Source

pub fn get_core_with_extras(&self, extra_names: &[String]) -> Vec<&Tool>

Get core tools plus any extras named by extra_names (deduplicated, extras appended after core in the order given). Unknown names are silently skipped.

Source

pub fn get_primary(&self) -> Vec<&Tool>

Get primary meta-tools (always available)

Source

pub fn filtered_view(&self, allow: &[&str]) -> Vec<Tool>

Return a filtered view containing only the named tools.

Useful when constructing a provider call for a constrained agent role — the caller supplies the allow-list (e.g. from AgentRole::allowed_tools) and receives only the matching Tool definitions.

Tools not present in the registry are silently skipped, so the list may be shorter than allow if some tools are not registered.

Source

pub fn len(&self) -> usize

Total number of registered tools

Source

pub fn is_empty(&self) -> bool

Whether the registry is empty

Trait Implementations§

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

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. 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> Same for T

Source§

type Output = T

Should always be Self
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
Source§

impl<T> ErasedDestructor for T
where T: 'static,