Skip to content

Commit 734d062

Browse files
refactor(server)!: migrate from Application wrappers to Starlette route-based endpoints for jsonrpc (#873)
# Description This PR refactors the jsonrpc server implementation to expose Starlette Route components directly (via AgentCardRoutes, JsonRpcRoutes) instead of requiring full FastAPI or Starlette application wrappers. Ref #797 🦕 --------- Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
1 parent 2b7108e commit 734d062

30 files changed

Lines changed: 547 additions & 1179 deletions

samples/hello_world_agent.py

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@
1111
from a2a.compat.v0_3.grpc_handler import CompatGrpcHandler
1212
from a2a.server.agent_execution.agent_executor import AgentExecutor
1313
from a2a.server.agent_execution.context import RequestContext
14-
from a2a.server.apps import A2AFastAPIApplication, A2ARESTFastAPIApplication
14+
from a2a.server.apps import A2ARESTFastAPIApplication
1515
from a2a.server.events.event_queue import EventQueue
1616
from a2a.server.request_handlers import GrpcHandler
1717
from a2a.server.request_handlers.default_request_handler import (
1818
DefaultRequestHandler,
1919
)
20+
from a2a.server.routes import create_agent_card_routes, create_jsonrpc_routes
2021
from a2a.server.tasks.inmemory_task_store import InMemoryTaskStore
2122
from a2a.server.tasks.task_updater import TaskUpdater
2223
from a2a.types import (
@@ -197,14 +198,17 @@ async def serve(
197198
)
198199
rest_app = rest_app_builder.build()
199200

200-
jsonrpc_app_builder = A2AFastAPIApplication(
201+
jsonrpc_routes = create_jsonrpc_routes(
202+
agent_card=agent_card,
203+
request_handler=request_handler,
204+
rpc_url='/a2a/jsonrpc/',
205+
)
206+
agent_card_routes = create_agent_card_routes(
201207
agent_card=agent_card,
202-
http_handler=request_handler,
203-
enable_v0_3_compat=True,
204208
)
205-
206209
app = FastAPI()
207-
jsonrpc_app_builder.add_routes_to_app(app, rpc_url='/a2a/jsonrpc/')
210+
app.routes.extend(jsonrpc_routes)
211+
app.routes.extend(agent_card_routes)
208212
app.mount('/a2a/rest', rest_app)
209213

210214
grpc_server = grpc.aio.server()

src/a2a/compat/v0_3/jsonrpc_adapter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
if TYPE_CHECKING:
1111
from starlette.requests import Request
1212

13-
from a2a.server.apps.jsonrpc.jsonrpc_app import CallContextBuilder
1413
from a2a.server.request_handlers.request_handler import RequestHandler
14+
from a2a.server.routes import CallContextBuilder
1515
from a2a.types.a2a_pb2 import AgentCard
1616

1717
_package_starlette_installed = True

src/a2a/compat/v0_3/rest_adapter.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,9 @@
3333

3434
from a2a.compat.v0_3 import conversions
3535
from a2a.compat.v0_3.rest_handler import REST03Handler
36-
from a2a.server.apps.jsonrpc.jsonrpc_app import (
37-
CallContextBuilder,
38-
DefaultCallContextBuilder,
39-
)
4036
from a2a.server.apps.rest.rest_adapter import RESTAdapterInterface
4137
from a2a.server.context import ServerCallContext
38+
from a2a.server.routes import CallContextBuilder, DefaultCallContextBuilder
4239
from a2a.utils.error_handlers import (
4340
rest_error_handler,
4441
rest_stream_error_handler,

src/a2a/server/apps/__init__.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,8 @@
11
"""HTTP application components for the A2A server."""
22

3-
from a2a.server.apps.jsonrpc import (
4-
A2AFastAPIApplication,
5-
A2AStarletteApplication,
6-
CallContextBuilder,
7-
JSONRPCApplication,
8-
)
93
from a2a.server.apps.rest import A2ARESTFastAPIApplication
104

115

126
__all__ = [
13-
'A2AFastAPIApplication',
147
'A2ARESTFastAPIApplication',
15-
'A2AStarletteApplication',
16-
'CallContextBuilder',
17-
'JSONRPCApplication',
188
]

src/a2a/server/apps/jsonrpc/__init__.py

Lines changed: 0 additions & 20 deletions
This file was deleted.

src/a2a/server/apps/jsonrpc/fastapi_app.py

Lines changed: 0 additions & 148 deletions
This file was deleted.

0 commit comments

Comments
 (0)