use a2a_client::WebA2AClient;
use a2a_rs::domain::{Message, Part, SendCompletion};
#[tokio::main]
async fn main() -> anyhow::Result<()> {
println!("Starting basic A2A client example");
let client = WebA2AClient::builder()
.http_url("http://localhost:8080")
.build();
println!("Created HTTP client for http://localhost:8080");
let message = Message::builder()
.message_id(uuid::Uuid::new_v4().to_string())
.role(a2a_rs::domain::Role::User)
.parts(vec![Part::text(
"Hello! I'd like to submit an expense reimbursement.".to_string(),
)])
.build();
println!("Sending message to agent...");
match client
.transport
.send_task_message(None, &message, None, None, SendCompletion::WhenSettled)
.await
{
Ok(task) => {
println!("✓ Message sent successfully!");
println!(" Task ID: {}", task.id);
println!(" State: {:?}", task.status.state);
println!(" Message count: {}", task.history.len());
println!("Retrieving task to see agent response...");
match client.transport.get_task(&task.id, None).await {
Ok(updated_task) => {
println!("✓ Retrieved task successfully!");
let history = &updated_task.history;
println!(" Conversation has {} messages", history.len());
if let Some(last_msg) = history.last() {
println!(" Last message role: {:?}", last_msg.role);
if let Some(text) = last_msg.parts.first().and_then(|p| p.get_text()) {
println!(" Agent says: {}", text);
}
}
}
Err(e) => {
eprintln!("Failed to retrieve task: {}", e);
}
}
}
Err(e) => {
eprintln!("Failed to send message: {}", e);
return Err(e.into());
}
}
println!("Example completed successfully!");
Ok(())
}