-
Notifications
You must be signed in to change notification settings - Fork 80
feat!: Add FastAPI JSONRPC Application #104
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There's now a backwards-incompatible change:
==================================== ERRORS ====================================
______________ ERROR collecting tests/server/test_integration.py _______________
ImportError while importing test module '/home/runner/work/a2a-python/a2a-python/tests/server/test_integration.py'.
Hint: make sure your test modules/packages have valid Python names.
Traceback:
/opt/hostedtoolcache/Python/3.10.17/x64/lib/python3.10/importlib/__init__.py:1[26](https://github.com/google-a2a/a2a-python/actions/runs/15398882285/job/43326395575#step:7:27): in import_module
return _bootstrap._gcd_import(name[level:], package, level)
tests/server/test_integration.py:10: in <module>
from a2a.server.apps.starlette_app import A2AStarletteApplication
src/a2a/server/apps/__init__.py:3: in <module>
from a2a.server.apps.starlette_app import A2AStarletteApplication
E ModuleNotFoundError: No module named 'a2a.server.apps.starlette_app'
================================ tests coverage ================================
Can you update the tests to fix this import error and any further usage of a2a.server.apps.starlette_app
in the docs/other examples?
Fixed in 54747f8:
Will update docs/examples after merge, if needed :) |
Seems like the tests are still failing |
@holtskinner Oh right, my bad! The updates for the extended agent card didn't get merged correctly. |
Description
Summary
This PR introduces a
A2AFastAPIApplication
class that enables serving A2A endpoints using a FastAPI application, while preserving compatibility with the existing JSONRPC Starlette-based architecture.Motivation
While the SDK currently provides a Starlette-based server app for A2A agent communication using JSONRPC, many production Python APIs are built with FastAPI due to its support for performance, extensibility, automatic OpenAPI schema generation, and strong async capabilities. Providing native FastAPI support enables seamless integration into such environments without requiring users to manually wrap the existing Starlette app.
This addition does not introduce any breaking changes. FastAPI is treated as an optional integration, and the core A2A logic continues to rely on shared base classes and request handlers.
Implementation Details
Introduced
JSONRPCApplication
, an abstract base class that encapsulates the shared request-handling logic for both Starlette and FastAPI JSONRPC applications. This isolates the common behavior, with the only required customization being thebuild(...)
method used to register routes and return the appropriate application instance.Added
A2AFastAPIApplication
, a concrete implementation ofJSONRPCApplication
that constructs a FastAPI app with the appropriate routes:POST /
(or custom RPC endpoint) for handling A2A JSON-RPC messages.GET /.well-known/agent.json
(or custom) for serving the agent card.All request processing is shared via
_handle_requests
and_handle_get_agent_card
.SSE streaming support is preserved for
SendStreamingMessageRequest
andTaskResubscriptionRequest
.Added
fastapi
to the dependencies inpyproject.toml
.Usage Example
Hello World Example (
examples/helloword/
)Change
A2AStarletteApplication
toA2AFastAPIApplication
Start the server
uv run .
CONTRIBUTING
Guide.nox -s format
from the repository root to format)Continues #26
Fixes #21 🦕