pub struct AgentClient<S> { /* private fields */ }Expand description
High-level A2A client for interacting with agents
This client wraps a Tower service and provides convenient methods for common A2A operations. The service is generic over any implementation that satisfies the Service trait bounds.
§Example
use tower_a2a::prelude::*;
let url = "https://agent.example.com".parse().unwrap();
let mut client = A2AClientBuilder::new(url)
.with_http()
.build()?;
let message = Message::user("Hello, agent!");
let task = client.send_message(message).await?;
println!("Task created: {}", task.id);Implementations§
Source§impl<S> AgentClient<S>
impl<S> AgentClient<S>
Sourcepub fn new(service: S, config: ClientConfig) -> Self
pub fn new(service: S, config: ClientConfig) -> Self
Create a new agent client
§Arguments
service- The Tower service that handles requestsconfig- Client configuration
Sourcepub fn config(&self) -> &ClientConfig
pub fn config(&self) -> &ClientConfig
Get the client configuration
Sourcepub async fn send_message_streaming(
&mut self,
message: Message,
) -> Result<Task, A2AError>
pub async fn send_message_streaming( &mut self, message: Message, ) -> Result<Task, A2AError>
Send a message with streaming enabled
Note: Streaming is not yet fully implemented
Sourcepub async fn send_message_in_context(
&mut self,
message: Message,
context_id: String,
) -> Result<Task, A2AError>
pub async fn send_message_in_context( &mut self, message: Message, context_id: String, ) -> Result<Task, A2AError>
Send a message in a specific context for multi-turn conversations
§Arguments
message- The message to sendcontext_id- The context ID for grouping related messages
Sourcepub async fn list_tasks(
&mut self,
status: Option<TaskStatus>,
limit: Option<u32>,
) -> Result<Vec<Task>, A2AError>
pub async fn list_tasks( &mut self, status: Option<TaskStatus>, limit: Option<u32>, ) -> Result<Vec<Task>, A2AError>
Sourcepub async fn list_all_tasks(&mut self) -> Result<Vec<Task>, A2AError>
pub async fn list_all_tasks(&mut self) -> Result<Vec<Task>, A2AError>
List all tasks without filtering
Sourcepub async fn list_tasks_by_status(
&mut self,
status: TaskStatus,
) -> Result<Vec<Task>, A2AError>
pub async fn list_tasks_by_status( &mut self, status: TaskStatus, ) -> Result<Vec<Task>, A2AError>
List tasks with a specific status
Sourcepub async fn discover(&mut self) -> Result<AgentCard, A2AError>
pub async fn discover(&mut self) -> Result<AgentCard, A2AError>
Discover agent capabilities by fetching the Agent Card
This retrieves the agent’s metadata from /.well-known/agent-card.json
§Returns
The agent’s capability card
Sourcepub async fn poll_until_complete(
&mut self,
task_id: String,
poll_interval_ms: u64,
max_attempts: usize,
) -> Result<Task, A2AError>
pub async fn poll_until_complete( &mut self, task_id: String, poll_interval_ms: u64, max_attempts: usize, ) -> Result<Task, A2AError>
Poll a task until it reaches a terminal state
This is a convenience method that repeatedly calls get_task until the task is completed, failed, cancelled, or rejected.
§Arguments
task_id- The task ID to pollpoll_interval- How often to poll (in milliseconds)max_attempts- Maximum number of polling attempts (0 = unlimited)
§Returns
The final task state