enki-runtime 0.1.4

A Rust-based agent mesh framework for building local and distributed AI agent systems
Documentation
//! TOML-based Agent Configuration Example
//!
//! This example demonstrates how to load agents from a TOML configuration file
//! instead of defining them programmatically.
//!
//! # Prerequisites
//!
//! 1. Install Ollama from https://ollama.ai
//! 2. Pull the gemma3 model: `ollama pull gemma3:latest`
//! 3. Ensure Ollama is running (default: http://127.0.0.1:11434)
//!
//! # Running
//!
//! ```bash
//! cargo run --example toml_agents
//! ```

use enki_runtime::config::MeshConfig;
use enki_runtime::core::agent::AgentContext;
use enki_runtime::core::error::Result;
use enki_runtime::core::mesh::Mesh;
use enki_runtime::llm::LlmAgent;
use enki_runtime::local::LocalMesh;
use enki_runtime::LlmAgentFromConfig; // Extension trait for from_config
use std::time::Duration;

#[tokio::main]
async fn main() -> Result<()> {
    println!("=== Enki Runtime - TOML Agent Configuration Example ===\n");

    // 1. Load configuration from TOML file
    let config_path = concat!(env!("CARGO_MANIFEST_DIR"), "/examples/agents.toml");
    println!("Loading configuration from: {}\n", config_path);

    let mesh_config = MeshConfig::from_file(config_path)?;
    println!("Mesh name: {}", mesh_config.name);
    println!("Number of agents: {}\n", mesh_config.agents.len());

    // 2. Create the LocalMesh
    let mesh = LocalMesh::new(&mesh_config.name);

    // 3. Create agents from configuration
    for agent_config in &mesh_config.agents {
        println!("Creating agent: {}", agent_config.name);
        println!("  Model: {}", agent_config.model);
        println!("  Temperature: {:?}", agent_config.temperature);
        println!("  Max tokens: {:?}", agent_config.max_tokens);

        let agent = LlmAgent::from_config(agent_config.clone())?;
        mesh.add_agent(Box::new(agent)).await?;
    }

    println!("\n✓ All agents created successfully from TOML configuration\n");

    // 4. Test one of the agents with a simple query
    println!("Testing the researcher agent with a query...\n");

    // Get a reference to test the first agent
    if let Some(researcher_config) = mesh_config.get_agent("researcher") {
        let mut test_agent = LlmAgent::from_config(researcher_config.clone())?;
        let mut ctx = AgentContext::new(mesh_config.name.clone(), None);

        let response = test_agent
            .send_message_and_get_response(
                "What are the main benefits of using Rust for systems programming? Keep it brief.",
                &mut ctx,
            )
            .await?;

        println!("========================================");
        println!("         RESEARCHER RESPONSE");
        println!("========================================\n");
        println!("{}", response);
        println!("\n========================================\n");
    }

    // 5. Demonstrate mesh start/stop (agents are already added)
    println!("Starting mesh with all configured agents...");
    mesh.start().await?;

    // Let it run briefly
    tokio::time::sleep(Duration::from_millis(500)).await;

    // Stop the mesh
    mesh.stop().await?;
    println!("Mesh stopped.\n");

    println!("=== Example completed successfully ===");
    Ok(())
}