Vapora/crates/vapora-agents/examples/01-simple-agent.rs

83 lines
2.6 KiB
Rust
Raw Permalink Normal View History

2026-01-12 03:34:01 +00:00
//! # Simple Agent Registration Example
//!
//! Demonstrates how to create an agent registry and register a basic agent.
//!
//! ## What This Example Shows
//! - Creating an `AgentRegistry` with capacity
//! - Defining agent metadata (name, role, capabilities, LLM provider)
//! - Registering an agent and retrieving its ID
//! - Querying registered agents
//!
//! ## Run
//! ```bash
//! cargo run --example 01-simple-agent -p vapora-agents
//! ```
//!
//! ## Expected Output
//! ```text
//! === Simple Agent Registration Example ===
//!
//! Creating agent registry with capacity 10...
//! Defined agent: "Developer A" (role: developer)
//! Registering agent with capabilities: [coding, testing]
//! Agent registered successfully
//! Agent ID: <uuid>
//! Agent Status: Ready
//!
//! === Registered Agents ===
//! Total: 1 agents
//! - Developer A (Role: developer, Status: Ready)
//! ```
use vapora_agents::{AgentMetadata, AgentRegistry};
fn main() {
println!("=== Simple Agent Registration Example ===\n");
// Step 1: Create an agent registry with a capacity limit
let registry = AgentRegistry::new(10);
println!("Created agent registry with capacity 10\n");
// Step 2: Define agent metadata
let agent = AgentMetadata::new(
"developer".to_string(), // role
"Developer A".to_string(), // name
"claude".to_string(), // provider (Claude)
"claude-opus-4-5".to_string(), // model
vec!["coding".to_string(), "testing".to_string()], // capabilities
);
println!("Defined agent: \"{}\" (role: {})", agent.name, agent.role);
println!("Capabilities: {:?}\n", agent.capabilities);
// Step 3: Register the agent
let agent_id = registry
.register_agent(agent)
.expect("Failed to register agent");
println!("Agent registered successfully");
println!("Agent ID: {}\n", agent_id);
// Step 4: Query the registry to verify
let all_agents = registry.list_all();
println!("=== Registered Agents ===");
println!("Total: {} agents", all_agents.len());
for agent_info in all_agents {
println!(
"- {} (Role: {}, Status: {:?}, Capabilities: {})",
agent_info.name,
agent_info.role,
agent_info.status,
agent_info.capabilities.join(", ")
);
}
// Step 5: Retrieve specific agent
let retrieved = registry
.get_agent(&agent_id)
.expect("Failed to retrieve agent");
println!(
"\nRetrieved agent: {} (Status: {:?})",
retrieved.name, retrieved.status
);
}