pub struct ToolRegistry { /* private fields */ }Expand description
A registry for managing a collection of tools.
Implementations§
Source§impl ToolRegistry
impl ToolRegistry
Sourcepub async fn execute(&self, name: &str, args: Value) -> Result<ToolResult>
pub async fn execute(&self, name: &str, args: Value) -> Result<ToolResult>
Executes a tool in the registry by name.
Sourcepub fn get_definitions(&self) -> Vec<ToolDefinition>
pub fn get_definitions(&self) -> Vec<ToolDefinition>
Gets the definitions of all tools in the registry.
Sourcepub fn list_tools(&self) -> Vec<String>
pub fn list_tools(&self) -> Vec<String>
Lists the names of all tools in the registry.
Examples found in repository?
examples/agent_with_tools.rs (line 25)
9async fn main() -> helios_engine::Result<()> {
10 // Load configuration from `config.toml`.
11 let config = Config::from_file("config.toml")?;
12
13 // Create an agent named "ToolAgent" and equip it with the `CalculatorTool` and `EchoTool`.
14 // Using the improved syntax to add multiple tools at once!
15 let mut agent = Agent::builder("ToolAgent")
16 .config(config)
17 .system_prompt("You are a helpful assistant with access to tools. Use them when needed.")
18 .tools(vec![Box::new(CalculatorTool), Box::new(EchoTool)])
19 .max_iterations(5)
20 .build()
21 .await?;
22
23 println!(
24 "Available tools: {:?}\n",
25 agent.tool_registry().list_tools()
26 );
27
28 // --- Test the calculator tool ---
29 let response = agent.chat("What is 25 * 4 + 10?").await?;
30 println!("Agent: {}\n", response);
31
32 // --- Test the echo tool ---
33 let response = agent
34 .chat("Can you echo this message: 'Hello from Helios!'")
35 .await?;
36 println!("Agent: {}\n", response);
37
38 Ok(())
39}Trait Implementations§
Auto Trait Implementations§
impl Freeze for ToolRegistry
impl !RefUnwindSafe for ToolRegistry
impl Send for ToolRegistry
impl Sync for ToolRegistry
impl Unpin 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