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}More 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Β§
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