Skip to content

Commit af76625

Browse files
committed
Update app constructor signatures
Adds optional card_modifier and extended_card_modifier params to A2AFastAPIApplication and A2AStarletteApplication constructors.
1 parent b5b3401 commit af76625

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import logging
22

3+
from collections.abc import Callable
34
from typing import TYPE_CHECKING, Any
45

56

@@ -21,6 +22,7 @@
2122
CallContextBuilder,
2223
JSONRPCApplication,
2324
)
25+
from a2a.server.context import ServerCallContext
2426
from a2a.server.request_handlers.jsonrpc_handler import RequestHandler
2527
from a2a.types import A2ARequest, AgentCard
2628
from a2a.utils.constants import (
@@ -64,12 +66,17 @@ class A2AFastAPIApplication(JSONRPCApplication):
6466
(SSE).
6567
"""
6668

67-
def __init__(
69+
def __init__( # noqa: PLR0913
6870
self,
6971
agent_card: AgentCard,
7072
http_handler: RequestHandler,
7173
extended_agent_card: AgentCard | None = None,
7274
context_builder: CallContextBuilder | None = None,
75+
card_modifier: Callable[[AgentCard], AgentCard] | None = None,
76+
extended_card_modifier: Callable[
77+
[AgentCard, ServerCallContext], AgentCard
78+
]
79+
| None = None,
7380
) -> None:
7481
"""Initializes the A2AFastAPIApplication.
7582
@@ -82,6 +89,11 @@ def __init__(
8289
context_builder: The CallContextBuilder used to construct the
8390
ServerCallContext passed to the http_handler. If None, no
8491
ServerCallContext is passed.
92+
card_modifier: An optional callback to dynamically modify the public
93+
agent card before it is served.
94+
extended_card_modifier: An optional callback to dynamically modify
95+
the extended agent card before it is served. It receives the
96+
call context.
8597
"""
8698
if not _package_fastapi_installed:
8799
raise ImportError(
@@ -94,6 +106,8 @@ def __init__(
94106
http_handler=http_handler,
95107
extended_agent_card=extended_agent_card,
96108
context_builder=context_builder,
109+
card_modifier=card_modifier,
110+
extended_card_modifier=extended_card_modifier,
97111
)
98112

99113
def add_routes_to_app(

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import logging
22

3+
from collections.abc import Callable
34
from typing import TYPE_CHECKING, Any
45

56

@@ -25,6 +26,7 @@
2526
CallContextBuilder,
2627
JSONRPCApplication,
2728
)
29+
from a2a.server.context import ServerCallContext
2830
from a2a.server.request_handlers.jsonrpc_handler import RequestHandler
2931
from a2a.types import AgentCard
3032
from a2a.utils.constants import (
@@ -46,12 +48,17 @@ class A2AStarletteApplication(JSONRPCApplication):
4648
(SSE).
4749
"""
4850

49-
def __init__(
51+
def __init__( # noqa: PLR0913
5052
self,
5153
agent_card: AgentCard,
5254
http_handler: RequestHandler,
5355
extended_agent_card: AgentCard | None = None,
5456
context_builder: CallContextBuilder | None = None,
57+
card_modifier: Callable[[AgentCard], AgentCard] | None = None,
58+
extended_card_modifier: Callable[
59+
[AgentCard, ServerCallContext], AgentCard
60+
]
61+
| None = None,
5562
) -> None:
5663
"""Initializes the A2AStarletteApplication.
5764
@@ -64,6 +71,11 @@ def __init__(
6471
context_builder: The CallContextBuilder used to construct the
6572
ServerCallContext passed to the http_handler. If None, no
6673
ServerCallContext is passed.
74+
card_modifier: An optional callback to dynamically modify the public
75+
agent card before it is served.
76+
extended_card_modifier: An optional callback to dynamically modify
77+
the extended agent card before it is served. It receives the
78+
call context.
6779
"""
6880
if not _package_starlette_installed:
6981
raise ImportError(
@@ -76,6 +88,8 @@ def __init__(
7688
http_handler=http_handler,
7789
extended_agent_card=extended_agent_card,
7890
context_builder=context_builder,
91+
card_modifier=card_modifier,
92+
extended_card_modifier=extended_card_modifier,
7993
)
8094

8195
def routes(

0 commit comments

Comments
 (0)