serve_agent/
serve_agent.rs

1//! Example: Serving an agent via HTTP API
2//!
3//! This example demonstrates how to serve an agent using the Helios Engine serve feature.
4//! The agent will be accessible via OpenAI-compatible API endpoints.
5
6use helios_engine::{Agent, CalculatorTool, Config};
7
8#[tokio::main]
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}