use ds_api::{AgentEvent, DeepseekAgent, tool};
use futures::StreamExt;
use serde_json::json;
struct Echo;
#[tool]
impl Tool for Echo {
async fn echo(&self, input: String) -> Value {
json!({ "echo": input })
}
}
#[tokio::main]
async fn main() {
let token = std::env::var("DEEPSEEK_API_KEY").expect("DEEPSEEK_API_KEY must be set");
let agent = DeepseekAgent::new(&token).add_tool(Echo);
let mut stream = agent.chat("Please echo: hello");
while let Some(event) = stream.next().await {
match event {
Err(e) => {
eprintln!("Error: {}", e);
break;
}
Ok(AgentEvent::Token(text)) => {
println!("Assistant: {}", text);
}
Ok(AgentEvent::ReasoningToken(text)) => {
println!("[reasoning] {}", text);
}
Ok(AgentEvent::ToolCall(c)) => {
if c.delta.is_empty() { println!("[tool call start] {} (id={})", c.name, c.id); }
else { println!("[tool call args] {}: {}", c.id, c.delta); }
}
Ok(AgentEvent::ToolResult(res)) => {
println!("[tool result] {} -> {}", res.name, res.result);
}
}
}
}