Agent

Struct Agent 

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

Represents an LLM-powered agent that can chat, use tools, and manage a conversation.

Implementations§

Source§

impl Agent

Source

pub fn builder(name: impl Into<String>) -> AgentBuilder

Returns a new AgentBuilder for constructing an agent.

§Arguments
  • name - The name of the agent.
Examples found in repository?
examples/custom_tool.rs (line 79)
74async fn main() -> helios_engine::Result<()> {
75    // Load configuration from `config.toml`.
76    let config = Config::from_file("config.toml")?;
77
78    // Create an agent named "WeatherAgent" and equip it with the `WeatherTool`.
79    let mut agent = Agent::builder("WeatherAgent")
80        .config(config)
81        .system_prompt("You are a helpful weather assistant. Use the weather tool to answer questions about weather.")
82        .tool(Box::new(WeatherTool))
83        .build()
84        .await?;
85
86    // --- Ask the agent about the weather ---
87    let response = agent.chat("What's the weather like in New York?").await?;
88    println!("Agent: {}\n", response);
89
90    // --- Ask again, but with a different unit ---
91    let response = agent.chat("How about in London, but in celsius?").await?;
92    println!("Agent: {}\n", response);
93
94    Ok(())
95}
More examples
Hide additional examples
examples/agent_with_tools.rs (line 15)
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}
examples/serve_agent.rs (line 19)
9async fn main() -> helios_engine::Result<()> {
10    // Initialize tracing
11    tracing_subscriber::fmt()
12        .with_max_level(tracing::Level::INFO)
13        .init();
14
15    // Load configuration
16    let config = Config::from_file("config.toml")?;
17
18    // Create an agent with tools
19    let agent = Agent::builder("API Agent")
20        .config(config)
21        .system_prompt("You are a helpful AI assistant with access to a calculator tool.")
22        .tool(Box::new(CalculatorTool))
23        .max_iterations(5)
24        .build()
25        .await?;
26
27    // Start the server
28    println!("Starting server on http://127.0.0.1:8000");
29    println!("Try: curl http://127.0.0.1:8000/v1/chat/completions \\");
30    println!("  -H 'Content-Type: application/json' \\");
31    println!("  -d '{{\"model\": \"local-model\", \"messages\": [{{\"role\": \"user\", \"content\": \"What is 15 * 7?\"}}]}}'");
32
33    helios_engine::serve::start_server_with_agent(
34        agent,
35        "local-model".to_string(),
36        "127.0.0.1:8000",
37    )
38    .await?;
39
40    Ok(())
41}
examples/basic_chat.rs (line 23)
14async fn main() -> helios_engine::Result<()> {
15    println!("🚀 Helios Engine - Basic Chat Example");
16    println!("=====================================");
17    println!("💡 Streaming is enabled by default - watch tokens appear in real-time!\n");
18
19    // Load configuration from `config.toml`.
20    let config = Config::from_file("config.toml")?;
21
22    // Create a simple agent named "BasicAgent".
23    let mut agent = Agent::builder("BasicAgent")
24        .config(config)
25        .system_prompt("You are a helpful assistant.")
26        .build()
27        .await?;
28
29    // --- Send a message to the agent ---
30    println!("User: Hello! How are you?");
31    print!("Agent (streaming): ");
32    io::stdout().flush()?;
33
34    let _response = agent.chat("Hello! How are you?").await?;
35    println!();
36
37    // --- Continue the conversation ---
38    println!("\nUser: What can you help me with?");
39    print!("Agent (streaming): ");
40    io::stdout().flush()?;
41
42    let _response = agent.chat("What can you help me with?").await?;
43    println!();
44
45    println!("\n Demo completed! Notice how responses streamed in real-time.");
46
47    Ok(())
48}
examples/multiple_agents.rs (line 17)
10async fn main() -> helios_engine::Result<()> {
11    // Load configuration from `config.toml`.
12    let config = Config::from_file("config.toml")?;
13
14    // --- Create multiple agents with different personalities and tools ---
15
16    // An agent specialized in math, equipped with a calculator tool.
17    let mut math_agent = Agent::builder("MathAgent")
18        .config(config.clone())
19        .system_prompt("You are a math expert. You love numbers and equations.")
20        .tool(Box::new(CalculatorTool))
21        .build()
22        .await?;
23
24    // A creative agent for writing and storytelling.
25    let mut creative_agent = Agent::builder("CreativeAgent")
26        .config(config)
27        .system_prompt("You are a creative writer who loves storytelling and poetry.")
28        .build()
29        .await?;
30
31    // --- Interact with the Math Agent ---
32    println!("=== Math Agent ===");
33    let response = math_agent.chat("What is the square root of 144?").await?;
34    println!("Math Agent: {}\n", response);
35
36    // --- Interact with the Creative Agent ---
37    println!("=== Creative Agent ===");
38    let response = creative_agent
39        .chat("Write a haiku about programming.")
40        .await?;
41    println!("Creative Agent: {}\n", response);
42
43    Ok(())
44}
examples/rag_qdrant_comparison.rs (line 32)
19async fn demonstrate_in_memory() -> helios_engine::Result<()> {
20    println!("=== IN-MEMORY RAG DEMONSTRATION ===\n");
21
22    let api_key = std::env::var("OPENAI_API_KEY").unwrap_or_else(|_| {
23        println!("⚠ Warning: OPENAI_API_KEY not set. Using placeholder.");
24        "your-api-key-here".to_string()
25    });
26
27    let config = Config::from_file("config.toml").unwrap_or_else(|_| Config::new_default());
28
29    // Create in-memory RAG tool
30    let rag_tool = RAGTool::new_in_memory("https://api.openai.com/v1/embeddings", &api_key);
31
32    let mut agent = Agent::builder("InMemoryAgent")
33        .config(config)
34        .system_prompt("You are a helpful assistant with in-memory RAG capabilities.")
35        .tool(Box::new(rag_tool))
36        .max_iterations(8)
37        .build()
38        .await?;
39
40    println!("✓ In-memory agent created\n");
41
42    // Add some documents
43    println!("Adding documents...");
44    agent.chat("Store: The capital of France is Paris.").await?;
45    agent
46        .chat("Store: The capital of Germany is Berlin.")
47        .await?;
48    agent.chat("Store: The capital of Italy is Rome.").await?;
49    println!("✓ Documents added\n");
50
51    // Search
52    println!("Searching...");
53    let response = agent.chat("What is the capital of Germany?").await?;
54    println!("Agent: {}\n", response);
55
56    println!("Advantages of in-memory:");
57    println!("  ✓ No external dependencies");
58    println!("  ✓ Fast and simple");
59    println!("  ✓ Perfect for development");
60    println!("  ✗ No persistence (data lost on restart)");
61    println!("  ✗ Limited scalability\n");
62
63    Ok(())
64}
65
66async fn demonstrate_qdrant() -> helios_engine::Result<()> {
67    println!("=== QDRANT RAG DEMONSTRATION ===\n");
68
69    let api_key = std::env::var("OPENAI_API_KEY").unwrap_or_else(|_| {
70        println!("⚠ Warning: OPENAI_API_KEY not set. Using placeholder.");
71        "your-api-key-here".to_string()
72    });
73
74    let config = Config::from_file("config.toml").unwrap_or_else(|_| Config::new_default());
75
76    // Create Qdrant RAG tool
77    let rag_tool = RAGTool::new_qdrant(
78        "http://localhost:6333",
79        "comparison_demo",
80        "https://api.openai.com/v1/embeddings",
81        &api_key,
82    );
83
84    let mut agent = Agent::builder("QdrantAgent")
85        .config(config)
86        .system_prompt("You are a helpful assistant with Qdrant RAG capabilities.")
87        .tool(Box::new(rag_tool))
88        .max_iterations(8)
89        .build()
90        .await?;
91
92    println!("✓ Qdrant agent created\n");
93
94    // Clear any existing data
95    println!("Clearing existing data...");
96    agent.chat("Clear all documents").await?;
97    println!("✓ Cleared\n");
98
99    // Add some documents
100    println!("Adding documents...");
101    agent
102        .chat("Store: The Eiffel Tower is located in Paris, France.")
103        .await?;
104    agent
105        .chat("Store: The Colosseum is located in Rome, Italy.")
106        .await?;
107    agent
108        .chat("Store: The Brandenburg Gate is located in Berlin, Germany.")
109        .await?;
110    println!("✓ Documents added\n");
111
112    // Search
113    println!("Searching...");
114    let response = agent.chat("What famous landmark is in Berlin?").await?;
115    println!("Agent: {}\n", response);
116
117    println!("Advantages of Qdrant:");
118    println!("  ✓ Persistent storage");
119    println!("  ✓ Highly scalable");
120    println!("  ✓ Production-ready");
121    println!("  ✓ Advanced features (filtering, etc.)");
122    println!("  ✗ Requires external service");
123    println!("  ✗ More complex setup\n");
124
125    Ok(())
126}
Source

pub async fn quick(name: impl Into<String>) -> Result<Self>

Creates a quick-start agent with minimal configuration.

This is the simplest way to create an agent - just provide a name and it uses the default configuration (reads from config.toml if available, otherwise uses defaults).

§Arguments
  • name - The name of the agent.
§Example
let mut agent = Agent::quick("MyAgent").await?;
let response = agent.chat("Hello!").await?;
println!("{}", response);
Examples found in repository?
examples/quickstart.rs (line 13)
9async fn main() -> helios_engine::Result<()> {
10    println!("⚡ Helios Quick Start\n");
11
12    // Step 1: Create an agent in ONE LINE (using auto config)
13    let mut agent = Agent::quick("MyAgent").await?;
14    println!("✓ Agent created");
15
16    // Step 2: Ask a question
17    let response = agent.ask("What's the capital of France?").await?;
18    println!("Q: What's the capital of France?");
19    println!("A: {}\n", response);
20
21    // Step 3: Ask another question (agent remembers context!)
22    let response2 = agent.ask("What's its population?").await?;
23    println!("Q: What's its population?");
24    println!("A: {}\n", response2);
25
26    // That's it! You're using Helios! 🎉
27    println!("✅ Done! Create an agent and chat - that simple!");
28
29    Ok(())
30}
More examples
Hide additional examples
examples/ultra_simple.rs (line 61)
9async fn main() -> helios_engine::Result<()> {
10    println!("🚀 Ultra Simple Helios Example\n");
11
12    // ========== SIMPLEST AGENT CREATION ==========
13    println!("1️⃣  Creating an agent - shortest possible syntax:\n");
14
15    // One-liner: Create agent with auto config
16    let mut agent = Agent::builder("Helper")
17        .auto_config()
18        .prompt("You are helpful and concise.")
19        .build()
20        .await?;
21
22    println!("✓ Agent created!\n");
23
24    // ========== SIMPLEST CHAT ==========
25    println!("2️⃣  Asking questions - simplest possible:\n");
26
27    // Use .ask() instead of .chat() for more natural syntax
28    let answer = agent.ask("What is 2+2?").await?;
29    println!("Q: What is 2+2?\nA: {}\n", answer);
30
31    // ========== SIMPLEST CONFIG ==========
32    println!("3️⃣  Creating config with shortest syntax:\n");
33
34    // Ultra-short config creation
35    let _config = Config::builder()
36        .m("gpt-4") // .m() is shorthand for .model()
37        .key("your-api-key") // .key() is shorthand for .api_key()
38        .temp(0.8) // .temp() is shorthand for .temperature()
39        .tokens(1024) // .tokens() is shorthand for .max_tokens()
40        .build();
41
42    println!("✓ Config created with ultra-short syntax!\n");
43
44    // ========== SIMPLEST AGENT WITH TOOLS ==========
45    println!("4️⃣  Agent with tools - simplest way:\n");
46
47    let mut calc_agent = Agent::builder("Calculator")
48        .auto_config()
49        .prompt("You are a math expert.")
50        .with_tool(Box::new(CalculatorTool)) // Add single tool
51        .build()
52        .await?;
53
54    let result = calc_agent.ask("Calculate 15 * 7 + 5").await?;
55    println!("Q: Calculate 15 * 7 + 5\nA: {}\n", result);
56
57    // ========== SIMPLEST QUICK AGENT ==========
58    println!("5️⃣  Quick agent - one method call:\n");
59
60    // Agent::quick() creates agent in ONE LINE with auto config!
61    let mut quick_agent = Agent::quick("QuickBot").await?;
62    let quick_answer = quick_agent.ask("Say hello!").await?;
63    println!("Response: {}\n", quick_answer);
64
65    // ========== SIMPLEST CHAT MESSAGES ==========
66    println!("6️⃣  Creating messages - super short syntax:\n");
67
68    use helios_engine::ChatMessage;
69
70    // Short aliases for message creation
71    let _sys_msg = ChatMessage::sys("You are helpful"); // .sys() not .system()
72    let _user_msg = ChatMessage::msg("Hello there"); // .msg() not .user()
73    let _reply_msg = ChatMessage::reply("Hi! How can I help?"); // .reply() not .assistant()
74
75    println!("✓ Messages created with ultra-short syntax!\n");
76
77    // ========== SHORTEST AUTOFOREST ==========
78    println!("7️⃣  AutoForest - simplest multi-agent orchestration:\n");
79
80    use helios_engine::AutoForest;
81
82    let mut forest = AutoForest::new(Config::builder().m("gpt-4").build())
83        .with_tools(vec![Box::new(CalculatorTool)])
84        .build()
85        .await?;
86
87    // Use .run() for shortest syntax
88    let forest_result = forest.run("Analyze these numbers: 10, 20, 30, 40").await?;
89    println!("Forest Result:\n{}\n", forest_result);
90
91    // ========== COMPARISON TABLE ==========
92    println!("📊 Syntax Comparison - Short vs Long:\n");
93    println!("┌─────────────────────┬──────────────────────┬─────────────────┐");
94    println!("│ Operation           │ Short Syntax         │ Long Syntax      │");
95    println!("├─────────────────────┼──────────────────────┼─────────────────┤");
96    println!("│ Create Agent        │ Agent::quick()       │ Agent::builder()│");
97    println!("│ Ask Question        │ .ask()               │ .chat()          │");
98    println!("│ System Prompt       │ .prompt()            │ .system_prompt() │");
99    println!("│ Config Model        │ .m()                 │ .model()         │");
100    println!("│ Config Key          │ .key()               │ .api_key()       │");
101    println!("│ Config Temp         │ .temp()              │ .temperature()   │");
102    println!("│ Config Tokens       │ .tokens()            │ .max_tokens()    │");
103    println!("│ System Message      │ ChatMessage::sys()   │ ChatMessage::system()");
104    println!("│ User Message        │ ChatMessage::msg()   │ ChatMessage::user()");
105    println!("│ Assistant Message   │ ChatMessage::reply() │ ChatMessage::assistant()");
106    println!("│ AutoForest Execute  │ .run()               │ .execute_task()  │");
107    println!("└─────────────────────┴──────────────────────┴─────────────────┘\n");
108
109    println!("✅ All examples completed!");
110    println!("💡 Tip: Mix and match short and long syntax based on your preference!");
111
112    Ok(())
113}
Source

pub fn name(&self) -> &str

Returns the name of the agent.

Source

pub fn set_system_prompt(&mut self, prompt: impl Into<String>)

Sets the system prompt for the agent.

§Arguments
  • prompt - The system prompt to set.
Source

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

Registers a tool with the agent.

§Arguments
  • tool - The tool to register.
Source

pub fn tool_registry(&self) -> &ToolRegistry

Returns a reference to the agent’s tool 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}
Source

pub fn tool_registry_mut(&mut self) -> &mut ToolRegistry

Returns a mutable reference to the agent’s tool registry.

Source

pub fn chat_session(&self) -> &ChatSession

Returns a reference to the agent’s chat session.

Examples found in repository?
examples/send_message_tool_demo.rs (line 145)
19async fn main() -> helios_engine::Result<()> {
20    println!("📨 Helios Engine - SendMessageTool Demo");
21    println!("=======================================\n");
22
23    // Load configuration
24    let config = Config::from_file("config.toml")?;
25    println!("✓ Loaded configuration from config.toml");
26
27    // Create a simple forest with two agents
28    let mut forest = ForestBuilder::new()
29        .config(config)
30        .agent(
31            "alice".to_string(),
32            Agent::builder("alice")
33                .system_prompt("You are Alice, a helpful communication assistant."),
34        )
35        .agent(
36            "bob".to_string(),
37            Agent::builder("bob")
38                .system_prompt("You are Bob, a friendly colleague who responds to messages."),
39        )
40        .max_iterations(3)
41        .build()
42        .await?;
43
44    println!("✓ Created Forest with 2 agents: Alice and Bob");
45    println!();
46
47    // Demonstrate SendMessageTool direct messaging
48    println!("📤 Testing SendMessageTool - Direct Message:");
49    println!("---------------------------------------------");
50
51    // Create the tool for Alice
52    let message_queue = Arc::new(RwLock::new(Vec::new()));
53    let shared_context = Arc::new(RwLock::new(helios_engine::SharedContext::new()));
54
55    let send_tool = SendMessageTool::new(
56        "alice".to_string(),
57        Arc::clone(&message_queue),
58        Arc::clone(&shared_context),
59    );
60
61    // Test 1: Send a direct message from Alice to Bob
62    println!("1. Alice sends a direct message to Bob...");
63
64    let direct_message_args = serde_json::json!({
65        "to": "bob",
66        "message": "Hi Bob! How are you doing today?"
67    });
68
69    let result = send_tool.execute(direct_message_args).await?;
70    println!("   Tool result: {}", result.output);
71    println!("   Success: {}", result.success);
72
73    // Check the message queue
74    {
75        let queue = message_queue.read().await;
76        println!("   Messages in queue: {}", queue.len());
77        if let Some(msg) = queue.first() {
78            println!("   Message details:");
79            println!("     From: {}", msg.from);
80            println!("     To: {:?}", msg.to);
81            println!("     Content: {}", msg.content);
82        }
83    }
84
85    // Check shared context
86    {
87        let context = shared_context.read().await;
88        let messages = context.get_recent_messages(10);
89        println!("   Messages in shared context: {}", messages.len());
90    }
91
92    println!();
93
94    // Test 2: Send a broadcast message
95    println!("2. Alice broadcasts a message to everyone...");
96
97    let broadcast_message_args = serde_json::json!({
98        "message": "Hello everyone! This is a broadcast message from Alice."
99    });
100
101    let result2 = send_tool.execute(broadcast_message_args).await?;
102    println!("   Tool result: {}", result2.output);
103    println!("   Success: {}", result2.success);
104
105    // Check the message queue after broadcast
106    {
107        let queue = message_queue.read().await;
108        println!("   Messages in queue: {}", queue.len());
109        if let Some(msg) = queue.last() {
110            println!("   Latest message details:");
111            println!("     From: {}", msg.from);
112            println!("     To: {:?}", msg.to);
113            println!("     Content: {}", msg.content);
114        }
115    }
116
117    println!();
118
119    // Demonstrate integration with Forest messaging system
120    println!("🌲 Testing Forest Integration:");
121    println!("------------------------------");
122
123    // Clear our test queues and use the forest's messaging system
124    {
125        let mut queue = message_queue.write().await;
126        queue.clear();
127    }
128
129    println!("3. Using Forest's messaging system...");
130
131    // Send message through the forest
132    forest
133        .send_message(
134            &"alice".to_string(),
135            Some(&"bob".to_string()),
136            "Hello Bob via Forest messaging!".to_string(),
137        )
138        .await?;
139
140    // Process messages
141    forest.process_messages().await?;
142
143    // Check if Bob received the message
144    if let Some(bob) = forest.get_agent(&"bob".to_string()) {
145        let messages = bob.chat_session().messages.clone();
146        println!("   Bob's message count: {}", messages.len());
147        if let Some(last_msg) = messages.last() {
148            println!("   Bob received: {}", last_msg.content);
149        }
150    }
151
152    println!();
153
154    // Test broadcast through forest
155    println!("4. Forest broadcast message...");
156
157    forest
158        .send_message(
159            &"alice".to_string(),
160            None, // Broadcast
161            "Forest broadcast: Meeting at 3 PM!".to_string(),
162        )
163        .await?;
164
165    forest.process_messages().await?;
166
167    // Check all agents received the broadcast
168    for agent_id in ["alice", "bob"] {
169        if let Some(agent) = forest.get_agent(&agent_id.to_string()) {
170            let messages = agent.chat_session().messages.clone();
171            if let Some(last_msg) = messages.last() {
172                if last_msg.content.contains("broadcast") || last_msg.content.contains("Meeting") {
173                    println!("   {} received broadcast: {}", agent_id, last_msg.content);
174                }
175            }
176        }
177    }
178
179    println!();
180    println!(" SendMessageTool demo completed successfully!");
181    println!();
182    println!("Key features tested:");
183    println!("  • Direct messaging between agents");
184    println!("  • Broadcast messaging to all agents");
185    println!("  • Message queue management");
186    println!("  • Shared context integration");
187    println!("  • Forest messaging system integration");
188
189    Ok(())
190}
More examples
Hide additional examples
examples/forest_of_agents.rs (line 181)
19async fn main() -> helios_engine::Result<()> {
20    println!("🚀 Helios Engine - Forest of Agents Demo (with Real-Time Streaming)");
21    println!("====================================================================\n");
22    println!("💡 Note: All agent responses stream in real-time, token by token!\n");
23
24    // Load configuration
25    let config = Config::from_file("config.toml")?;
26
27    // Create a Forest of Agents with specialized agents
28    // Using the improved syntax to add multiple agents at once!
29    let mut forest = ForestBuilder::new()
30        .config(config)
31        .agents(vec![
32            // Coordinator agent - manages the team and delegates tasks
33            (
34                "coordinator".to_string(),
35                Agent::builder("coordinator")
36                    .system_prompt(
37                        "You are a project coordinator. For simple tasks that you can handle yourself, \
38                        complete them directly and provide a complete response. For complex tasks that \
39                        require specialized expertise, you can delegate using the 'delegate_task' tool \
40                        to agents like 'researcher', 'writer', 'editor', and 'qa'.\n\n\
41                        When you delegate a task, WAIT for the response and then synthesize the results. \
42                        Always provide a final, complete answer to the user's request."
43                    )
44                    .max_iterations(10)
45            ),
46            // Research agent - gathers and analyzes information
47            (
48                "researcher".to_string(),
49                Agent::builder("researcher")
50                    .system_prompt(
51                        "You are a research specialist who excels at gathering information, \
52                        analyzing data, and providing insights. You work closely with the coordinator \
53                        and writer to ensure all work is based on accurate information. Use \
54                        communication tools to share your findings and request clarification when needed."
55                    )
56                    .max_iterations(10)
57            ),
58            // Writer agent - creates content and documentation
59            (
60                "writer".to_string(),
61                Agent::builder("writer")
62                    .system_prompt(
63                        "You are a skilled writer who creates clear, well-structured content and \
64                        documentation. When you receive a task, complete it fully and provide the \
65                        final written content. You can use communication tools to request information \
66                        from the researcher if needed."
67                    )
68                    .max_iterations(10)
69            ),
70            // Editor agent - reviews and improves content
71            (
72                "editor".to_string(),
73                Agent::builder("editor")
74                    .system_prompt(
75                        "You are an editor who reviews content for quality, clarity, and consistency. \
76                        When you receive content to review, provide constructive feedback and an \
77                        improved version."
78                    )
79                    .max_iterations(10)
80            ),
81            // Quality Assurance agent - validates the final output
82            (
83                "qa".to_string(),
84                Agent::builder("qa")
85                    .system_prompt(
86                        "You are a quality assurance specialist who validates that all requirements \
87                        are met and the output is accurate and complete. When you receive content to \
88                        review, verify it meets all requirements and provide your assessment."
89                    )
90                    .max_iterations(10)
91            ),
92        ])
93        .max_iterations(15)
94        .build()
95        .await?;
96
97    println!(" Created Forest of Agents with 5 specialized agents:");
98    println!("  • 🎯 Coordinator: Manages projects and delegates tasks");
99    println!("  • 🔬 Researcher: Gathers and analyzes information");
100    println!("  • ✍️  Writer: Creates content and documentation");
101    println!("  • 📝 Editor: Reviews and improves content quality");
102    println!("  •  QA: Validates requirements and final output");
103    println!();
104
105    // Demonstrate collaborative task execution with streaming
106    println!("🎯 TASK: Create a brief guide on sustainable gardening");
107    println!("{}", "=".repeat(70));
108    println!();
109
110    println!("🎬 Starting collaborative task execution...");
111    println!("   (Watch the responses stream in real-time!)\n");
112
113    // Simpler task for demonstration - DISABLED TOOLS FOR TESTING
114    let task = "Create a brief guide (2-3 paragraphs) on sustainable gardening. \
115                Include key benefits and one practical technique.";
116
117    println!("📋 Task Description:");
118    println!("   {}\n", task);
119
120    println!("{}", "─".repeat(70));
121    println!("🤖 COORDINATOR (streaming response):");
122    print!("   ");
123    io::stdout().flush()?;
124
125    let _result = forest
126        .execute_collaborative_task(
127            &"coordinator".to_string(),
128            task.to_string(),
129            vec![
130                "researcher".to_string(),
131                "writer".to_string(),
132                "editor".to_string(),
133                "qa".to_string(),
134            ],
135        )
136        .await?;
137
138    println!();
139    println!("{}", "─".repeat(70));
140    println!();
141    println!("✨ Collaborative task completed!");
142    println!();
143
144    // Demonstrate direct agent communication with streaming
145    println!("💬 Testing direct agent-to-agent communication with streaming:");
146    println!("{}", "─".repeat(70));
147    println!();
148
149    let mut forest_clone = forest;
150
151    // Test a simple chat to show streaming
152    println!("📤 Sending task to Writer agent...");
153    println!("🤖 WRITER (streaming response):");
154    print!("   ");
155    io::stdout().flush()?;
156
157    if let Some(writer) = forest_clone.get_agent_mut(&"writer".to_string()) {
158        let _response = writer
159            .chat("Write one short paragraph about composting.")
160            .await?;
161        println!();
162    }
163
164    println!();
165    println!("{}", "─".repeat(70));
166    println!();
167
168    // Send a direct message between agents
169    println!("📤 Coordinator → Researcher: Direct message");
170    forest_clone
171        .send_message(
172            &"coordinator".to_string(),
173            Some(&"researcher".to_string()),
174            "Great job on the research! The information was very helpful.".to_string(),
175        )
176        .await?;
177
178    forest_clone.process_messages().await?;
179
180    if let Some(researcher) = forest_clone.get_agent(&"researcher".to_string()) {
181        let messages = researcher.chat_session().messages.clone();
182        if let Some(last_msg) = messages.last() {
183            println!("📥 Researcher received: \"{}\"", last_msg.content);
184        }
185    }
186    println!();
187
188    // Demonstrate shared context
189    println!("🧠 Shared Context Demo:");
190    println!("{}", "─".repeat(70));
191    forest_clone
192        .set_shared_context(
193            "project_status".to_string(),
194            serde_json::json!({
195                "name": "Sustainable Gardening Guide",
196                "status": "completed",
197                "contributors": ["coordinator", "researcher", "writer"],
198                "completion_date": "2025-11-03"
199            }),
200        )
201        .await;
202
203    let context = forest_clone.get_shared_context().await;
204    if let Some(status) = context.get("project_status") {
205        println!("📊 Shared project status:");
206        println!("{}", serde_json::to_string_pretty(&status).unwrap());
207    }
208    println!();
209
210    println!("{}", "=".repeat(70));
211    println!(" Forest of Agents Demo Completed Successfully!");
212    println!("{}", "=".repeat(70));
213    println!();
214    println!("🎉 Key Features Demonstrated:");
215    println!("  ✓ Real-time streaming responses from all agents");
216    println!("  ✓ Multi-agent collaboration on tasks");
217    println!("  ✓ Inter-agent communication (direct messages)");
218    println!("  ✓ Task delegation and coordination");
219    println!("  ✓ Shared context and memory");
220    println!("  ✓ Specialized agent roles working together");
221    println!();
222    println!("💡 Notice how all responses streamed token-by-token in real-time!");
223    println!("   This provides immediate feedback and better user experience.");
224
225    Ok(())
226}
Source

pub fn chat_session_mut(&mut self) -> &mut ChatSession

Returns a mutable reference to the agent’s chat session.

Source

pub fn clear_history(&mut self)

Clears the agent’s chat history.

Source

pub async fn send_message( &mut self, message: impl Into<String>, ) -> Result<String>

Sends a message to the agent and gets a response.

§Arguments
  • message - The message to send.
§Returns

A Result containing the agent’s response.

Source

pub async fn chat(&mut self, message: impl Into<String>) -> Result<String>

A convenience method for sending a message to the agent.

Examples found in repository?
examples/custom_tool.rs (line 87)
74async fn main() -> helios_engine::Result<()> {
75    // Load configuration from `config.toml`.
76    let config = Config::from_file("config.toml")?;
77
78    // Create an agent named "WeatherAgent" and equip it with the `WeatherTool`.
79    let mut agent = Agent::builder("WeatherAgent")
80        .config(config)
81        .system_prompt("You are a helpful weather assistant. Use the weather tool to answer questions about weather.")
82        .tool(Box::new(WeatherTool))
83        .build()
84        .await?;
85
86    // --- Ask the agent about the weather ---
87    let response = agent.chat("What's the weather like in New York?").await?;
88    println!("Agent: {}\n", response);
89
90    // --- Ask again, but with a different unit ---
91    let response = agent.chat("How about in London, but in celsius?").await?;
92    println!("Agent: {}\n", response);
93
94    Ok(())
95}
More examples
Hide additional examples
examples/agent_with_tools.rs (line 29)
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}
examples/basic_chat.rs (line 34)
14async fn main() -> helios_engine::Result<()> {
15    println!("🚀 Helios Engine - Basic Chat Example");
16    println!("=====================================");
17    println!("💡 Streaming is enabled by default - watch tokens appear in real-time!\n");
18
19    // Load configuration from `config.toml`.
20    let config = Config::from_file("config.toml")?;
21
22    // Create a simple agent named "BasicAgent".
23    let mut agent = Agent::builder("BasicAgent")
24        .config(config)
25        .system_prompt("You are a helpful assistant.")
26        .build()
27        .await?;
28
29    // --- Send a message to the agent ---
30    println!("User: Hello! How are you?");
31    print!("Agent (streaming): ");
32    io::stdout().flush()?;
33
34    let _response = agent.chat("Hello! How are you?").await?;
35    println!();
36
37    // --- Continue the conversation ---
38    println!("\nUser: What can you help me with?");
39    print!("Agent (streaming): ");
40    io::stdout().flush()?;
41
42    let _response = agent.chat("What can you help me with?").await?;
43    println!();
44
45    println!("\n Demo completed! Notice how responses streamed in real-time.");
46
47    Ok(())
48}
examples/multiple_agents.rs (line 33)
10async fn main() -> helios_engine::Result<()> {
11    // Load configuration from `config.toml`.
12    let config = Config::from_file("config.toml")?;
13
14    // --- Create multiple agents with different personalities and tools ---
15
16    // An agent specialized in math, equipped with a calculator tool.
17    let mut math_agent = Agent::builder("MathAgent")
18        .config(config.clone())
19        .system_prompt("You are a math expert. You love numbers and equations.")
20        .tool(Box::new(CalculatorTool))
21        .build()
22        .await?;
23
24    // A creative agent for writing and storytelling.
25    let mut creative_agent = Agent::builder("CreativeAgent")
26        .config(config)
27        .system_prompt("You are a creative writer who loves storytelling and poetry.")
28        .build()
29        .await?;
30
31    // --- Interact with the Math Agent ---
32    println!("=== Math Agent ===");
33    let response = math_agent.chat("What is the square root of 144?").await?;
34    println!("Math Agent: {}\n", response);
35
36    // --- Interact with the Creative Agent ---
37    println!("=== Creative Agent ===");
38    let response = creative_agent
39        .chat("Write a haiku about programming.")
40        .await?;
41    println!("Creative Agent: {}\n", response);
42
43    Ok(())
44}
examples/rag_qdrant_comparison.rs (line 44)
19async fn demonstrate_in_memory() -> helios_engine::Result<()> {
20    println!("=== IN-MEMORY RAG DEMONSTRATION ===\n");
21
22    let api_key = std::env::var("OPENAI_API_KEY").unwrap_or_else(|_| {
23        println!("⚠ Warning: OPENAI_API_KEY not set. Using placeholder.");
24        "your-api-key-here".to_string()
25    });
26
27    let config = Config::from_file("config.toml").unwrap_or_else(|_| Config::new_default());
28
29    // Create in-memory RAG tool
30    let rag_tool = RAGTool::new_in_memory("https://api.openai.com/v1/embeddings", &api_key);
31
32    let mut agent = Agent::builder("InMemoryAgent")
33        .config(config)
34        .system_prompt("You are a helpful assistant with in-memory RAG capabilities.")
35        .tool(Box::new(rag_tool))
36        .max_iterations(8)
37        .build()
38        .await?;
39
40    println!("✓ In-memory agent created\n");
41
42    // Add some documents
43    println!("Adding documents...");
44    agent.chat("Store: The capital of France is Paris.").await?;
45    agent
46        .chat("Store: The capital of Germany is Berlin.")
47        .await?;
48    agent.chat("Store: The capital of Italy is Rome.").await?;
49    println!("✓ Documents added\n");
50
51    // Search
52    println!("Searching...");
53    let response = agent.chat("What is the capital of Germany?").await?;
54    println!("Agent: {}\n", response);
55
56    println!("Advantages of in-memory:");
57    println!("  ✓ No external dependencies");
58    println!("  ✓ Fast and simple");
59    println!("  ✓ Perfect for development");
60    println!("  ✗ No persistence (data lost on restart)");
61    println!("  ✗ Limited scalability\n");
62
63    Ok(())
64}
65
66async fn demonstrate_qdrant() -> helios_engine::Result<()> {
67    println!("=== QDRANT RAG DEMONSTRATION ===\n");
68
69    let api_key = std::env::var("OPENAI_API_KEY").unwrap_or_else(|_| {
70        println!("⚠ Warning: OPENAI_API_KEY not set. Using placeholder.");
71        "your-api-key-here".to_string()
72    });
73
74    let config = Config::from_file("config.toml").unwrap_or_else(|_| Config::new_default());
75
76    // Create Qdrant RAG tool
77    let rag_tool = RAGTool::new_qdrant(
78        "http://localhost:6333",
79        "comparison_demo",
80        "https://api.openai.com/v1/embeddings",
81        &api_key,
82    );
83
84    let mut agent = Agent::builder("QdrantAgent")
85        .config(config)
86        .system_prompt("You are a helpful assistant with Qdrant RAG capabilities.")
87        .tool(Box::new(rag_tool))
88        .max_iterations(8)
89        .build()
90        .await?;
91
92    println!("✓ Qdrant agent created\n");
93
94    // Clear any existing data
95    println!("Clearing existing data...");
96    agent.chat("Clear all documents").await?;
97    println!("✓ Cleared\n");
98
99    // Add some documents
100    println!("Adding documents...");
101    agent
102        .chat("Store: The Eiffel Tower is located in Paris, France.")
103        .await?;
104    agent
105        .chat("Store: The Colosseum is located in Rome, Italy.")
106        .await?;
107    agent
108        .chat("Store: The Brandenburg Gate is located in Berlin, Germany.")
109        .await?;
110    println!("✓ Documents added\n");
111
112    // Search
113    println!("Searching...");
114    let response = agent.chat("What famous landmark is in Berlin?").await?;
115    println!("Agent: {}\n", response);
116
117    println!("Advantages of Qdrant:");
118    println!("  ✓ Persistent storage");
119    println!("  ✓ Highly scalable");
120    println!("  ✓ Production-ready");
121    println!("  ✓ Advanced features (filtering, etc.)");
122    println!("  ✗ Requires external service");
123    println!("  ✗ More complex setup\n");
124
125    Ok(())
126}
examples/react_agent.rs (line 47)
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}
Source

pub async fn ask(&mut self, question: impl Into<String>) -> Result<String>

Ultra-simple alias for chat - just ask a question!

Examples found in repository?
examples/quickstart.rs (line 17)
9async fn main() -> helios_engine::Result<()> {
10    println!("⚡ Helios Quick Start\n");
11
12    // Step 1: Create an agent in ONE LINE (using auto config)
13    let mut agent = Agent::quick("MyAgent").await?;
14    println!("✓ Agent created");
15
16    // Step 2: Ask a question
17    let response = agent.ask("What's the capital of France?").await?;
18    println!("Q: What's the capital of France?");
19    println!("A: {}\n", response);
20
21    // Step 3: Ask another question (agent remembers context!)
22    let response2 = agent.ask("What's its population?").await?;
23    println!("Q: What's its population?");
24    println!("A: {}\n", response2);
25
26    // That's it! You're using Helios! 🎉
27    println!("✅ Done! Create an agent and chat - that simple!");
28
29    Ok(())
30}
More examples
Hide additional examples
examples/ultra_simple.rs (line 28)
9async fn main() -> helios_engine::Result<()> {
10    println!("🚀 Ultra Simple Helios Example\n");
11
12    // ========== SIMPLEST AGENT CREATION ==========
13    println!("1️⃣  Creating an agent - shortest possible syntax:\n");
14
15    // One-liner: Create agent with auto config
16    let mut agent = Agent::builder("Helper")
17        .auto_config()
18        .prompt("You are helpful and concise.")
19        .build()
20        .await?;
21
22    println!("✓ Agent created!\n");
23
24    // ========== SIMPLEST CHAT ==========
25    println!("2️⃣  Asking questions - simplest possible:\n");
26
27    // Use .ask() instead of .chat() for more natural syntax
28    let answer = agent.ask("What is 2+2?").await?;
29    println!("Q: What is 2+2?\nA: {}\n", answer);
30
31    // ========== SIMPLEST CONFIG ==========
32    println!("3️⃣  Creating config with shortest syntax:\n");
33
34    // Ultra-short config creation
35    let _config = Config::builder()
36        .m("gpt-4") // .m() is shorthand for .model()
37        .key("your-api-key") // .key() is shorthand for .api_key()
38        .temp(0.8) // .temp() is shorthand for .temperature()
39        .tokens(1024) // .tokens() is shorthand for .max_tokens()
40        .build();
41
42    println!("✓ Config created with ultra-short syntax!\n");
43
44    // ========== SIMPLEST AGENT WITH TOOLS ==========
45    println!("4️⃣  Agent with tools - simplest way:\n");
46
47    let mut calc_agent = Agent::builder("Calculator")
48        .auto_config()
49        .prompt("You are a math expert.")
50        .with_tool(Box::new(CalculatorTool)) // Add single tool
51        .build()
52        .await?;
53
54    let result = calc_agent.ask("Calculate 15 * 7 + 5").await?;
55    println!("Q: Calculate 15 * 7 + 5\nA: {}\n", result);
56
57    // ========== SIMPLEST QUICK AGENT ==========
58    println!("5️⃣  Quick agent - one method call:\n");
59
60    // Agent::quick() creates agent in ONE LINE with auto config!
61    let mut quick_agent = Agent::quick("QuickBot").await?;
62    let quick_answer = quick_agent.ask("Say hello!").await?;
63    println!("Response: {}\n", quick_answer);
64
65    // ========== SIMPLEST CHAT MESSAGES ==========
66    println!("6️⃣  Creating messages - super short syntax:\n");
67
68    use helios_engine::ChatMessage;
69
70    // Short aliases for message creation
71    let _sys_msg = ChatMessage::sys("You are helpful"); // .sys() not .system()
72    let _user_msg = ChatMessage::msg("Hello there"); // .msg() not .user()
73    let _reply_msg = ChatMessage::reply("Hi! How can I help?"); // .reply() not .assistant()
74
75    println!("✓ Messages created with ultra-short syntax!\n");
76
77    // ========== SHORTEST AUTOFOREST ==========
78    println!("7️⃣  AutoForest - simplest multi-agent orchestration:\n");
79
80    use helios_engine::AutoForest;
81
82    let mut forest = AutoForest::new(Config::builder().m("gpt-4").build())
83        .with_tools(vec![Box::new(CalculatorTool)])
84        .build()
85        .await?;
86
87    // Use .run() for shortest syntax
88    let forest_result = forest.run("Analyze these numbers: 10, 20, 30, 40").await?;
89    println!("Forest Result:\n{}\n", forest_result);
90
91    // ========== COMPARISON TABLE ==========
92    println!("📊 Syntax Comparison - Short vs Long:\n");
93    println!("┌─────────────────────┬──────────────────────┬─────────────────┐");
94    println!("│ Operation           │ Short Syntax         │ Long Syntax      │");
95    println!("├─────────────────────┼──────────────────────┼─────────────────┤");
96    println!("│ Create Agent        │ Agent::quick()       │ Agent::builder()│");
97    println!("│ Ask Question        │ .ask()               │ .chat()          │");
98    println!("│ System Prompt       │ .prompt()            │ .system_prompt() │");
99    println!("│ Config Model        │ .m()                 │ .model()         │");
100    println!("│ Config Key          │ .key()               │ .api_key()       │");
101    println!("│ Config Temp         │ .temp()              │ .temperature()   │");
102    println!("│ Config Tokens       │ .tokens()            │ .max_tokens()    │");
103    println!("│ System Message      │ ChatMessage::sys()   │ ChatMessage::system()");
104    println!("│ User Message        │ ChatMessage::msg()   │ ChatMessage::user()");
105    println!("│ Assistant Message   │ ChatMessage::reply() │ ChatMessage::assistant()");
106    println!("│ AutoForest Execute  │ .run()               │ .execute_task()  │");
107    println!("└─────────────────────┴──────────────────────┴─────────────────┘\n");
108
109    println!("✅ All examples completed!");
110    println!("💡 Tip: Mix and match short and long syntax based on your preference!");
111
112    Ok(())
113}
Source

pub fn with_system_prompt(self, prompt: impl Into<String>) -> Self

Sets system prompt and returns self for chaining

Source

pub fn with_tool(self, tool: Box<dyn Tool>) -> Self

Registers a tool and returns self for chaining

Source

pub fn with_tools(self, tools: Vec<Box<dyn Tool>>) -> Self

Registers multiple tools and returns self for chaining

Source

pub fn set_max_iterations(&mut self, max: usize)

Sets the maximum number of iterations for tool execution.

§Arguments
  • max - The maximum number of iterations.
Source

pub fn get_session_summary(&self) -> String

Returns a summary of the current chat session.

Examples found in repository?
examples/agent_with_file_tools.rs (line 77)
10async fn main() -> helios_engine::Result<()> {
11    println!("🚀 Helios Engine - Agent with File Tools Example");
12    println!("=================================================\n");
13
14    // Load configuration
15    let config = Config::from_file("config.toml").unwrap_or_else(|_| {
16        println!("⚠ No config.toml found, using default configuration");
17        Config::new_default()
18    });
19
20    // Create an agent named "FileAssistant" and equip it with file tools.
21    let mut agent = Agent::builder("FileAssistant")
22        .config(config)
23        .system_prompt(
24            "You are a helpful file management assistant. You can search for files, \
25             read file contents, and edit files. Always confirm with the user before \
26             making changes to files. Keep track of important session information.",
27        )
28        .tool(Box::new(FileSearchTool))
29        .tool(Box::new(FileReadTool))
30        .tool(Box::new(FileEditTool))
31        .tool(Box::new(FileWriteTool))
32        .max_iterations(10)
33        .build()
34        .await?;
35
36    println!("✓ Agent created with file tools");
37    println!("✓ Available tools: file_search, file_read, file_edit, file_write\n");
38
39    // Set initial session memory for the agent.
40    agent.set_memory("session_start", chrono::Utc::now().to_rfc3339());
41    agent.set_memory(
42        "working_directory",
43        std::env::current_dir()?.display().to_string(),
44    );
45    agent.set_memory("tasks_completed", "0");
46
47    // --- Example 1: Search for Rust files ---
48    println!("Example 1: Searching for Rust files");
49    println!("====================================\n");
50
51    let response = agent
52        .chat("Find all Rust source files in the src directory")
53        .await?;
54    println!("Agent: {}\n", response);
55
56    // Update session memory after the task.
57    agent.increment_tasks_completed();
58    agent.set_memory("last_task", "file_search");
59
60    // --- Example 2: Read a specific file ---
61    println!("\nExample 2: Reading file contents");
62    println!("==================================\n");
63
64    let response = agent
65        .chat("Read the contents of src/lib.rs and give me a summary")
66        .await?;
67    println!("Agent: {}\n", response);
68
69    // Update session memory after the task.
70    agent.increment_tasks_completed();
71    agent.set_memory("last_task", "file_read");
72
73    // --- Example 3: Show session summary ---
74    println!("\nExample 3: Session Summary");
75    println!("==========================\n");
76
77    println!("{}", agent.get_session_summary());
78
79    // --- Example 4: Check session memory ---
80    println!("\nExample 4: Checking Session Memory");
81    println!("===================================\n");
82
83    println!(
84        "Working directory: {}",
85        agent
86            .get_memory("working_directory")
87            .unwrap_or(&"unknown".to_string())
88    );
89    println!(
90        "Tasks completed: {}",
91        agent
92            .get_memory("tasks_completed")
93            .unwrap_or(&"0".to_string())
94    );
95    println!(
96        "Last task: {}",
97        agent.get_memory("last_task").unwrap_or(&"none".to_string())
98    );
99
100    println!("\n Example completed successfully!");
101    println!("\n💡 Key Features Demonstrated:");
102    println!("  • File search with pattern matching and content search");
103    println!("  • File reading with line range support");
104    println!("  • File editing with find/replace functionality");
105    println!("  • Session memory for tracking agent state");
106    println!("  • Streaming responses (works with both local and remote models)");
107
108    Ok(())
109}
More examples
Hide additional examples
examples/complete_demo.rs (line 89)
12async fn main() -> helios_engine::Result<()> {
13    println!("🚀 Helios Engine - Complete Feature Demo");
14    println!("=========================================\n");
15
16    // Load configuration from `config.toml` or use default.
17    let config = Config::from_file("config.toml").unwrap_or_else(|_| {
18        println!("⚠ No config.toml found, using default configuration");
19        Config::new_default()
20    });
21
22    // Create an agent named "SmartAssistant" and equip it with all file tools.
23    println!("📦 Creating agent with file tools...");
24    let mut agent = Agent::builder("SmartAssistant")
25        .config(config)
26        .system_prompt(
27            "You are an intelligent assistant with file management capabilities. \
28             You can search files, read them, and make edits. Always explain what \
29             you're doing and track important information in session memory.",
30        )
31        .tool(Box::new(FileSearchTool))
32        .tool(Box::new(FileReadTool))
33        .tool(Box::new(FileEditTool))
34        .tool(Box::new(FileWriteTool))
35        .max_iterations(10)
36        .build()
37        .await?;
38
39    println!("✓ Agent created successfully!\n");
40
41    // Initialize session memory with some starting values.
42    println!("🧠 Initializing session memory...");
43    agent.set_memory("session_start", chrono::Utc::now().to_rfc3339());
44    agent.set_memory(
45        "working_directory",
46        std::env::current_dir()?.display().to_string(),
47    );
48    agent.set_memory("files_accessed", "0");
49    agent.set_memory("edits_made", "0");
50    println!("✓ Session memory initialized\n");
51
52    // --- Demo 1: Search for files with streaming response ---
53    println!("Demo 1: File Search with Streaming");
54    println!("===================================");
55    println!("User: Find all Rust example files\n");
56
57    print!("Agent: ");
58    io::stdout().flush()?;
59
60    let response1 = agent
61        .chat("Find all Rust example files in the examples directory")
62        .await?;
63    println!("{}\n", response1);
64
65    // Update session memory after the task.
66    agent.increment_counter("files_accessed");
67    agent.set_memory("last_action", "file_search");
68
69    // --- Demo 2: Read a file ---
70    println!("\nDemo 2: Reading File Contents");
71    println!("==============================");
72    println!("User: Read the NEW_FEATURES.md file and summarize the key points\n");
73
74    print!("Agent: ");
75    io::stdout().flush()?;
76
77    let response2 = agent
78        .chat("Read the NEW_FEATURES.md file and give me a brief summary of what's new")
79        .await?;
80    println!("{}\n", response2);
81
82    // Update session memory after the task.
83    agent.increment_counter("files_accessed");
84    agent.set_memory("last_action", "file_read");
85
86    // --- Demo 3: Show session summary ---
87    println!("\nDemo 3: Session Summary");
88    println!("=======================\n");
89    println!("{}", agent.get_session_summary());
90
91    // --- Demo 4: Interactive mode ---
92    println!("\n\nDemo 4: Interactive Mode");
93    println!("========================");
94    println!("You can now interact with the agent. Type 'exit' to quit.\n");
95
96    loop {
97        print!("\nYou: ");
98        io::stdout().flush()?;
99
100        let mut input = String::new();
101        io::stdin().read_line(&mut input)?;
102        let input = input.trim();
103
104        if input.is_empty() {
105            continue;
106        }
107
108        match input.to_lowercase().as_str() {
109            "exit" | "quit" => {
110                println!("\n👋 Goodbye!");
111                break;
112            }
113            "summary" => {
114                println!("\n📊 Session Summary:");
115                println!("{}", agent.get_session_summary());
116                continue;
117            }
118            "memory" => {
119                println!("\n🧠 Session Memory:");
120                if let Some(start) = agent.get_memory("session_start") {
121                    println!("  Session started: {}", start);
122                }
123                if let Some(dir) = agent.get_memory("working_directory") {
124                    println!("  Working directory: {}", dir);
125                }
126                if let Some(files) = agent.get_memory("files_accessed") {
127                    println!("  Files accessed: {}", files);
128                }
129                if let Some(edits) = agent.get_memory("edits_made") {
130                    println!("  Edits made: {}", edits);
131                }
132                if let Some(action) = agent.get_memory("last_action") {
133                    println!("  Last action: {}", action);
134                }
135                continue;
136            }
137            "help" => {
138                println!("\n📖 Available Commands:");
139                println!("  exit, quit  - Exit the demo");
140                println!("  summary     - Show session summary");
141                println!("  memory      - Show session memory");
142                println!("  help        - Show this help");
143                println!("\n💡 Try asking the agent to:");
144                println!("  • Search for specific files");
145                println!("  • Read file contents");
146                println!("  • Summarize what it has done");
147                continue;
148            }
149            _ => {}
150        }
151
152        // Send message to agent with streaming.
153        print!("\nAgent: ");
154        io::stdout().flush()?;
155
156        match agent.chat(input).await {
157            Ok(response) => {
158                println!("{}", response);
159
160                // Update memory after each interaction.
161                agent.increment_counter("files_accessed");
162            }
163            Err(e) => {
164                eprintln!("\n❌ Error: {}", e);
165            }
166        }
167    }
168
169    // --- Final summary ---
170    println!("\n📊 Final Session Summary:");
171    println!("{}", agent.get_session_summary());
172
173    println!("\n Demo completed successfully!");
174    println!("\n💡 Features Demonstrated:");
175    println!("  ✓ Streaming responses (local/remote models)");
176    println!("  ✓ File search with pattern matching");
177    println!("  ✓ File reading with summaries");
178    println!("  ✓ Session memory tracking");
179    println!("  ✓ Interactive conversation");
180    println!("  ✓ Real-time progress updates");
181
182    Ok(())
183}
Source

pub fn clear_memory(&mut self)

Clears the agent’s memory (agent-scoped metadata).

Source

pub fn set_memory(&mut self, key: impl Into<String>, value: impl Into<String>)

Sets a value in the agent’s memory.

Examples found in repository?
examples/agent_with_file_tools.rs (line 40)
10async fn main() -> helios_engine::Result<()> {
11    println!("🚀 Helios Engine - Agent with File Tools Example");
12    println!("=================================================\n");
13
14    // Load configuration
15    let config = Config::from_file("config.toml").unwrap_or_else(|_| {
16        println!("⚠ No config.toml found, using default configuration");
17        Config::new_default()
18    });
19
20    // Create an agent named "FileAssistant" and equip it with file tools.
21    let mut agent = Agent::builder("FileAssistant")
22        .config(config)
23        .system_prompt(
24            "You are a helpful file management assistant. You can search for files, \
25             read file contents, and edit files. Always confirm with the user before \
26             making changes to files. Keep track of important session information.",
27        )
28        .tool(Box::new(FileSearchTool))
29        .tool(Box::new(FileReadTool))
30        .tool(Box::new(FileEditTool))
31        .tool(Box::new(FileWriteTool))
32        .max_iterations(10)
33        .build()
34        .await?;
35
36    println!("✓ Agent created with file tools");
37    println!("✓ Available tools: file_search, file_read, file_edit, file_write\n");
38
39    // Set initial session memory for the agent.
40    agent.set_memory("session_start", chrono::Utc::now().to_rfc3339());
41    agent.set_memory(
42        "working_directory",
43        std::env::current_dir()?.display().to_string(),
44    );
45    agent.set_memory("tasks_completed", "0");
46
47    // --- Example 1: Search for Rust files ---
48    println!("Example 1: Searching for Rust files");
49    println!("====================================\n");
50
51    let response = agent
52        .chat("Find all Rust source files in the src directory")
53        .await?;
54    println!("Agent: {}\n", response);
55
56    // Update session memory after the task.
57    agent.increment_tasks_completed();
58    agent.set_memory("last_task", "file_search");
59
60    // --- Example 2: Read a specific file ---
61    println!("\nExample 2: Reading file contents");
62    println!("==================================\n");
63
64    let response = agent
65        .chat("Read the contents of src/lib.rs and give me a summary")
66        .await?;
67    println!("Agent: {}\n", response);
68
69    // Update session memory after the task.
70    agent.increment_tasks_completed();
71    agent.set_memory("last_task", "file_read");
72
73    // --- Example 3: Show session summary ---
74    println!("\nExample 3: Session Summary");
75    println!("==========================\n");
76
77    println!("{}", agent.get_session_summary());
78
79    // --- Example 4: Check session memory ---
80    println!("\nExample 4: Checking Session Memory");
81    println!("===================================\n");
82
83    println!(
84        "Working directory: {}",
85        agent
86            .get_memory("working_directory")
87            .unwrap_or(&"unknown".to_string())
88    );
89    println!(
90        "Tasks completed: {}",
91        agent
92            .get_memory("tasks_completed")
93            .unwrap_or(&"0".to_string())
94    );
95    println!(
96        "Last task: {}",
97        agent.get_memory("last_task").unwrap_or(&"none".to_string())
98    );
99
100    println!("\n Example completed successfully!");
101    println!("\n💡 Key Features Demonstrated:");
102    println!("  • File search with pattern matching and content search");
103    println!("  • File reading with line range support");
104    println!("  • File editing with find/replace functionality");
105    println!("  • Session memory for tracking agent state");
106    println!("  • Streaming responses (works with both local and remote models)");
107
108    Ok(())
109}
More examples
Hide additional examples
examples/complete_demo.rs (line 43)
12async fn main() -> helios_engine::Result<()> {
13    println!("🚀 Helios Engine - Complete Feature Demo");
14    println!("=========================================\n");
15
16    // Load configuration from `config.toml` or use default.
17    let config = Config::from_file("config.toml").unwrap_or_else(|_| {
18        println!("⚠ No config.toml found, using default configuration");
19        Config::new_default()
20    });
21
22    // Create an agent named "SmartAssistant" and equip it with all file tools.
23    println!("📦 Creating agent with file tools...");
24    let mut agent = Agent::builder("SmartAssistant")
25        .config(config)
26        .system_prompt(
27            "You are an intelligent assistant with file management capabilities. \
28             You can search files, read them, and make edits. Always explain what \
29             you're doing and track important information in session memory.",
30        )
31        .tool(Box::new(FileSearchTool))
32        .tool(Box::new(FileReadTool))
33        .tool(Box::new(FileEditTool))
34        .tool(Box::new(FileWriteTool))
35        .max_iterations(10)
36        .build()
37        .await?;
38
39    println!("✓ Agent created successfully!\n");
40
41    // Initialize session memory with some starting values.
42    println!("🧠 Initializing session memory...");
43    agent.set_memory("session_start", chrono::Utc::now().to_rfc3339());
44    agent.set_memory(
45        "working_directory",
46        std::env::current_dir()?.display().to_string(),
47    );
48    agent.set_memory("files_accessed", "0");
49    agent.set_memory("edits_made", "0");
50    println!("✓ Session memory initialized\n");
51
52    // --- Demo 1: Search for files with streaming response ---
53    println!("Demo 1: File Search with Streaming");
54    println!("===================================");
55    println!("User: Find all Rust example files\n");
56
57    print!("Agent: ");
58    io::stdout().flush()?;
59
60    let response1 = agent
61        .chat("Find all Rust example files in the examples directory")
62        .await?;
63    println!("{}\n", response1);
64
65    // Update session memory after the task.
66    agent.increment_counter("files_accessed");
67    agent.set_memory("last_action", "file_search");
68
69    // --- Demo 2: Read a file ---
70    println!("\nDemo 2: Reading File Contents");
71    println!("==============================");
72    println!("User: Read the NEW_FEATURES.md file and summarize the key points\n");
73
74    print!("Agent: ");
75    io::stdout().flush()?;
76
77    let response2 = agent
78        .chat("Read the NEW_FEATURES.md file and give me a brief summary of what's new")
79        .await?;
80    println!("{}\n", response2);
81
82    // Update session memory after the task.
83    agent.increment_counter("files_accessed");
84    agent.set_memory("last_action", "file_read");
85
86    // --- Demo 3: Show session summary ---
87    println!("\nDemo 3: Session Summary");
88    println!("=======================\n");
89    println!("{}", agent.get_session_summary());
90
91    // --- Demo 4: Interactive mode ---
92    println!("\n\nDemo 4: Interactive Mode");
93    println!("========================");
94    println!("You can now interact with the agent. Type 'exit' to quit.\n");
95
96    loop {
97        print!("\nYou: ");
98        io::stdout().flush()?;
99
100        let mut input = String::new();
101        io::stdin().read_line(&mut input)?;
102        let input = input.trim();
103
104        if input.is_empty() {
105            continue;
106        }
107
108        match input.to_lowercase().as_str() {
109            "exit" | "quit" => {
110                println!("\n👋 Goodbye!");
111                break;
112            }
113            "summary" => {
114                println!("\n📊 Session Summary:");
115                println!("{}", agent.get_session_summary());
116                continue;
117            }
118            "memory" => {
119                println!("\n🧠 Session Memory:");
120                if let Some(start) = agent.get_memory("session_start") {
121                    println!("  Session started: {}", start);
122                }
123                if let Some(dir) = agent.get_memory("working_directory") {
124                    println!("  Working directory: {}", dir);
125                }
126                if let Some(files) = agent.get_memory("files_accessed") {
127                    println!("  Files accessed: {}", files);
128                }
129                if let Some(edits) = agent.get_memory("edits_made") {
130                    println!("  Edits made: {}", edits);
131                }
132                if let Some(action) = agent.get_memory("last_action") {
133                    println!("  Last action: {}", action);
134                }
135                continue;
136            }
137            "help" => {
138                println!("\n📖 Available Commands:");
139                println!("  exit, quit  - Exit the demo");
140                println!("  summary     - Show session summary");
141                println!("  memory      - Show session memory");
142                println!("  help        - Show this help");
143                println!("\n💡 Try asking the agent to:");
144                println!("  • Search for specific files");
145                println!("  • Read file contents");
146                println!("  • Summarize what it has done");
147                continue;
148            }
149            _ => {}
150        }
151
152        // Send message to agent with streaming.
153        print!("\nAgent: ");
154        io::stdout().flush()?;
155
156        match agent.chat(input).await {
157            Ok(response) => {
158                println!("{}", response);
159
160                // Update memory after each interaction.
161                agent.increment_counter("files_accessed");
162            }
163            Err(e) => {
164                eprintln!("\n❌ Error: {}", e);
165            }
166        }
167    }
168
169    // --- Final summary ---
170    println!("\n📊 Final Session Summary:");
171    println!("{}", agent.get_session_summary());
172
173    println!("\n Demo completed successfully!");
174    println!("\n💡 Features Demonstrated:");
175    println!("  ✓ Streaming responses (local/remote models)");
176    println!("  ✓ File search with pattern matching");
177    println!("  ✓ File reading with summaries");
178    println!("  ✓ Session memory tracking");
179    println!("  ✓ Interactive conversation");
180    println!("  ✓ Real-time progress updates");
181
182    Ok(())
183}
Source

pub fn get_memory(&self, key: &str) -> Option<&String>

Gets a value from the agent’s memory.

Examples found in repository?
examples/agent_with_file_tools.rs (line 86)
10async fn main() -> helios_engine::Result<()> {
11    println!("🚀 Helios Engine - Agent with File Tools Example");
12    println!("=================================================\n");
13
14    // Load configuration
15    let config = Config::from_file("config.toml").unwrap_or_else(|_| {
16        println!("⚠ No config.toml found, using default configuration");
17        Config::new_default()
18    });
19
20    // Create an agent named "FileAssistant" and equip it with file tools.
21    let mut agent = Agent::builder("FileAssistant")
22        .config(config)
23        .system_prompt(
24            "You are a helpful file management assistant. You can search for files, \
25             read file contents, and edit files. Always confirm with the user before \
26             making changes to files. Keep track of important session information.",
27        )
28        .tool(Box::new(FileSearchTool))
29        .tool(Box::new(FileReadTool))
30        .tool(Box::new(FileEditTool))
31        .tool(Box::new(FileWriteTool))
32        .max_iterations(10)
33        .build()
34        .await?;
35
36    println!("✓ Agent created with file tools");
37    println!("✓ Available tools: file_search, file_read, file_edit, file_write\n");
38
39    // Set initial session memory for the agent.
40    agent.set_memory("session_start", chrono::Utc::now().to_rfc3339());
41    agent.set_memory(
42        "working_directory",
43        std::env::current_dir()?.display().to_string(),
44    );
45    agent.set_memory("tasks_completed", "0");
46
47    // --- Example 1: Search for Rust files ---
48    println!("Example 1: Searching for Rust files");
49    println!("====================================\n");
50
51    let response = agent
52        .chat("Find all Rust source files in the src directory")
53        .await?;
54    println!("Agent: {}\n", response);
55
56    // Update session memory after the task.
57    agent.increment_tasks_completed();
58    agent.set_memory("last_task", "file_search");
59
60    // --- Example 2: Read a specific file ---
61    println!("\nExample 2: Reading file contents");
62    println!("==================================\n");
63
64    let response = agent
65        .chat("Read the contents of src/lib.rs and give me a summary")
66        .await?;
67    println!("Agent: {}\n", response);
68
69    // Update session memory after the task.
70    agent.increment_tasks_completed();
71    agent.set_memory("last_task", "file_read");
72
73    // --- Example 3: Show session summary ---
74    println!("\nExample 3: Session Summary");
75    println!("==========================\n");
76
77    println!("{}", agent.get_session_summary());
78
79    // --- Example 4: Check session memory ---
80    println!("\nExample 4: Checking Session Memory");
81    println!("===================================\n");
82
83    println!(
84        "Working directory: {}",
85        agent
86            .get_memory("working_directory")
87            .unwrap_or(&"unknown".to_string())
88    );
89    println!(
90        "Tasks completed: {}",
91        agent
92            .get_memory("tasks_completed")
93            .unwrap_or(&"0".to_string())
94    );
95    println!(
96        "Last task: {}",
97        agent.get_memory("last_task").unwrap_or(&"none".to_string())
98    );
99
100    println!("\n Example completed successfully!");
101    println!("\n💡 Key Features Demonstrated:");
102    println!("  • File search with pattern matching and content search");
103    println!("  • File reading with line range support");
104    println!("  • File editing with find/replace functionality");
105    println!("  • Session memory for tracking agent state");
106    println!("  • Streaming responses (works with both local and remote models)");
107
108    Ok(())
109}
More examples
Hide additional examples
examples/complete_demo.rs (line 120)
12async fn main() -> helios_engine::Result<()> {
13    println!("🚀 Helios Engine - Complete Feature Demo");
14    println!("=========================================\n");
15
16    // Load configuration from `config.toml` or use default.
17    let config = Config::from_file("config.toml").unwrap_or_else(|_| {
18        println!("⚠ No config.toml found, using default configuration");
19        Config::new_default()
20    });
21
22    // Create an agent named "SmartAssistant" and equip it with all file tools.
23    println!("📦 Creating agent with file tools...");
24    let mut agent = Agent::builder("SmartAssistant")
25        .config(config)
26        .system_prompt(
27            "You are an intelligent assistant with file management capabilities. \
28             You can search files, read them, and make edits. Always explain what \
29             you're doing and track important information in session memory.",
30        )
31        .tool(Box::new(FileSearchTool))
32        .tool(Box::new(FileReadTool))
33        .tool(Box::new(FileEditTool))
34        .tool(Box::new(FileWriteTool))
35        .max_iterations(10)
36        .build()
37        .await?;
38
39    println!("✓ Agent created successfully!\n");
40
41    // Initialize session memory with some starting values.
42    println!("🧠 Initializing session memory...");
43    agent.set_memory("session_start", chrono::Utc::now().to_rfc3339());
44    agent.set_memory(
45        "working_directory",
46        std::env::current_dir()?.display().to_string(),
47    );
48    agent.set_memory("files_accessed", "0");
49    agent.set_memory("edits_made", "0");
50    println!("✓ Session memory initialized\n");
51
52    // --- Demo 1: Search for files with streaming response ---
53    println!("Demo 1: File Search with Streaming");
54    println!("===================================");
55    println!("User: Find all Rust example files\n");
56
57    print!("Agent: ");
58    io::stdout().flush()?;
59
60    let response1 = agent
61        .chat("Find all Rust example files in the examples directory")
62        .await?;
63    println!("{}\n", response1);
64
65    // Update session memory after the task.
66    agent.increment_counter("files_accessed");
67    agent.set_memory("last_action", "file_search");
68
69    // --- Demo 2: Read a file ---
70    println!("\nDemo 2: Reading File Contents");
71    println!("==============================");
72    println!("User: Read the NEW_FEATURES.md file and summarize the key points\n");
73
74    print!("Agent: ");
75    io::stdout().flush()?;
76
77    let response2 = agent
78        .chat("Read the NEW_FEATURES.md file and give me a brief summary of what's new")
79        .await?;
80    println!("{}\n", response2);
81
82    // Update session memory after the task.
83    agent.increment_counter("files_accessed");
84    agent.set_memory("last_action", "file_read");
85
86    // --- Demo 3: Show session summary ---
87    println!("\nDemo 3: Session Summary");
88    println!("=======================\n");
89    println!("{}", agent.get_session_summary());
90
91    // --- Demo 4: Interactive mode ---
92    println!("\n\nDemo 4: Interactive Mode");
93    println!("========================");
94    println!("You can now interact with the agent. Type 'exit' to quit.\n");
95
96    loop {
97        print!("\nYou: ");
98        io::stdout().flush()?;
99
100        let mut input = String::new();
101        io::stdin().read_line(&mut input)?;
102        let input = input.trim();
103
104        if input.is_empty() {
105            continue;
106        }
107
108        match input.to_lowercase().as_str() {
109            "exit" | "quit" => {
110                println!("\n👋 Goodbye!");
111                break;
112            }
113            "summary" => {
114                println!("\n📊 Session Summary:");
115                println!("{}", agent.get_session_summary());
116                continue;
117            }
118            "memory" => {
119                println!("\n🧠 Session Memory:");
120                if let Some(start) = agent.get_memory("session_start") {
121                    println!("  Session started: {}", start);
122                }
123                if let Some(dir) = agent.get_memory("working_directory") {
124                    println!("  Working directory: {}", dir);
125                }
126                if let Some(files) = agent.get_memory("files_accessed") {
127                    println!("  Files accessed: {}", files);
128                }
129                if let Some(edits) = agent.get_memory("edits_made") {
130                    println!("  Edits made: {}", edits);
131                }
132                if let Some(action) = agent.get_memory("last_action") {
133                    println!("  Last action: {}", action);
134                }
135                continue;
136            }
137            "help" => {
138                println!("\n📖 Available Commands:");
139                println!("  exit, quit  - Exit the demo");
140                println!("  summary     - Show session summary");
141                println!("  memory      - Show session memory");
142                println!("  help        - Show this help");
143                println!("\n💡 Try asking the agent to:");
144                println!("  • Search for specific files");
145                println!("  • Read file contents");
146                println!("  • Summarize what it has done");
147                continue;
148            }
149            _ => {}
150        }
151
152        // Send message to agent with streaming.
153        print!("\nAgent: ");
154        io::stdout().flush()?;
155
156        match agent.chat(input).await {
157            Ok(response) => {
158                println!("{}", response);
159
160                // Update memory after each interaction.
161                agent.increment_counter("files_accessed");
162            }
163            Err(e) => {
164                eprintln!("\n❌ Error: {}", e);
165            }
166        }
167    }
168
169    // --- Final summary ---
170    println!("\n📊 Final Session Summary:");
171    println!("{}", agent.get_session_summary());
172
173    println!("\n Demo completed successfully!");
174    println!("\n💡 Features Demonstrated:");
175    println!("  ✓ Streaming responses (local/remote models)");
176    println!("  ✓ File search with pattern matching");
177    println!("  ✓ File reading with summaries");
178    println!("  ✓ Session memory tracking");
179    println!("  ✓ Interactive conversation");
180    println!("  ✓ Real-time progress updates");
181
182    Ok(())
183}
Source

pub fn remove_memory(&mut self, key: &str) -> Option<String>

Removes a value from the agent’s memory.

Source

pub fn increment_counter(&mut self, key: &str) -> u32

Increments a counter in the agent’s memory.

Examples found in repository?
examples/complete_demo.rs (line 66)
12async fn main() -> helios_engine::Result<()> {
13    println!("🚀 Helios Engine - Complete Feature Demo");
14    println!("=========================================\n");
15
16    // Load configuration from `config.toml` or use default.
17    let config = Config::from_file("config.toml").unwrap_or_else(|_| {
18        println!("⚠ No config.toml found, using default configuration");
19        Config::new_default()
20    });
21
22    // Create an agent named "SmartAssistant" and equip it with all file tools.
23    println!("📦 Creating agent with file tools...");
24    let mut agent = Agent::builder("SmartAssistant")
25        .config(config)
26        .system_prompt(
27            "You are an intelligent assistant with file management capabilities. \
28             You can search files, read them, and make edits. Always explain what \
29             you're doing and track important information in session memory.",
30        )
31        .tool(Box::new(FileSearchTool))
32        .tool(Box::new(FileReadTool))
33        .tool(Box::new(FileEditTool))
34        .tool(Box::new(FileWriteTool))
35        .max_iterations(10)
36        .build()
37        .await?;
38
39    println!("✓ Agent created successfully!\n");
40
41    // Initialize session memory with some starting values.
42    println!("🧠 Initializing session memory...");
43    agent.set_memory("session_start", chrono::Utc::now().to_rfc3339());
44    agent.set_memory(
45        "working_directory",
46        std::env::current_dir()?.display().to_string(),
47    );
48    agent.set_memory("files_accessed", "0");
49    agent.set_memory("edits_made", "0");
50    println!("✓ Session memory initialized\n");
51
52    // --- Demo 1: Search for files with streaming response ---
53    println!("Demo 1: File Search with Streaming");
54    println!("===================================");
55    println!("User: Find all Rust example files\n");
56
57    print!("Agent: ");
58    io::stdout().flush()?;
59
60    let response1 = agent
61        .chat("Find all Rust example files in the examples directory")
62        .await?;
63    println!("{}\n", response1);
64
65    // Update session memory after the task.
66    agent.increment_counter("files_accessed");
67    agent.set_memory("last_action", "file_search");
68
69    // --- Demo 2: Read a file ---
70    println!("\nDemo 2: Reading File Contents");
71    println!("==============================");
72    println!("User: Read the NEW_FEATURES.md file and summarize the key points\n");
73
74    print!("Agent: ");
75    io::stdout().flush()?;
76
77    let response2 = agent
78        .chat("Read the NEW_FEATURES.md file and give me a brief summary of what's new")
79        .await?;
80    println!("{}\n", response2);
81
82    // Update session memory after the task.
83    agent.increment_counter("files_accessed");
84    agent.set_memory("last_action", "file_read");
85
86    // --- Demo 3: Show session summary ---
87    println!("\nDemo 3: Session Summary");
88    println!("=======================\n");
89    println!("{}", agent.get_session_summary());
90
91    // --- Demo 4: Interactive mode ---
92    println!("\n\nDemo 4: Interactive Mode");
93    println!("========================");
94    println!("You can now interact with the agent. Type 'exit' to quit.\n");
95
96    loop {
97        print!("\nYou: ");
98        io::stdout().flush()?;
99
100        let mut input = String::new();
101        io::stdin().read_line(&mut input)?;
102        let input = input.trim();
103
104        if input.is_empty() {
105            continue;
106        }
107
108        match input.to_lowercase().as_str() {
109            "exit" | "quit" => {
110                println!("\n👋 Goodbye!");
111                break;
112            }
113            "summary" => {
114                println!("\n📊 Session Summary:");
115                println!("{}", agent.get_session_summary());
116                continue;
117            }
118            "memory" => {
119                println!("\n🧠 Session Memory:");
120                if let Some(start) = agent.get_memory("session_start") {
121                    println!("  Session started: {}", start);
122                }
123                if let Some(dir) = agent.get_memory("working_directory") {
124                    println!("  Working directory: {}", dir);
125                }
126                if let Some(files) = agent.get_memory("files_accessed") {
127                    println!("  Files accessed: {}", files);
128                }
129                if let Some(edits) = agent.get_memory("edits_made") {
130                    println!("  Edits made: {}", edits);
131                }
132                if let Some(action) = agent.get_memory("last_action") {
133                    println!("  Last action: {}", action);
134                }
135                continue;
136            }
137            "help" => {
138                println!("\n📖 Available Commands:");
139                println!("  exit, quit  - Exit the demo");
140                println!("  summary     - Show session summary");
141                println!("  memory      - Show session memory");
142                println!("  help        - Show this help");
143                println!("\n💡 Try asking the agent to:");
144                println!("  • Search for specific files");
145                println!("  • Read file contents");
146                println!("  • Summarize what it has done");
147                continue;
148            }
149            _ => {}
150        }
151
152        // Send message to agent with streaming.
153        print!("\nAgent: ");
154        io::stdout().flush()?;
155
156        match agent.chat(input).await {
157            Ok(response) => {
158                println!("{}", response);
159
160                // Update memory after each interaction.
161                agent.increment_counter("files_accessed");
162            }
163            Err(e) => {
164                eprintln!("\n❌ Error: {}", e);
165            }
166        }
167    }
168
169    // --- Final summary ---
170    println!("\n📊 Final Session Summary:");
171    println!("{}", agent.get_session_summary());
172
173    println!("\n Demo completed successfully!");
174    println!("\n💡 Features Demonstrated:");
175    println!("  ✓ Streaming responses (local/remote models)");
176    println!("  ✓ File search with pattern matching");
177    println!("  ✓ File reading with summaries");
178    println!("  ✓ Session memory tracking");
179    println!("  ✓ Interactive conversation");
180    println!("  ✓ Real-time progress updates");
181
182    Ok(())
183}
Source

pub fn increment_tasks_completed(&mut self) -> u32

Increments the “tasks_completed” counter in the agent’s memory.

Examples found in repository?
examples/agent_with_file_tools.rs (line 57)
10async fn main() -> helios_engine::Result<()> {
11    println!("🚀 Helios Engine - Agent with File Tools Example");
12    println!("=================================================\n");
13
14    // Load configuration
15    let config = Config::from_file("config.toml").unwrap_or_else(|_| {
16        println!("⚠ No config.toml found, using default configuration");
17        Config::new_default()
18    });
19
20    // Create an agent named "FileAssistant" and equip it with file tools.
21    let mut agent = Agent::builder("FileAssistant")
22        .config(config)
23        .system_prompt(
24            "You are a helpful file management assistant. You can search for files, \
25             read file contents, and edit files. Always confirm with the user before \
26             making changes to files. Keep track of important session information.",
27        )
28        .tool(Box::new(FileSearchTool))
29        .tool(Box::new(FileReadTool))
30        .tool(Box::new(FileEditTool))
31        .tool(Box::new(FileWriteTool))
32        .max_iterations(10)
33        .build()
34        .await?;
35
36    println!("✓ Agent created with file tools");
37    println!("✓ Available tools: file_search, file_read, file_edit, file_write\n");
38
39    // Set initial session memory for the agent.
40    agent.set_memory("session_start", chrono::Utc::now().to_rfc3339());
41    agent.set_memory(
42        "working_directory",
43        std::env::current_dir()?.display().to_string(),
44    );
45    agent.set_memory("tasks_completed", "0");
46
47    // --- Example 1: Search for Rust files ---
48    println!("Example 1: Searching for Rust files");
49    println!("====================================\n");
50
51    let response = agent
52        .chat("Find all Rust source files in the src directory")
53        .await?;
54    println!("Agent: {}\n", response);
55
56    // Update session memory after the task.
57    agent.increment_tasks_completed();
58    agent.set_memory("last_task", "file_search");
59
60    // --- Example 2: Read a specific file ---
61    println!("\nExample 2: Reading file contents");
62    println!("==================================\n");
63
64    let response = agent
65        .chat("Read the contents of src/lib.rs and give me a summary")
66        .await?;
67    println!("Agent: {}\n", response);
68
69    // Update session memory after the task.
70    agent.increment_tasks_completed();
71    agent.set_memory("last_task", "file_read");
72
73    // --- Example 3: Show session summary ---
74    println!("\nExample 3: Session Summary");
75    println!("==========================\n");
76
77    println!("{}", agent.get_session_summary());
78
79    // --- Example 4: Check session memory ---
80    println!("\nExample 4: Checking Session Memory");
81    println!("===================================\n");
82
83    println!(
84        "Working directory: {}",
85        agent
86            .get_memory("working_directory")
87            .unwrap_or(&"unknown".to_string())
88    );
89    println!(
90        "Tasks completed: {}",
91        agent
92            .get_memory("tasks_completed")
93            .unwrap_or(&"0".to_string())
94    );
95    println!(
96        "Last task: {}",
97        agent.get_memory("last_task").unwrap_or(&"none".to_string())
98    );
99
100    println!("\n Example completed successfully!");
101    println!("\n💡 Key Features Demonstrated:");
102    println!("  • File search with pattern matching and content search");
103    println!("  • File reading with line range support");
104    println!("  • File editing with find/replace functionality");
105    println!("  • Session memory for tracking agent state");
106    println!("  • Streaming responses (works with both local and remote models)");
107
108    Ok(())
109}
Source

pub async fn chat_with_history( &mut self, messages: Vec<ChatMessage>, temperature: Option<f32>, max_tokens: Option<u32>, stop: Option<Vec<String>>, ) -> Result<String>

Executes a stateless conversation with the provided message history.

This method creates a temporary chat session with the provided messages and executes the agent logic without modifying the agent’s persistent session. This is useful for OpenAI API compatibility where each request contains the full conversation history.

§Arguments
  • messages - The complete conversation history for this request
  • temperature - Optional temperature parameter for generation
  • max_tokens - Optional maximum tokens parameter for generation
  • stop - Optional stop sequences for generation
§Returns

A Result containing the assistant’s response content.

Source

pub async fn chat_stream_with_history<F>( &mut self, messages: Vec<ChatMessage>, temperature: Option<f32>, max_tokens: Option<u32>, stop: Option<Vec<String>>, on_chunk: F, ) -> Result<ChatMessage>
where F: FnMut(&str) + Send,

Executes a stateless conversation with the provided message history and streams the response.

This method creates a temporary chat session with the provided messages and streams the agent’s response in real-time as tokens are generated. Note: Tool calls are not supported in streaming mode yet - they will be executed after the initial response is complete.

§Arguments
  • messages - The complete conversation history for this request
  • temperature - Optional temperature parameter for generation
  • max_tokens - Optional maximum tokens parameter for generation
  • stop - Optional stop sequences for generation
  • on_chunk - Callback function called for each chunk of generated text
§Returns

A Result containing the final assistant message after streaming is complete.

Auto Trait Implementations§

§

impl Freeze for Agent

§

impl !RefUnwindSafe for Agent

§

impl Send for Agent

§

impl Sync for Agent

§

impl Unpin for Agent

§

impl !UnwindSafe for Agent

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