pub struct AgentBuilder { /* private fields */ }Implementationsยง
Sourceยงimpl AgentBuilder
impl AgentBuilder
pub fn new(name: impl Into<String>) -> Self
Sourcepub fn config(self, config: Config) -> Self
pub fn config(self, config: Config) -> Self
Examples found in repository?
examples/custom_tool.rs (line 80)
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
examples/agent_with_tools.rs (line 16)
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 20)
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 24)
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 18)
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 33)
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}Additional examples can be found in:
- examples/serve_with_custom_endpoints.rs
- examples/react_agent.rs
- examples/agent_with_file_tools.rs
- examples/agent_with_memory_db.rs
- examples/serve_simple_endpoints.rs
- examples/react_debugging.rs
- examples/react_comparison.rs
- examples/rag_in_memory.rs
- examples/agent_with_rag.rs
- examples/tool_builder_demo.rs
- examples/complete_demo.rs
- examples/react_custom_prompt.rs
Sourcepub fn auto_config(self) -> Self
pub fn auto_config(self) -> Self
Shorthand: set config directly from a file or use defaults
Examples found in repository?
examples/ultra_simple.rs (line 17)
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}Sourcepub fn system_prompt(self, prompt: impl Into<String>) -> Self
pub fn system_prompt(self, prompt: impl Into<String>) -> Self
Examples found in repository?
examples/custom_tool.rs (line 81)
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
examples/agent_with_tools.rs (line 17)
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 21)
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 25)
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 19)
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 34)
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}Additional examples can be found in:
- examples/serve_with_custom_endpoints.rs
- examples/react_agent.rs
- examples/forest_simple_demo.rs
- examples/agent_with_file_tools.rs
- examples/agent_with_memory_db.rs
- examples/serve_simple_endpoints.rs
- examples/react_debugging.rs
- examples/react_comparison.rs
- examples/rag_in_memory.rs
- examples/agent_with_rag.rs
- examples/tool_builder_demo.rs
- examples/send_message_tool_demo.rs
- examples/complete_demo.rs
- examples/react_custom_prompt.rs
- examples/forest_of_agents.rs
- examples/forest_with_coordinator.rs
Sourcepub fn prompt(self, prompt: impl Into<String>) -> Self
pub fn prompt(self, prompt: impl Into<String>) -> Self
Shorthand: use โpromptโ instead of โsystem_promptโ
Examples found in repository?
examples/ultra_simple.rs (line 18)
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}Sourcepub fn tool(self, tool: Box<dyn Tool>) -> Self
pub fn tool(self, tool: Box<dyn Tool>) -> Self
Adds a single tool to the agent.
Examples found in repository?
examples/custom_tool.rs (line 82)
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
examples/serve_agent.rs (line 22)
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/multiple_agents.rs (line 20)
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 35)
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/serve_with_custom_endpoints.rs (line 22)
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 // Define custom endpoints
28 let custom_endpoints = CustomEndpointsConfig {
29 endpoints: vec![
30 CustomEndpoint {
31 method: "GET".to_string(),
32 path: "/api/version".to_string(),
33 response: serde_json::json!({
34 "version": "0.2.8",
35 "service": "Helios Engine",
36 "features": ["agents", "tools", "streaming", "custom_endpoints"]
37 }),
38 status_code: 200,
39 },
40 CustomEndpoint {
41 method: "GET".to_string(),
42 path: "/api/status".to_string(),
43 response: serde_json::json!({
44 "status": "operational",
45 "uptime": "unknown",
46 "model": "agent-based"
47 }),
48 status_code: 200,
49 },
50 CustomEndpoint {
51 method: "POST".to_string(),
52 path: "/api/echo".to_string(),
53 response: serde_json::json!({
54 "message": "Echo endpoint - this returns static data",
55 "note": "For dynamic responses, use the chat completions endpoint"
56 }),
57 status_code: 200,
58 },
59 ],
60 };
61
62 // Start the server with custom endpoints
63 println!("Starting server on http://127.0.0.1:8000");
64 println!("๐ก OpenAI-compatible API endpoints:");
65 println!(" POST /v1/chat/completions");
66 println!(" GET /v1/models");
67 println!("๐ก Custom endpoints:");
68 println!(" GET /api/version");
69 println!(" GET /api/status");
70 println!(" POST /api/echo");
71 println!();
72 println!("Try: curl http://127.0.0.1:8000/api/version");
73
74 helios_engine::serve::start_server_with_agent_and_custom_endpoints(
75 agent,
76 "local-model".to_string(),
77 "127.0.0.1:8000",
78 Some(custom_endpoints),
79 )
80 .await?;
81
82 Ok(())
83}examples/agent_with_file_tools.rs (line 28)
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}Sourcepub fn with_tool(self, tool: Box<dyn Tool>) -> Self
pub fn with_tool(self, tool: Box<dyn Tool>) -> Self
Shorthand: add a single tool (alias for tool())
Examples found in repository?
examples/ultra_simple.rs (line 50)
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}Sourcepub fn tools(self, tools: Vec<Box<dyn Tool>>) -> Self
pub fn tools(self, tools: Vec<Box<dyn Tool>>) -> Self
Adds multiple tools to the agent at once.
ยงExample
let agent = Agent::builder("MyAgent")
.config(config)
.tools(vec![
Box::new(CalculatorTool),
Box::new(EchoTool),
])
.build()
.await?;Examples found in repository?
examples/agent_with_tools.rs (line 18)
9async fn main() -> helios_engine::Result<()> {
10 // Load configuration from `config.toml`.
11 let config = Config::from_file("config.toml")?;
12
13 // Create an agent named "ToolAgent" and equip it with the `CalculatorTool` and `EchoTool`.
14 // Using the improved syntax to add multiple tools at once!
15 let mut agent = Agent::builder("ToolAgent")
16 .config(config)
17 .system_prompt("You are a helpful assistant with access to tools. Use them when needed.")
18 .tools(vec![Box::new(CalculatorTool), Box::new(EchoTool)])
19 .max_iterations(5)
20 .build()
21 .await?;
22
23 println!(
24 "Available tools: {:?}\n",
25 agent.tool_registry().list_tools()
26 );
27
28 // --- Test the calculator tool ---
29 let response = agent.chat("What is 25 * 4 + 10?").await?;
30 println!("Agent: {}\n", response);
31
32 // --- Test the echo tool ---
33 let response = agent
34 .chat("Can you echo this message: 'Hello from Helios!'")
35 .await?;
36 println!("Agent: {}\n", response);
37
38 Ok(())
39}More examples
examples/react_agent.rs (lines 25-29)
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 (lines 29-33)
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 20)
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}examples/react_custom_prompt.rs (line 62)
9async fn main() -> helios_engine::Result<()> {
10 println!("๐ง Helios Engine - ReAct with Custom Prompts");
11 println!("=============================================\n");
12
13 let config = Config::from_file("config.toml")?;
14
15 // Example 1: Math-focused reasoning prompt
16 println!("โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ");
17 println!("Example 1: Mathematical Problem Solver");
18 println!("โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ\n");
19
20 let math_prompt = r#"As a mathematical problem solver, analyze this systematically:
21
221. IDENTIFY: What mathematical operations are required?
232. DECOMPOSE: Break complex calculations into simple steps
243. ORDER: Determine the correct order of operations (PEMDAS/BODMAS)
254. PLAN: List which calculator functions to use and in what sequence
265. VERIFY: Consider how to check the answer
27
28Provide your mathematical reasoning clearly."#;
29
30 let mut math_agent = Agent::builder("MathExpert")
31 .config(config.clone())
32 .system_prompt("You are a mathematical expert who thinks carefully about calculations.")
33 .tool(Box::new(CalculatorTool))
34 .react_with_prompt(math_prompt)
35 .build()
36 .await?;
37
38 println!("User: Calculate ((15 * 8) + (20 * 3)) / 2\n");
39 let response = math_agent
40 .chat("Calculate ((15 * 8) + (20 * 3)) / 2")
41 .await?;
42 println!("\nAgent: {}\n", response);
43
44 // Example 2: Data analysis reasoning prompt
45 println!("โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ");
46 println!("Example 2: Data Analysis Agent");
47 println!("โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ\n");
48
49 let data_prompt = r#"As a data analyst, approach this task methodically:
50
511. UNDERSTAND: What data or files are we working with?
522. EXTRACT: What information needs to be retrieved?
533. PROCESS: What transformations or calculations are needed?
544. TOOLS: Which tools should I use and in what order?
555. OUTPUT: What format should the final answer take?
56
57Think through the data pipeline step by step."#;
58
59 let mut data_agent = Agent::builder("DataAnalyst")
60 .config(config.clone())
61 .system_prompt("You are a data analyst who carefully plans data processing tasks.")
62 .tools(vec![Box::new(FileReadTool), Box::new(CalculatorTool)])
63 .react_with_prompt(data_prompt)
64 .build()
65 .await?;
66
67 println!("User: If I have numbers 10, 20, 30, 40, 50, what's their average?\n");
68 let response = data_agent
69 .chat("If I have numbers 10, 20, 30, 40, 50, what's their average?")
70 .await?;
71 println!("\nAgent: {}\n", response);
72
73 // Example 3: Task planning reasoning prompt
74 println!("โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ");
75 println!("Example 3: Task Planning Agent");
76 println!("โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ\n");
77
78 let planning_prompt = r#"As a task planning expert, organize this systematically:
79
801. GOAL: What is the end objective?
812. PREREQUISITES: What information do I already have?
823. DEPENDENCIES: What needs to happen before what?
834. RESOURCES: What tools are available to me?
845. STEPS: Create a numbered action plan
856. CONTINGENCY: What could go wrong?
86
87Plan the execution strategy carefully."#;
88
89 let mut planning_agent = Agent::builder("TaskPlanner")
90 .config(config.clone())
91 .system_prompt("You are a strategic planner who breaks down complex tasks.")
92 .tool(Box::new(CalculatorTool))
93 .react_with_prompt(planning_prompt)
94 .build()
95 .await?;
96
97 println!("User: I need to calculate the total cost: 5 items at $12.50 each, plus 8% tax\n");
98 let response = planning_agent
99 .chat("I need to calculate the total cost: 5 items at $12.50 each, plus 8% tax")
100 .await?;
101 println!("\nAgent: {}\n", response);
102
103 // Example 4: Scientific reasoning prompt
104 println!("โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ");
105 println!("Example 4: Scientific Reasoning Agent");
106 println!("โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ\n");
107
108 let scientific_prompt = r#"Apply the scientific method to this problem:
109
1101. OBSERVATION: What is being asked?
1112. HYPOTHESIS: What approach should work?
1123. VARIABLES: What factors are involved?
1134. METHOD: What tools and operations are needed?
1145. PREDICTION: What result do we expect?
1156. VERIFICATION: How can we validate the answer?
116
117Use rigorous scientific thinking."#;
118
119 let mut science_agent = Agent::builder("Scientist")
120 .config(config)
121 .system_prompt("You are a scientist who applies rigorous methodology.")
122 .tool(Box::new(CalculatorTool))
123 .react_with_prompt(scientific_prompt)
124 .build()
125 .await?;
126
127 println!("User: If velocity = 30 m/s and time = 4 seconds, what's the distance?\n");
128 let response = science_agent
129 .chat("If velocity = 30 m/s and time = 4 seconds, what's the distance?")
130 .await?;
131 println!("\nAgent: {}\n", response);
132
133 println!("โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ");
134 println!(" Custom Prompt Demo Complete!");
135 println!("โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ");
136 println!("\nKey Takeaways:");
137 println!(" โข Custom prompts tailor reasoning to specific domains");
138 println!(" โข Different prompts optimize for different task types");
139 println!(" โข Use .react_with_prompt() for domain-specific reasoning");
140 println!(" โข Each agent can have its own reasoning style\n");
141
142 Ok(())
143}Sourcepub fn with_tools(self, tools: Vec<Box<dyn Tool>>) -> Self
pub fn with_tools(self, tools: Vec<Box<dyn Tool>>) -> Self
Shorthand: add multiple tools (alias for tools())
Sourcepub fn max_iterations(self, max: usize) -> Self
pub fn max_iterations(self, max: usize) -> Self
Examples found in repository?
examples/agent_with_tools.rs (line 19)
9async fn main() -> helios_engine::Result<()> {
10 // Load configuration from `config.toml`.
11 let config = Config::from_file("config.toml")?;
12
13 // Create an agent named "ToolAgent" and equip it with the `CalculatorTool` and `EchoTool`.
14 // Using the improved syntax to add multiple tools at once!
15 let mut agent = Agent::builder("ToolAgent")
16 .config(config)
17 .system_prompt("You are a helpful assistant with access to tools. Use them when needed.")
18 .tools(vec![Box::new(CalculatorTool), Box::new(EchoTool)])
19 .max_iterations(5)
20 .build()
21 .await?;
22
23 println!(
24 "Available tools: {:?}\n",
25 agent.tool_registry().list_tools()
26 );
27
28 // --- Test the calculator tool ---
29 let response = agent.chat("What is 25 * 4 + 10?").await?;
30 println!("Agent: {}\n", response);
31
32 // --- Test the echo tool ---
33 let response = agent
34 .chat("Can you echo this message: 'Hello from Helios!'")
35 .await?;
36 println!("Agent: {}\n", response);
37
38 Ok(())
39}More examples
examples/serve_agent.rs (line 23)
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/rag_qdrant_comparison.rs (line 36)
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/serve_with_custom_endpoints.rs (line 23)
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 // Define custom endpoints
28 let custom_endpoints = CustomEndpointsConfig {
29 endpoints: vec![
30 CustomEndpoint {
31 method: "GET".to_string(),
32 path: "/api/version".to_string(),
33 response: serde_json::json!({
34 "version": "0.2.8",
35 "service": "Helios Engine",
36 "features": ["agents", "tools", "streaming", "custom_endpoints"]
37 }),
38 status_code: 200,
39 },
40 CustomEndpoint {
41 method: "GET".to_string(),
42 path: "/api/status".to_string(),
43 response: serde_json::json!({
44 "status": "operational",
45 "uptime": "unknown",
46 "model": "agent-based"
47 }),
48 status_code: 200,
49 },
50 CustomEndpoint {
51 method: "POST".to_string(),
52 path: "/api/echo".to_string(),
53 response: serde_json::json!({
54 "message": "Echo endpoint - this returns static data",
55 "note": "For dynamic responses, use the chat completions endpoint"
56 }),
57 status_code: 200,
58 },
59 ],
60 };
61
62 // Start the server with custom endpoints
63 println!("Starting server on http://127.0.0.1:8000");
64 println!("๐ก OpenAI-compatible API endpoints:");
65 println!(" POST /v1/chat/completions");
66 println!(" GET /v1/models");
67 println!("๐ก Custom endpoints:");
68 println!(" GET /api/version");
69 println!(" GET /api/status");
70 println!(" POST /api/echo");
71 println!();
72 println!("Try: curl http://127.0.0.1:8000/api/version");
73
74 helios_engine::serve::start_server_with_agent_and_custom_endpoints(
75 agent,
76 "local-model".to_string(),
77 "127.0.0.1:8000",
78 Some(custom_endpoints),
79 )
80 .await?;
81
82 Ok(())
83}examples/react_agent.rs (line 31)
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/forest_simple_demo.rs (line 27)
9async fn main() -> helios_engine::Result<()> {
10 println!("๐ Forest of Agents - Simple Demo\n");
11
12 let config = Config::from_file("config.toml")?;
13
14 // Create a simpler forest with just 3 agents
15 let mut forest = ForestBuilder::new()
16 .config(config)
17 .agent(
18 "coordinator".to_string(),
19 Agent::builder("coordinator")
20 .system_prompt(
21 "You are a project coordinator. Your ONLY job is to create plans, not execute tasks.\n\
22 When given a task, IMMEDIATELY use the create_plan tool with this format:\n\
23 - objective: the overall goal\n\
24 - tasks: JSON array with structure [{\"id\":\"task_1\",\"description\":\"...\",\"assigned_to\":\"worker1\",\"dependencies\":[]}]\n\n\
25 Keep plans simple with 2-3 tasks max. Do NOT try to complete the task yourself."
26 )
27 .max_iterations(15)
28 )
29 .agent(
30 "worker1".to_string(),
31 Agent::builder("worker1")
32 .system_prompt(
33 "You are a helpful worker. Complete the task assigned to you and use the \
34 update_task_memory tool to save your results. Be brief and direct."
35 )
36 .max_iterations(8)
37 )
38 .agent(
39 "worker2".to_string(),
40 Agent::builder("worker2")
41 .system_prompt(
42 "You are a helpful worker. Complete the task assigned to you and use the \
43 update_task_memory tool to save your results. Be brief and direct."
44 )
45 .max_iterations(8)
46 )
47 .max_iterations(20)
48 .build()
49 .await?;
50
51 println!(" Forest created with 3 agents\n");
52
53 // Simple task
54 let task = "List 3 benefits of exercise. Keep it brief.";
55 println!("๐ Task: {}\n", task);
56
57 let result = forest
58 .execute_collaborative_task(
59 &"coordinator".to_string(),
60 task.to_string(),
61 vec!["worker1".to_string(), "worker2".to_string()],
62 )
63 .await?;
64
65 println!("\n{}\n", "=".repeat(60));
66 println!("โจ RESULT:\n{}\n", result);
67 println!("{}\n", "=".repeat(60));
68
69 // Show task breakdown
70 let context = forest.get_shared_context().await;
71 if let Some(plan) = context.get_plan() {
72 println!("๐ Plan Summary:");
73 let (completed, total) = plan.get_progress();
74 println!(" Completed: {}/{} tasks\n", completed, total);
75
76 for task in plan.tasks_in_order() {
77 let status = match task.status {
78 helios_engine::forest::TaskStatus::Completed => "",
79 helios_engine::forest::TaskStatus::InProgress => "๐",
80 helios_engine::forest::TaskStatus::Pending => "โณ",
81 helios_engine::forest::TaskStatus::Failed => "โ",
82 };
83 println!(" {} [{}] {}", status, task.assigned_to, task.description);
84 }
85 } else {
86 println!("๐ No plan was created (coordinator handled directly)");
87 }
88
89 println!("\n Demo completed!");
90
91 Ok(())
92}Additional examples can be found in:
Sourcepub fn react(self) -> Self
pub fn react(self) -> Self
Enables ReAct mode for the agent.
In ReAct mode, the agent will reason about the task and create a plan before taking actions. This helps the agent think through problems more systematically and make better decisions.
ยงExample
let agent = Agent::builder("MyAgent")
.config(config)
.react()
.build()
.await?;Examples found in repository?
examples/react_agent.rs (line 30)
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}More examples
examples/react_comparison.rs (line 28)
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}Sourcepub fn react_with_prompt(self, prompt: impl Into<String>) -> Self
pub fn react_with_prompt(self, prompt: impl Into<String>) -> Self
Enables ReAct mode with a custom reasoning prompt.
This allows you to customize how the agent reasons about tasks. You can tailor the reasoning process to specific domains or tasks.
ยงArguments
prompt- Custom prompt to guide the agentโs reasoning
ยงExample
let custom_prompt = r#"
As a mathematical problem solver:
1. Identify the mathematical operations needed
2. Break down complex calculations into steps
3. Determine the order of operations
4. Plan which calculator functions to use
"#;
let agent = Agent::builder("MathAgent")
.config(config)
.react_with_prompt(custom_prompt)
.build()
.await?;Examples found in repository?
examples/react_debugging.rs (line 34)
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}More examples
examples/react_custom_prompt.rs (line 34)
9async fn main() -> helios_engine::Result<()> {
10 println!("๐ง Helios Engine - ReAct with Custom Prompts");
11 println!("=============================================\n");
12
13 let config = Config::from_file("config.toml")?;
14
15 // Example 1: Math-focused reasoning prompt
16 println!("โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ");
17 println!("Example 1: Mathematical Problem Solver");
18 println!("โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ\n");
19
20 let math_prompt = r#"As a mathematical problem solver, analyze this systematically:
21
221. IDENTIFY: What mathematical operations are required?
232. DECOMPOSE: Break complex calculations into simple steps
243. ORDER: Determine the correct order of operations (PEMDAS/BODMAS)
254. PLAN: List which calculator functions to use and in what sequence
265. VERIFY: Consider how to check the answer
27
28Provide your mathematical reasoning clearly."#;
29
30 let mut math_agent = Agent::builder("MathExpert")
31 .config(config.clone())
32 .system_prompt("You are a mathematical expert who thinks carefully about calculations.")
33 .tool(Box::new(CalculatorTool))
34 .react_with_prompt(math_prompt)
35 .build()
36 .await?;
37
38 println!("User: Calculate ((15 * 8) + (20 * 3)) / 2\n");
39 let response = math_agent
40 .chat("Calculate ((15 * 8) + (20 * 3)) / 2")
41 .await?;
42 println!("\nAgent: {}\n", response);
43
44 // Example 2: Data analysis reasoning prompt
45 println!("โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ");
46 println!("Example 2: Data Analysis Agent");
47 println!("โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ\n");
48
49 let data_prompt = r#"As a data analyst, approach this task methodically:
50
511. UNDERSTAND: What data or files are we working with?
522. EXTRACT: What information needs to be retrieved?
533. PROCESS: What transformations or calculations are needed?
544. TOOLS: Which tools should I use and in what order?
555. OUTPUT: What format should the final answer take?
56
57Think through the data pipeline step by step."#;
58
59 let mut data_agent = Agent::builder("DataAnalyst")
60 .config(config.clone())
61 .system_prompt("You are a data analyst who carefully plans data processing tasks.")
62 .tools(vec![Box::new(FileReadTool), Box::new(CalculatorTool)])
63 .react_with_prompt(data_prompt)
64 .build()
65 .await?;
66
67 println!("User: If I have numbers 10, 20, 30, 40, 50, what's their average?\n");
68 let response = data_agent
69 .chat("If I have numbers 10, 20, 30, 40, 50, what's their average?")
70 .await?;
71 println!("\nAgent: {}\n", response);
72
73 // Example 3: Task planning reasoning prompt
74 println!("โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ");
75 println!("Example 3: Task Planning Agent");
76 println!("โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ\n");
77
78 let planning_prompt = r#"As a task planning expert, organize this systematically:
79
801. GOAL: What is the end objective?
812. PREREQUISITES: What information do I already have?
823. DEPENDENCIES: What needs to happen before what?
834. RESOURCES: What tools are available to me?
845. STEPS: Create a numbered action plan
856. CONTINGENCY: What could go wrong?
86
87Plan the execution strategy carefully."#;
88
89 let mut planning_agent = Agent::builder("TaskPlanner")
90 .config(config.clone())
91 .system_prompt("You are a strategic planner who breaks down complex tasks.")
92 .tool(Box::new(CalculatorTool))
93 .react_with_prompt(planning_prompt)
94 .build()
95 .await?;
96
97 println!("User: I need to calculate the total cost: 5 items at $12.50 each, plus 8% tax\n");
98 let response = planning_agent
99 .chat("I need to calculate the total cost: 5 items at $12.50 each, plus 8% tax")
100 .await?;
101 println!("\nAgent: {}\n", response);
102
103 // Example 4: Scientific reasoning prompt
104 println!("โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ");
105 println!("Example 4: Scientific Reasoning Agent");
106 println!("โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ\n");
107
108 let scientific_prompt = r#"Apply the scientific method to this problem:
109
1101. OBSERVATION: What is being asked?
1112. HYPOTHESIS: What approach should work?
1123. VARIABLES: What factors are involved?
1134. METHOD: What tools and operations are needed?
1145. PREDICTION: What result do we expect?
1156. VERIFICATION: How can we validate the answer?
116
117Use rigorous scientific thinking."#;
118
119 let mut science_agent = Agent::builder("Scientist")
120 .config(config)
121 .system_prompt("You are a scientist who applies rigorous methodology.")
122 .tool(Box::new(CalculatorTool))
123 .react_with_prompt(scientific_prompt)
124 .build()
125 .await?;
126
127 println!("User: If velocity = 30 m/s and time = 4 seconds, what's the distance?\n");
128 let response = science_agent
129 .chat("If velocity = 30 m/s and time = 4 seconds, what's the distance?")
130 .await?;
131 println!("\nAgent: {}\n", response);
132
133 println!("โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ");
134 println!(" Custom Prompt Demo Complete!");
135 println!("โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ");
136 println!("\nKey Takeaways:");
137 println!(" โข Custom prompts tailor reasoning to specific domains");
138 println!(" โข Different prompts optimize for different task types");
139 println!(" โข Use .react_with_prompt() for domain-specific reasoning");
140 println!(" โข Each agent can have its own reasoning style\n");
141
142 Ok(())
143}Sourcepub async fn build(self) -> Result<Agent>
pub async fn build(self) -> Result<Agent>
Examples found in repository?
examples/custom_tool.rs (line 83)
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
examples/agent_with_tools.rs (line 20)
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 24)
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 26)
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 21)
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 37)
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}Additional examples can be found in:
- examples/serve_with_custom_endpoints.rs
- examples/react_agent.rs
- examples/agent_with_file_tools.rs
- examples/agent_with_memory_db.rs
- examples/serve_simple_endpoints.rs
- examples/react_debugging.rs
- examples/react_comparison.rs
- examples/rag_in_memory.rs
- examples/ultra_simple.rs
- examples/agent_with_rag.rs
- examples/tool_builder_demo.rs
- examples/complete_demo.rs
- examples/react_custom_prompt.rs
Auto Trait Implementationsยง
impl !RefUnwindSafe for AgentBuilder
impl !UnwindSafe for AgentBuilder
impl Freeze for AgentBuilder
impl Send for AgentBuilder
impl Sync for AgentBuilder
impl Unpin for AgentBuilder
impl UnsafeUnpin for AgentBuilder
Blanket Implementationsยง
Sourceยงimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Sourceยงfn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more