-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug_agent.rs
More file actions
79 lines (66 loc) · 3.73 KB
/
Copy pathdebug_agent.rs
File metadata and controls
79 lines (66 loc) · 3.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//! Debug example showing exact prompts and responses.
//!
//! Run with:
//! GROQ_API_KEY=your_key cargo run --example debug_agent
use dragen::{Agent, AgentConfig};
use littrs::{tool, PyValue};
/// Add two numbers together.
///
/// Args:
/// a: First number
/// b: Second number
#[tool]
fn add(a: i64, b: i64) -> i64 {
a + b
}
/// Get information about a person.
///
/// Args:
/// name: The person's name
#[tool]
fn get_person_info(name: String) -> PyValue {
PyValue::Dict(vec![
(PyValue::Str("name".to_string()), PyValue::Str(name)),
(PyValue::Str("age".to_string()), PyValue::Int(30)),
])
}
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let config = AgentConfig::new("llama-3.3-70b-versatile")
.max_iterations(3);
let mut agent = Agent::new(config);
agent.register(add::Tool);
agent.register(get_person_info::Tool);
let task = "Calculate 5 + 3 and look up Alice's age.";
println!("╔══════════════════════════════════════════════════════════════╗");
println!("║ SYSTEM PROMPT ║");
println!("╚══════════════════════════════════════════════════════════════╝\n");
// The system prompt is built automatically from the template
// For this debug example, we'll show what the first message looks like after agent.run() starts
println!("(System prompt will be shown in conversation log below)");
println!("\n╔══════════════════════════════════════════════════════════════╗");
println!("║ USER TASK ║");
println!("╚══════════════════════════════════════════════════════════════╝\n");
println!("{}\n", task);
// Run the agent
match agent.run::<String>(task).await {
Ok(result) => {
println!("\n╔══════════════════════════════════════════════════════════════╗");
println!("║ CONVERSATION LOG ║");
println!("╚══════════════════════════════════════════════════════════════╝\n");
for (i, msg) in agent.messages().iter().enumerate() {
let role = format!("{:?}", msg.role).to_uppercase();
println!("--- [{}] {} ---", i, role);
println!("{}\n", msg.content);
}
println!("╔══════════════════════════════════════════════════════════════╗");
println!("║ FINAL ANSWER ║");
println!("╚══════════════════════════════════════════════════════════════╝\n");
println!("{}", result);
}
Err(e) => {
eprintln!("Agent error: {}", e);
}
}
Ok(())
}