-
Notifications
You must be signed in to change notification settings - Fork 162
feat: Adding stand-alone support for RESTful API serving #297
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
Open
pstephengoogle
wants to merge
16
commits into
restful
Choose a base branch
from
updates
base: restful
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
03a0fbe
feat: [WIP] Add dedicated RESTful handler
pstephengoogle 661db10
Address gemini comments
pstephengoogle f7bbfc4
add to allowlist
pstephengoogle 0274112
fix: Send push notifications for message/send (#298)
kthota-g 2126828
fix: Resolve dependency issue with sql stores (#303)
kthota-g e781ced
feat: add `metadata` property to `RequestContext` (#302)
fernando-torres-blip-ai 6412c75
fix: Improve error handling in task creation (#294)
pankaj-bind 3776721
test: improve test coverage (#290)
ognis1205 4e02c19
chore(main): release 0.2.12 (#288)
release-please[bot] dc95e2a
chore: Move `docker/postgres/init.sql` to `tests/` (#304)
holtskinner e5d99ee
feat: Support for Database based Push Config Store (#299)
kthota-g b94b8f5
fix: Handle readtimeout errors. (#305)
kthota-g 2482059
Formatting
holtskinner c4a324d
fix: Add validation for empty artifact lists in `completed_task` (#308)
pankaj-bind ecbbb7e
ci: Add ruff format checking (#309)
holtskinner 45b148e
Merge branch 'main' of https://github.com/google-a2a/a2a-python into …
holtskinner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
"""A2A REST Applications.""" | ||
|
||
from a2a.server.apps.rest.fastapi_app import A2ARESTFastAPIApplication | ||
from a2a.server.apps.rest.rest_app import RESTApplication | ||
|
||
|
||
__all__ = [ | ||
'A2ARESTFastAPIApplication', | ||
'RESTApplication', | ||
] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,81 @@ | ||||||
import logging | ||||||
|
||||||
from typing import Any | ||||||
|
||||||
from fastapi import APIRouter, FastAPI, Request, Response | ||||||
|
||||||
from a2a.server.apps.jsonrpc.jsonrpc_app import ( | ||||||
CallContextBuilder, | ||||||
) | ||||||
from a2a.server.apps.rest.rest_app import ( | ||||||
RESTApplication, | ||||||
) | ||||||
from a2a.server.request_handlers.request_handler import RequestHandler | ||||||
from a2a.types import AgentCard | ||||||
|
||||||
|
||||||
logger = logging.getLogger(__name__) | ||||||
|
||||||
|
||||||
class A2ARESTFastAPIApplication: | ||||||
"""A FastAPI application implementing the A2A protocol server REST endpoints. | ||||||
|
||||||
Handles incoming REST requests, routes them to the appropriate | ||||||
handler methods, and manages response generation including Server-Sent Events | ||||||
(SSE). | ||||||
""" | ||||||
|
||||||
def __init__( | ||||||
self, | ||||||
agent_card: AgentCard, | ||||||
http_handler: RequestHandler, | ||||||
context_builder: CallContextBuilder | None = None, | ||||||
): | ||||||
"""Initializes the A2ARESTFastAPIApplication. | ||||||
|
||||||
Args: | ||||||
agent_card: The AgentCard describing the agent's capabilities. | ||||||
http_handler: The handler instance responsible for processing A2A | ||||||
requests via http. | ||||||
extended_agent_card: An optional, distinct AgentCard to be served | ||||||
at the authenticated extended card endpoint. | ||||||
context_builder: The CallContextBuilder used to construct the | ||||||
ServerCallContext passed to the http_handler. If None, no | ||||||
ServerCallContext is passed. | ||||||
""" | ||||||
self._handler = RESTApplication( | ||||||
agent_card=agent_card, | ||||||
http_handler=http_handler, | ||||||
context_builder=context_builder, | ||||||
) | ||||||
|
||||||
def build( | ||||||
self, | ||||||
agent_card_url: str = '/.well-known/agent.json', | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Also add import: from a2a.utils.constants import AGENT_CARD_WELL_KNOWN_PATH |
||||||
rpc_url: str = '', | ||||||
**kwargs: Any, | ||||||
) -> FastAPI: | ||||||
"""Builds and returns the FastAPI application instance. | ||||||
|
||||||
Args: | ||||||
agent_card_url: The URL for the agent card endpoint. | ||||||
rpc_url: The URL for the A2A JSON-RPC endpoint. | ||||||
extended_agent_card_url: The URL for the authenticated extended agent card endpoint. | ||||||
**kwargs: Additional keyword arguments to pass to the FastAPI constructor. | ||||||
|
||||||
Returns: | ||||||
A configured FastAPI application instance. | ||||||
""" | ||||||
app = FastAPI(**kwargs) | ||||||
router = APIRouter() | ||||||
for route, callback in self._handler.routes().items(): | ||||||
router.add_api_route( | ||||||
f'{rpc_url}{route[0]}', callback, methods=[route[1]] | ||||||
) | ||||||
|
||||||
@router.get(f'{rpc_url}{agent_card_url}') | ||||||
async def get_agent_card(request: Request) -> Response: | ||||||
return await self._handler._handle_get_agent_card(request) | ||||||
|
||||||
app.include_router(router) | ||||||
return app |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
nit: this param should be called request_handler, right? As it is the base request handler, there's nothing related to HTTP.