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/basic_chat.rs (line 16)
10async fn main() -> helios_engine::Result<()> {
11 // Load configuration from `config.toml`.
12 let config = Config::from_file("config.toml")?;
13
14 // Create a simple agent named "BasicAgent".
15 let mut agent = Agent::builder("BasicAgent")
16 .config(config)
17 .system_prompt("You are a helpful assistant.")
18 .build()
19 .await?;
20
21 // --- Send a message to the agent ---
22 let response = agent.chat("Hello! How are you?").await?;
23 println!("Agent: {}", response);
24
25 // --- Continue the conversation ---
26 let response = agent.chat("What can you help me with?").await?;
27 println!("Agent: {}", response);
28
29 Ok(())
30}More examples
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}examples/agent_with_tools.rs (line 15)
9async fn main() -> helios_engine::Result<()> {
10 // Load configuration from `config.toml`.
11 let config = Config::from_file("config.toml")?;
12
13 // Create an agent named "ToolAgent" and equip it with the `CalculatorTool` and `EchoTool`.
14 let mut agent = Agent::builder("ToolAgent")
15 .config(config)
16 .system_prompt("You are a helpful assistant with access to tools. Use them when needed.")
17 .tool(Box::new(CalculatorTool))
18 .tool(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/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/serve_with_custom_endpoints.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 // 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}Additional examples can be found in:
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/basic_chat.rs (line 17)
10async fn main() -> helios_engine::Result<()> {
11 // Load configuration from `config.toml`.
12 let config = Config::from_file("config.toml")?;
13
14 // Create a simple agent named "BasicAgent".
15 let mut agent = Agent::builder("BasicAgent")
16 .config(config)
17 .system_prompt("You are a helpful assistant.")
18 .build()
19 .await?;
20
21 // --- Send a message to the agent ---
22 let response = agent.chat("Hello! How are you?").await?;
23 println!("Agent: {}", response);
24
25 // --- Continue the conversation ---
26 let response = agent.chat("What can you help me with?").await?;
27 println!("Agent: {}", response);
28
29 Ok(())
30}More examples
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}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 let mut agent = Agent::builder("ToolAgent")
15 .config(config)
16 .system_prompt("You are a helpful assistant with access to tools. Use them when needed.")
17 .tool(Box::new(CalculatorTool))
18 .tool(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/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/serve_with_custom_endpoints.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 // 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}Additional examples can be found in:
Sourcepub fn tool(self, tool: Box<dyn Tool>) -> Self
pub fn tool(self, tool: Box<dyn Tool>) -> Self
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/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 let mut agent = Agent::builder("ToolAgent")
15 .config(config)
16 .system_prompt("You are a helpful assistant with access to tools. Use them when needed.")
17 .tool(Box::new(CalculatorTool))
18 .tool(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 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/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}Additional examples can be found in:
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 let mut agent = Agent::builder("ToolAgent")
15 .config(config)
16 .system_prompt("You are a helpful assistant with access to tools. Use them when needed.")
17 .tool(Box::new(CalculatorTool))
18 .tool(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/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/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}examples/agent_with_memory_db.rs (line 30)
10async fn main() -> helios_engine::Result<()> {
11 println!("🚀 Helios Engine - Agent with Memory DB Example");
12 println!("================================================\n");
13
14 // Load configuration from `config.toml` or use default.
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 "DataAgent" and equip it with the MemoryDBTool.
21 let mut agent = Agent::builder("DataAgent")
22 .config(config)
23 .system_prompt(
24 "You are a helpful assistant with access to an in-memory database. \
25 You can store and retrieve information using the memory_db tool. \
26 Operations available: set, get, delete, list, clear, exists. \
27 Use this to remember important information across our conversation.",
28 )
29 .tool(Box::new(MemoryDBTool::new()))
30 .max_iterations(10)
31 .build()
32 .await?;
33
34 println!("✓ Agent created with memory database tool\n");
35
36 // --- Example 1: Store user preferences ---
37 println!("Example 1: Storing User Preferences");
38 println!("====================================\n");
39
40 let response = agent
41 .chat("Store my name as 'Alice' and my favorite color as 'blue' in the database")
42 .await?;
43 println!("Agent: {}\n", response);
44
45 // --- Example 2: Retrieve stored data ---
46 println!("\nExample 2: Retrieving Stored Data");
47 println!("==================================\n");
48
49 let response = agent.chat("What's my name and favorite color?").await?;
50 println!("Agent: {}\n", response);
51
52 // --- Example 3: Store calculations ---
53 println!("\nExample 3: Caching Calculations");
54 println!("================================\n");
55
56 let response = agent
57 .chat("Calculate 123 * 456 and store the result in the database with key 'calculation_result'")
58 .await?;
59 println!("Agent: {}\n", response);
60
61 // --- Example 4: List all stored data ---
62 println!("\nExample 4: Listing All Data");
63 println!("===========================\n");
64
65 let response = agent
66 .chat("Show me everything stored in the database")
67 .await?;
68 println!("Agent: {}\n", response);
69
70 // --- Example 5: Check if key exists ---
71 println!("\nExample 5: Checking Key Existence");
72 println!("==================================\n");
73
74 let response = agent
75 .chat("Check if 'name' and 'age' exist in the database")
76 .await?;
77 println!("Agent: {}\n", response);
78
79 // --- Example 6: Delete specific data ---
80 println!("\nExample 6: Deleting Data");
81 println!("========================\n");
82
83 let response = agent
84 .chat("Delete the 'calculation_result' from the database")
85 .await?;
86 println!("Agent: {}\n", response);
87
88 // --- Example 7: Final state ---
89 println!("\nExample 7: Final Database State");
90 println!("================================\n");
91
92 let response = agent
93 .chat("List all remaining items in the database")
94 .await?;
95 println!("Agent: {}\n", response);
96
97 println!("\n✅ Example completed successfully!");
98 println!("\n💡 Key Features Demonstrated:");
99 println!(" • Setting key-value pairs in memory database");
100 println!(" • Retrieving stored values");
101 println!(" • Listing all database contents");
102 println!(" • Checking key existence");
103 println!(" • Deleting specific entries");
104 println!(" • Persistent data across multiple agent interactions");
105 println!("\n📝 Use Cases:");
106 println!(" • Caching expensive computations");
107 println!(" • Storing user preferences during conversation");
108 println!(" • Maintaining context across multiple queries");
109 println!(" • Temporary data storage for complex workflows");
110
111 Ok(())
112}examples/agent_with_rag.rs (line 56)
23async fn main() -> helios_engine::Result<()> {
24 println!("🚀 Helios Engine - Agent with RAG Example");
25 println!("==========================================\n");
26
27 // Check for the required OpenAI API key.
28 let embedding_api_key = std::env::var("OPENAI_API_KEY").unwrap_or_else(|_| {
29 println!("⚠ Warning: OPENAI_API_KEY not set. Using placeholder.");
30 "your-api-key-here".to_string()
31 });
32
33 // Load configuration from `config.toml` or use default.
34 let config = Config::from_file("config.toml").unwrap_or_else(|_| {
35 println!("⚠ No config.toml found, using default configuration");
36 Config::new_default()
37 });
38
39 // Create a new `QdrantRAGTool`.
40 let rag_tool = QdrantRAGTool::new(
41 "http://localhost:6333", // Qdrant URL
42 "helios_knowledge", // Collection name
43 "https://api.openai.com/v1/embeddings", // Embedding API
44 embedding_api_key, // API key
45 );
46
47 // Create an agent named "KnowledgeAgent" and equip it with the RAG tool.
48 let mut agent = Agent::builder("KnowledgeAgent")
49 .config(config)
50 .system_prompt(
51 "You are a helpful assistant with access to a RAG (Retrieval-Augmented Generation) system. \
52 You can store documents and retrieve relevant information to answer questions. \
53 When answering questions, first search for relevant documents, then provide informed answers based on the retrieved context."
54 )
55 .tool(Box::new(rag_tool))
56 .max_iterations(10)
57 .build()
58 .await?;
59
60 println!("✓ Agent created with RAG capabilities\n");
61
62 // --- Example 1: Add knowledge to the database ---
63 println!("Example 1: Adding Documents to Knowledge Base");
64 println!("==============================================\n");
65
66 let response = agent
67 .chat(
68 "Store this information: Rust is a systems programming language that runs blazingly fast, \
69 prevents segfaults, and guarantees thread safety. It was created by Mozilla Research."
70 )
71 .await?;
72 println!("Agent: {}\n", response);
73
74 let response = agent
75 .chat(
76 "Store this: Python is a high-level, interpreted programming language known for its \
77 clear syntax and readability. It was created by Guido van Rossum in 1991.",
78 )
79 .await?;
80 println!("Agent: {}\n", response);
81
82 let response = agent
83 .chat(
84 "Store this: JavaScript is a programming language commonly used for web development. \
85 It allows developers to create interactive web pages and runs in web browsers.",
86 )
87 .await?;
88 println!("Agent: {}\n", response);
89
90 // --- Example 2: Semantic search - ask questions ---
91 println!("\nExample 2: Semantic Search and Q&A");
92 println!("===================================\n");
93
94 let response = agent
95 .chat("What programming language is known for preventing segfaults?")
96 .await?;
97 println!("Agent: {}\n", response);
98
99 let response = agent
100 .chat("Tell me about the programming language created in 1991")
101 .await?;
102 println!("Agent: {}\n", response);
103
104 // --- Example 3: Multi-document retrieval ---
105 println!("\nExample 3: Multi-Document Retrieval");
106 println!("====================================\n");
107
108 let response = agent
109 .chat("Search for information about programming languages and summarize what you find")
110 .await?;
111 println!("Agent: {}\n", response);
112
113 // --- Example 4: Adding documents with metadata ---
114 println!("\nExample 4: Documents with Metadata");
115 println!("===================================\n");
116
117 let response = agent
118 .chat(
119 "Store this with metadata: \
120 The Helios Engine is a Rust framework for building LLM agents. \
121 Metadata: category=framework, language=rust, year=2024",
122 )
123 .await?;
124 println!("Agent: {}\n", response);
125
126 println!("\n✅ Example completed successfully!");
127 println!("\n💡 Key Features Demonstrated:");
128 println!(" • Document embedding with OpenAI embeddings");
129 println!(" • Vector storage in Qdrant database");
130 println!(" • Semantic search with cosine similarity");
131 println!(" • RAG workflow for context-aware answers");
132 println!(" • Metadata support for document organization");
133
134 println!("\n📝 RAG Use Cases:");
135 println!(" • Question answering over custom knowledge bases");
136 println!(" • Document search and retrieval");
137 println!(" • Building chatbots with domain-specific knowledge");
138 println!(" • Information extraction from large document sets");
139
140 println!("\n🔧 Setup Instructions:");
141 println!(" 1. Start Qdrant: docker run -p 6333:6333 qdrant/qdrant");
142 println!(" 2. Set API key: export OPENAI_API_KEY=your-key");
143 println!(" 3. Run example: cargo run --example agent_with_rag");
144
145 Ok(())
146}Additional examples can be found in:
Sourcepub async fn build(self) -> Result<Agent>
pub async fn build(self) -> Result<Agent>
Examples found in repository?
examples/basic_chat.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 a simple agent named "BasicAgent".
15 let mut agent = Agent::builder("BasicAgent")
16 .config(config)
17 .system_prompt("You are a helpful assistant.")
18 .build()
19 .await?;
20
21 // --- Send a message to the agent ---
22 let response = agent.chat("Hello! How are you?").await?;
23 println!("Agent: {}", response);
24
25 // --- Continue the conversation ---
26 let response = agent.chat("What can you help me with?").await?;
27 println!("Agent: {}", response);
28
29 Ok(())
30}More examples
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}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 let mut agent = Agent::builder("ToolAgent")
15 .config(config)
16 .system_prompt("You are a helpful assistant with access to tools. Use them when needed.")
17 .tool(Box::new(CalculatorTool))
18 .tool(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/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/serve_with_custom_endpoints.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 // 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}Additional examples can be found in:
Auto Trait Implementations§
impl Freeze for AgentBuilder
impl !RefUnwindSafe for AgentBuilder
impl Send for AgentBuilder
impl Sync for AgentBuilder
impl Unpin for AgentBuilder
impl !UnwindSafe 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