Skip to content

Commit e990245

Browse files
authored
fasta2a: be more strict on agent card (#1781)
1 parent f132f4e commit e990245

File tree

3 files changed

+58
-4
lines changed

3 files changed

+58
-4
lines changed

fasta2a/fasta2a/applications.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,16 @@
1212
from starlette.types import ExceptionHandler, Lifespan, Receive, Scope, Send
1313

1414
from .broker import Broker
15-
from .schema import AgentCard, Capabilities, Provider, Skill, a2a_request_ta, a2a_response_ta, agent_card_ta
15+
from .schema import (
16+
AgentCard,
17+
Authentication,
18+
Capabilities,
19+
Provider,
20+
Skill,
21+
a2a_request_ta,
22+
a2a_response_ta,
23+
agent_card_ta,
24+
)
1625
from .storage import Storage
1726
from .task_manager import TaskManager
1827

@@ -82,12 +91,13 @@ async def _agent_card_endpoint(self, request: Request) -> Response:
8291
default_input_modes=self.default_input_modes,
8392
default_output_modes=self.default_output_modes,
8493
capabilities=Capabilities(streaming=False, push_notifications=False, state_transition_history=False),
94+
authentication=Authentication(schemes=[]),
8595
)
8696
if self.description is not None:
8797
agent_card['description'] = self.description
8898
if self.provider is not None:
8999
agent_card['provider'] = self.provider
90-
self._agent_card_json_schema = agent_card_ta.dump_json(agent_card)
100+
self._agent_card_json_schema = agent_card_ta.dump_json(agent_card, by_alias=True)
91101
return Response(content=self._agent_card_json_schema, media_type='application/json')
92102

93103
async def _agent_run_endpoint(self, request: Request) -> Response:

fasta2a/fasta2a/schema.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,7 @@ class AgentCard(TypedDict):
4141
capabilities: Capabilities
4242
"""The capabilities of the agent."""
4343

44-
# TODO(Marcelo): The spec makes authentication required.
45-
authentication: NotRequired[Authentication]
44+
authentication: Authentication
4645
"""The authentication schemes supported by the agent.
4746
4847
Intended to match OpenAPI authentication structure.

tests/fasta2a/test_applications.py

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
from __future__ import annotations as _annotations
2+
3+
from contextlib import asynccontextmanager
4+
5+
import httpx
6+
import pytest
7+
from asgi_lifespan import LifespanManager
8+
from inline_snapshot import snapshot
9+
10+
from ..conftest import try_import
11+
12+
with try_import() as imports_successful:
13+
from fasta2a.applications import FastA2A
14+
from fasta2a.broker import InMemoryBroker
15+
from fasta2a.storage import InMemoryStorage
16+
17+
18+
pytestmark = [pytest.mark.anyio, pytest.mark.skipif(not imports_successful(), reason='fasta2a not installed')]
19+
20+
21+
@asynccontextmanager
22+
async def create_test_client(app: FastA2A):
23+
async with LifespanManager(app=app) as manager:
24+
transport = httpx.ASGITransport(app=manager.app)
25+
async with httpx.AsyncClient(transport=transport, base_url='http://testclient') as client:
26+
yield client
27+
28+
29+
async def test_agent_card():
30+
app = FastA2A(storage=InMemoryStorage(), broker=InMemoryBroker())
31+
async with create_test_client(app) as client:
32+
response = await client.get('/.well-known/agent.json')
33+
assert response.status_code == 200
34+
assert response.json() == snapshot(
35+
{
36+
'name': 'Agent',
37+
'url': 'http://localhost:8000',
38+
'version': '1.0.0',
39+
'skills': [],
40+
'defaultInputModes': ['application/json'],
41+
'defaultOutputModes': ['application/json'],
42+
'capabilities': {'streaming': False, 'pushNotifications': False, 'stateTransitionHistory': False},
43+
'authentication': {'schemes': []},
44+
}
45+
)

0 commit comments

Comments
 (0)