AgentBuilder

Struct AgentBuilder 

Source
pub struct AgentBuilder { /* private fields */ }

Implementations§

Source§

impl AgentBuilder

Source

pub fn new(name: impl Into<String>) -> Self

Source

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
Hide additional 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}
Source

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
Hide additional 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}
Source

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
Hide additional 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}
Source

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}
Source

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

pub async fn 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
Hide additional 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}

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more