Continuing with A2A evaluation next up is a2a-sdk (unrelated to previously evaluated a2a-server). This evaluation is largely based on getting the hello world from the a2a-samples project working as per the instruction of a2a-protocol. With additional, integration with other Http2 based non Python clients.
(I) Installation
pip install a2a-sdk
# uvicorn python-dotenv (packages existing)
# For Http2 support
pip install hypercorn
pip install h2==4.2.0 (See Issue 1 at the end & the bug details)
git clone https://github.com/a2aproject/a2a-samples.git -b main --depth 1
(II) Replace uvicorn server with hypercorn (support for Http2)
The a2a-samples make use of the uvicorn python server. However, uvicorn is a Http1.x compliant server and doesn't support Http2. Keep seeing the following messages if client requests from Http2:
"WARNING: Unsupported upgrade request. "
In order to support a wider & more updated category of clients, uvicorn is replaced with a hypercorn which is Http2 compliant.
In order to switch to hypercorn, the following changes are done to _main_.py of helloworld python project:
#import uvicorn
# Use Hypercorn for Http2
import asyncio
from hypercorn.config import Config
from hypercorn.asyncio import serve
....
config = Config()
config.bind="127.0.0.1:8080" # Binds to all interfaces on port 8080
asyncio.run(serve(server.build(), config))
# uvicorn.run(server.build(), host='127.0.0.1', port=8080, log-level='debug')
(III) Run helloworld
python a2a-samples/samples/python/agents/helloworld/__main__.py
(IV) View AgentCard
Open in the browser or via curl:
curl http:///127.0.0.1:8080/.well-known/agent-card.json
Response:
{"capabilities":{"streaming":true},"defaultInputModes":["text"],"defaultOutputModes":["text"],"description":"Just a hello world agent","name":"Hello World Agent","preferredTransport":"JSONRPC","protocolVersion":"0.3.0","skills":[{"description":"just returns hello world","examples":["hi","hello world"],"id":"hello_world","name":"Returns hello world","tags":["hello world"]}],"supportsAuthenticatedExtendedCard":true,"url":"http://127.0.0.1:8080/","version":"1.0.0"}
For the Authorized Extended Agent Card:
curl -H "Authorization: Bearer dummy-token-for-extended-card" --http2 http://127.0.0.1:8080/agent/authenticatedExtendedCard
Response:
{"capabilities":{"streaming":true},"defaultInputModes":["text"],"defaultOutputModes":["text"],"description":"The full-featured hello world agent for authenticated users.","name":"Hello World Agent - Extended Edition","preferredTransport":"JSONRPC","protocolVersion":"0.3.0","skills":[{"description":"just returns hello world","examples":["hi","hello world"],"id":"hello_world","name":"Returns hello world","tags":["hello world"]},{"description":"A more enthusiastic greeting, only for authenticated users.","examples":["super hi","give me a super hello"],"id":"super_hello_world","name":"Returns a SUPER Hello World","tags":["hello world","super","extended"]}],"supportsAuthenticatedExtendedCard":true,"url":"http://127.0.0.1:8080/","version":"1.0.1"}
(V) Send/ Receive message to Agent
curl -H "Content-Type: application/json" http:///127.0.0.1:8080 -d '{"jsonrpc":"2.0","id":"ee22f765-0253-40a0-a29f-c786b090889d","method":"message/send","params":{"message":{"role":"user","parts":[{"text":"hello there!","kind":"text"}],"messageId":"ccaf4715-712e-40c6-82bc-634a7a7136f2","kind":"message"},"configuration":{"blocking":false}}}'
Response:
{"id":"ee22f765-0253-40a0-a29f-c786b090889d","jsonrpc":"2.0","result":{"kind":"message","messageId":"d813fed8-58cd-4337-8295-6282930d4d4e","parts":[{"kind":"text","text":"Hello World"}],"role":"agent"}}
(VI) Send/ Receive via Http2
curl -iv --http2 http://127.0.0.1:8080/.well-known/agent-card.json
&
curl -iv --http2 -H "Content-Type: application/json" http://127.0.0.1:8080 -d '{"jsonrpc":"2.0","id":"ee22f765-0253-40a0-a29f-c786b090889d","method":"message/send","params":{"message":{"role":"user","parts":[{"text":"dragons and wizards","kind":"text"}],"messageId":"ccaf4715-712e-40c6-82bc-634a7a7136f2","kind":"message"},"configuration":{"blocking":false}}}'
(The responses are the same as shown above)
(VII) Send/ Receive from Java client
TBD
(VIII) Issues
Issue 1: Compatibility issue with hypercorn (ver=0.17.3) & latest h2 (ver=4.3.0)
Ran in to the issue in the mentioned here:
| File "/home/algo/Tools/venv/langvang/lib/python3.13/site-packages/hypercorn/protocol/h2.py", line 138, in initiate
| event = h2.events.RequestReceived()
| TypeError: RequestReceived.__init__() missing 1 required keyword-only argument: 'stream_id'
Issue was resolved by downgrading to h2 (ver=4.2.0).
No comments:
Post a Comment