client.py
"""
Basic A2A Client
================
Sends a message to the local A2A server and prints the JSON response.
"""
from typing import Any
from uuid import uuid4
import httpx
from a2a.client import A2AClient
from a2a.types import (
MessageSendParams,
SendMessageRequest,
SendStreamingMessageRequest, # noqa: F401
)
# ---------------------------------------------------------------------------
# Create Client Request
# ---------------------------------------------------------------------------
async def main() -> None:
async with httpx.AsyncClient() as httpx_client:
client = await A2AClient.get_client_from_agent_card_url(
httpx_client, "http://localhost:9999"
)
send_message_payload: dict[str, Any] = {
"message": {
"role": "user",
"parts": [
{
"type": "text",
"text": "Hello! What can you tell me about the weather in Tokyo?",
}
],
"messageId": uuid4().hex,
},
}
request = SendMessageRequest(params=MessageSendParams(**send_message_payload))
response = await client.send_message(request)
print(response.model_dump(mode="json", exclude_none=True))
# streaming_request = SendStreamingMessageRequest(
# params=MessageSendParams(**send_message_payload)
# )
# stream_response = client.send_message_streaming(streaming_request)
# async for chunk in stream_response:
# print(chunk.model_dump(mode='json', exclude_none=True))
# ---------------------------------------------------------------------------
# Run Client
# ---------------------------------------------------------------------------
if __name__ == "__main__":
import asyncio
asyncio.run(main())
Run the Example
1
Set up your virtual environment
uv venv --python 3.12
source .venv/bin/activate
uv venv --python 3.12
.venv\Scripts\activate
2
Install dependencies
uv pip install -U agno a2a-sdk httpx openai uvicorn
3
Export your API keys
export OPENAI_API_KEY="your_openai_api_key_here"
$Env:OPENAI_API_KEY="your_openai_api_key_here"
4
Clone Agno
Clone the repository and run the remaining commands from its root:
git clone https://github.com/agno-agi/agno.git
cd agno
5
Start the A2A server
In another terminal, start the Basic A2A Server on port 9999:
python cookbook/05_agent_os/interfaces/a2a/basic_agent/__main__.py
6
Run the example
Run the example from the repository root:
python cookbook/05_agent_os/interfaces/a2a/basic_agent/client.py