ToolRegistry

Struct ToolRegistry 

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

A registry for managing a collection of tools.

ImplementationsΒ§

SourceΒ§

impl ToolRegistry

Source

pub fn new() -> Self

Creates a new ToolRegistry.

Source

pub fn register(&mut self, tool: Box<dyn Tool>)

Registers a tool with the registry.

Source

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

Gets a tool from the registry by name.

Source

pub async fn execute(&self, name: &str, args: Value) -> Result<ToolResult>

Executes a tool in the registry by name.

Source

pub fn get_definitions(&self) -> Vec<ToolDefinition>

Gets the definitions of all tools in the registry.

Source

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}
More examples
Hide additional examples
examples/react_agent.rs (line 37)
10async fn main() -> helios_engine::Result<()> {
11    println!("🧠 Helios Engine - ReAct Agent Example");
12    println!("======================================\n");
13
14    // Load configuration from `config.toml`.
15    let config = Config::from_file("config.toml")?;
16
17    // Create an agent with ReAct mode enabled.
18    // Notice the simple `.react()` call in the builder pattern!
19    let mut agent = Agent::builder("ReActAgent")
20        .config(config)
21        .system_prompt(
22            "You are a helpful assistant that thinks carefully before acting. \
23             Use your reasoning to plan your approach.",
24        )
25        .tools(vec![
26            Box::new(CalculatorTool),
27            Box::new(EchoTool),
28            Box::new(FileReadTool),
29        ])
30        .react() // Enable ReAct mode - that's all it takes!
31        .max_iterations(5)
32        .build()
33        .await?;
34
35    println!(
36        "Available tools: {:?}\n",
37        agent.tool_registry().list_tools()
38    );
39
40    println!("═══════════════════════════════════════════════════════════");
41    println!("Example 1: Mathematical Problem");
42    println!("═══════════════════════════════════════════════════════════\n");
43
44    // --- Test 1: Math problem requiring reasoning ---
45    println!("User: I need to calculate (25 * 4) + (100 / 5). Can you help?\n");
46    let response = agent
47        .chat("I need to calculate (25 * 4) + (100 / 5). Can you help?")
48        .await?;
49    println!("\nAgent: {}\n", response);
50
51    println!("═══════════════════════════════════════════════════════════");
52    println!("Example 2: Multi-step Task");
53    println!("═══════════════════════════════════════════════════════════\n");
54
55    // --- Test 2: Multi-step task ---
56    println!("User: First calculate 15 * 7, then echo the result back to me.\n");
57    let response = agent
58        .chat("First calculate 15 * 7, then echo the result back to me.")
59        .await?;
60    println!("\nAgent: {}\n", response);
61
62    println!("═══════════════════════════════════════════════════════════");
63    println!(" ReAct Demo Complete!");
64    println!("═══════════════════════════════════════════════════════════");
65    println!("\nNotice how the agent:");
66    println!("  1. πŸ’­ First reasons about the task");
67    println!("  2. πŸ“‹ Creates a plan");
68    println!("  3. ⚑ Then executes the actions\n");
69    println!("This leads to more thoughtful and systematic problem-solving!");
70
71    Ok(())
72}
examples/react_debugging.rs (line 41)
9async fn main() -> helios_engine::Result<()> {
10    println!("πŸ” Helios Engine - ReAct for Debugging");
11    println!("=======================================\n");
12
13    let config = Config::from_file("config.toml")?;
14
15    // Create a ReAct agent with verbose reasoning
16    let debug_prompt = r#"Debug this task step by step. For each step, explain:
17
181. CURRENT STATE: What information do I have?
192. NEXT ACTION: What should I do next?
203. REASONING: Why is this the right action?
214. EXPECTED RESULT: What should happen?
225. VALIDATION: How will I know if it worked?
23
24Be extremely detailed in your thinking."#;
25
26    let mut debug_agent = Agent::builder("DebugAgent")
27        .config(config)
28        .system_prompt("You are a debugging assistant who explains every decision.")
29        .tools(vec![
30            Box::new(CalculatorTool),
31            Box::new(JsonParserTool),
32            Box::new(FileReadTool),
33        ])
34        .react_with_prompt(debug_prompt)
35        .max_iterations(15) // Allow more iterations for complex debugging
36        .build()
37        .await?;
38
39    println!(
40        "Available tools: {:?}\n",
41        debug_agent.tool_registry().list_tools()
42    );
43
44    // Scenario 1: Tracing calculation steps
45    println!("═══════════════════════════════════════════════════════════");
46    println!("Scenario 1: Trace Complex Calculation");
47    println!("═══════════════════════════════════════════════════════════\n");
48
49    println!("Problem: Calculate the compound interest formula result");
50    println!("Formula: A = P(1 + r)^n where P=1000, r=0.05, n=3\n");
51
52    let response = debug_agent
53        .chat("Calculate compound interest: Principal=1000, rate=0.05, time=3 years. Use A = P * (1 + r)^n")
54        .await?;
55    println!("\nAgent: {}\n", response);
56
57    // Scenario 2: Understanding tool selection
58    println!("═══════════════════════════════════════════════════════════");
59    println!("Scenario 2: Tool Selection Reasoning");
60    println!("═══════════════════════════════════════════════════════════\n");
61
62    println!("Task: Parse JSON and extract a value, then perform calculation\n");
63
64    let response = debug_agent
65        .chat(r#"Parse this JSON: {"price": 25.50, "quantity": 4} and calculate the total cost"#)
66        .await?;
67    println!("\nAgent: {}\n", response);
68
69    // Scenario 3: Error recovery reasoning
70    println!("═══════════════════════════════════════════════════════════");
71    println!("Scenario 3: Multi-Step Problem Solving");
72    println!("═══════════════════════════════════════════════════════════\n");
73
74    println!("Task: Calculate average of a series of operations\n");
75
76    let response = debug_agent
77        .chat("Calculate: (10 * 5) + (20 * 3) + (15 * 2), then divide by 3 to get the average")
78        .await?;
79    println!("\nAgent: {}\n", response);
80
81    // Explanation
82    println!("═══════════════════════════════════════════════════════════");
83    println!("πŸ’‘ Debugging Benefits");
84    println!("═══════════════════════════════════════════════════════════\n");
85
86    println!("ReAct mode helps you:");
87    println!("  1. πŸ” See exactly what the agent is thinking");
88    println!("  2. 🎯 Understand why it chose specific tools");
89    println!("  3. πŸ“‹ Follow the step-by-step execution plan");
90    println!("  4. πŸ› Identify where reasoning might go wrong");
91    println!("  5. πŸ”§ Optimize prompts based on visible thinking\n");
92
93    println!("Tips for debugging with ReAct:");
94    println!("  β€’ Use detailed custom prompts for more verbose reasoning");
95    println!("  β€’ Increase max_iterations for complex tasks");
96    println!("  β€’ Watch the 'πŸ’­ ReAct Reasoning' output carefully");
97    println!("  β€’ Compare reasoning across different queries");
98    println!("  β€’ Adjust system prompts based on reasoning patterns\n");
99
100    Ok(())
101}
examples/react_comparison.rs (line 34)
9async fn main() -> helios_engine::Result<()> {
10    println!("πŸ”¬ Helios Engine - ReAct Comparison Demo");
11    println!("=========================================\n");
12
13    let config1 = Config::from_file("config.toml")?;
14    let config2 = Config::from_file("config.toml")?;
15
16    // Create two identical agents, one with ReAct and one without
17    let mut standard_agent = Agent::builder("StandardAgent")
18        .config(config1)
19        .system_prompt("You are a helpful assistant with access to tools.")
20        .tools(vec![Box::new(CalculatorTool), Box::new(EchoTool)])
21        .build()
22        .await?;
23
24    let mut react_agent = Agent::builder("ReActAgent")
25        .config(config2)
26        .system_prompt("You are a helpful assistant with access to tools.")
27        .tools(vec![Box::new(CalculatorTool), Box::new(EchoTool)])
28        .react() // The only difference!
29        .build()
30        .await?;
31
32    println!(
33        "Tools available: {:?}\n",
34        standard_agent.tool_registry().list_tools()
35    );
36
37    // Test Case 1: Simple calculation
38    println!("═══════════════════════════════════════════════════════════");
39    println!("Test Case 1: Simple Mathematical Calculation");
40    println!("═══════════════════════════════════════════════════════════\n");
41
42    let query1 = "What is 25 * 8?";
43    println!("Query: {}\n", query1);
44
45    println!("--- STANDARD AGENT ---");
46    let response1 = standard_agent.chat(query1).await?;
47    println!("Response: {}\n", response1);
48
49    println!("--- REACT AGENT ---");
50    let response2 = react_agent.chat(query1).await?;
51    println!("Response: {}\n", response2);
52
53    // Test Case 2: Multi-step problem
54    println!("═══════════════════════════════════════════════════════════");
55    println!("Test Case 2: Multi-Step Problem");
56    println!("═══════════════════════════════════════════════════════════\n");
57
58    let query2 = "Calculate (15 + 25) * 3, then echo the result";
59    println!("Query: {}\n", query2);
60
61    println!("--- STANDARD AGENT ---");
62    let response3 = standard_agent.chat(query2).await?;
63    println!("Response: {}\n", response3);
64
65    println!("--- REACT AGENT ---");
66    let response4 = react_agent.chat(query2).await?;
67    println!("Response: {}\n", response4);
68
69    // Test Case 3: Complex multi-tool task
70    println!("═══════════════════════════════════════════════════════════");
71    println!("Test Case 3: Complex Multi-Tool Task");
72    println!("═══════════════════════════════════════════════════════════\n");
73
74    let query3 =
75        "First calculate 100 / 4, then multiply that by 3, and finally echo the final answer";
76    println!("Query: {}\n", query3);
77
78    println!("--- STANDARD AGENT ---");
79    let response5 = standard_agent.chat(query3).await?;
80    println!("Response: {}\n", response5);
81
82    println!("--- REACT AGENT ---");
83    let response6 = react_agent.chat(query3).await?;
84    println!("Response: {}\n", response6);
85
86    // Summary
87    println!("═══════════════════════════════════════════════════════════");
88    println!("πŸ“Š Comparison Summary");
89    println!("═══════════════════════════════════════════════════════════\n");
90
91    println!("STANDARD AGENT:");
92    println!("  βœ“ Faster execution (no reasoning overhead)");
93    println!("  βœ“ Direct tool usage");
94    println!("  βœ— No visible thought process");
95    println!("  βœ— May miss planning opportunities\n");
96
97    println!("REACT AGENT:");
98    println!("  βœ“ Shows reasoning process (πŸ’­ ReAct Reasoning)");
99    println!("  βœ“ Systematic approach to problems");
100    println!("  βœ“ Better for complex tasks");
101    println!("  βœ— Slightly slower (extra LLM call)\n");
102
103    println!("WHEN TO USE:");
104    println!("  β†’ Standard: Simple, direct tasks where speed matters");
105    println!("  β†’ ReAct: Complex tasks, debugging, when you want transparency\n");
106
107    Ok(())
108}

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> 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, 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