pub struct ToolRegistry { /* private fields */ }Expand description
Registry for external tools.
ToolRegistry stores registered tools and provides methods for invoking them with proper process lifecycle management.
§Example
ⓘ
use forge_agent::workflow::tools::{Tool, ToolRegistry, ToolInvocation};
let mut registry = ToolRegistry::new();
// Register magellan
let magellan = Tool::new("magellan", "/usr/bin/magellan")
.default_args(vec!["--db".to_string(), ".forge/graph.db".to_string()])
.description("Graph-based code indexer");
registry.register(magellan)?;
// Check registration
assert!(registry.is_registered("magellan"));
// List all tools
let tools = registry.list_tools();
assert!(tools.contains(&"magellan"));Implementations§
Source§impl ToolRegistry
impl ToolRegistry
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new empty ToolRegistry.
§Example
use forge_agent::workflow::tools::ToolRegistry;
let registry = ToolRegistry::new();
assert_eq!(registry.len(), 0);Sourcepub fn register(&mut self, tool: Tool) -> Result<(), ToolError>
pub fn register(&mut self, tool: Tool) -> Result<(), ToolError>
Registers a tool in the registry.
§Arguments
tool- Tool to register
§Returns
Ok(())if registration succeededErr(ToolError::AlreadyRegistered)if tool with same name exists
§Example
use forge_agent::workflow::tools::{Tool, ToolRegistry};
let mut registry = ToolRegistry::new();
let tool = Tool::new("magellan", "/usr/bin/magellan");
registry.register(tool)?;Sourcepub fn get(&self, name: &str) -> Option<&Tool>
pub fn get(&self, name: &str) -> Option<&Tool>
Gets a tool by name.
§Arguments
name- Tool name to look up
§Returns
Some(&Tool)if tool existsNoneif tool not found
§Example
use forge_agent::workflow::tools::{Tool, ToolRegistry};
let mut registry = ToolRegistry::new();
registry.register(Tool::new("magellan", "/usr/bin/magellan")).unwrap();
let tool = registry.get("magellan");
assert!(tool.is_some());
assert_eq!(tool.unwrap().name, "magellan");Sourcepub async fn invoke(
&self,
invocation: &ToolInvocation,
) -> Result<ToolInvocationResult, ToolError>
pub async fn invoke( &self, invocation: &ToolInvocation, ) -> Result<ToolInvocationResult, ToolError>
Invokes a tool with the given invocation parameters.
§Arguments
invocation- Tool invocation request
§Returns
Ok(ToolInvocationResult)with result and optional process guardErr(ToolError)if tool not found or execution fails
§Example
ⓘ
use forge_agent::workflow::tools::{ToolRegistry, ToolInvocation, Tool};
let mut registry = ToolRegistry::new();
registry.register(Tool::new("echo", "/bin/echo")).unwrap();
let invocation = ToolInvocation::new("echo")
.args(vec!["hello".to_string(), "world".to_string()]);
let result = registry.invoke(&invocation).await?;
assert!(result.result.success);Sourcepub fn list_tools(&self) -> Vec<&str>
pub fn list_tools(&self) -> Vec<&str>
Lists all registered tool names.
§Returns
Vector of tool names
§Example
use forge_agent::workflow::tools::{Tool, ToolRegistry};
let mut registry = ToolRegistry::new();
registry.register(Tool::new("magellan", "/usr/bin/magellan")).unwrap();
registry.register(Tool::new("cargo", "/usr/bin/cargo")).unwrap();
let tools = registry.list_tools();
assert_eq!(tools.len(), 2);Sourcepub fn is_registered(&self, name: &str) -> bool
pub fn is_registered(&self, name: &str) -> bool
Checks if a tool is registered.
§Arguments
name- Tool name to check
§Returns
trueif tool is registeredfalseif tool is not registered
§Example
use forge_agent::workflow::tools::{Tool, ToolRegistry};
let mut registry = ToolRegistry::new();
registry.register(Tool::new("magellan", "/usr/bin/magellan")).unwrap();
assert!(registry.is_registered("magellan"));
assert!(!registry.is_registered("cargo"));Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of registered tools.
§Example
use forge_agent::workflow::tools::{Tool, ToolRegistry};
let mut registry = ToolRegistry::new();
assert_eq!(registry.len(), 0);
registry.register(Tool::new("magellan", "/usr/bin/magellan")).unwrap();
assert_eq!(registry.len(), 1);Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true if the registry is empty.
§Example
use forge_agent::workflow::tools::ToolRegistry;
let registry = ToolRegistry::new();
assert!(registry.is_empty());Sourcepub fn with_standard_tools() -> Self
pub fn with_standard_tools() -> Self
Creates a ToolRegistry with standard tools pre-registered.
This method attempts to discover and register commonly-used tools:
- magellan (graph-based code indexer)
- cargo (Rust package manager)
- splice (precision code editor)
Tools that are not found are logged but don’t cause failure (graceful degradation).
§Returns
A ToolRegistry with discovered tools registered
§Example
use forge_agent::workflow::tools::ToolRegistry;
let registry = ToolRegistry::with_standard_tools();
// registry may have magellan, cargo, splice if they were foundTrait Implementations§
Source§impl Clone for ToolRegistry
impl Clone for ToolRegistry
Source§fn clone(&self) -> ToolRegistry
fn clone(&self) -> ToolRegistry
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for ToolRegistry
impl RefUnwindSafe for ToolRegistry
impl Send for ToolRegistry
impl Sync for ToolRegistry
impl Unpin for ToolRegistry
impl UnsafeUnpin for ToolRegistry
impl UnwindSafe for ToolRegistry
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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