Agent to Agent Protocol Python SDK - Supporting Python 3.8-3.13
Install using pip:
pip install pya2a- Implements Agent to Agent Protocol client and server
- Supports sending, retrieving, and canceling tasks
- Supports notification configuration
- Supports streaming responses
- Compatible with Python 3.8-3.13
import asyncio
from a2a.client import A2AClient
from a2a.types import Message, TextPart
async def main():
client = A2AClient(url="http://example.com/agent")
# Create task
task_response = await client.send_task({
"id": "task-123",
"message": Message(
role="user",
parts=[TextPart(text="Hello, this is a test")]
)
})
print(f"Task created successfully: {task_response.result.id}")
# Get task
task = await client.get_task({"id": "task-123"})
print(f"Task status: {task.result.status.state}")
if __name__ == "__main__":
asyncio.run(main())import asyncio
from a2a.client import A2AClient
from a2a.types import Message, TextPart
async def main():
client = A2AClient(url="http://example.com/agent")
# Send streaming task request
async for response in client.send_task_streaming({
"id": "task-123",
"message": Message(
role="user",
parts=[TextPart(text="Please generate a long text")]
)
}):
if response.result:
print(response.result)
if __name__ == "__main__":
asyncio.run(main())- Clone the repository:
git clone https://github.com/your-username/a2a.git
cd a2a- Install Poetry (if not already installed):
curl -sSL https://install.python-poetry.org | python3 -- Install dependencies:
poetry install- Activate the virtual environment:
poetry shellRun tests using pytest:
poetry run pytestThis project supports testing on Python 3.8-3.13. There are several ways to run tests across multiple Python versions:
First, install tox and the tox-poetry plugin:
pip install tox tox-poetryThen run the tests:
toxThis will run tests on all Python versions configured in tox.ini.
We provide a script to automatically run tests on multiple Python versions:
./scripts/run_tests_multi_python.shThis script requires pyenv to be installed with the appropriate Python versions.
When you push code to the repository, GitHub Actions will automatically run tests on multiple Python versions. You can view the results in the Actions tab of the GitHub repository.
Pull Requests are welcome! Please ensure before submitting:
- Update tests to reflect your changes
- Update documentation
- Your code passes all tests
- Format code with Black
- Lint code with Ruff
The initial code for this SDK was derived from the common parts of the Google A2A project samples.
MIT