ba8892b0ad
First of the six agents, and the one that gives the A2A facade for the others to interoperate with. A turn exchanges the user's token once per audience, builds one MCP toolset per server with those tokens, runs the model through the Kong AI gateway, and drops the toolsets. Per-turn MCP clients are the point, not an implementation detail: a token that outlives its turn can be replayed after the session ended. Several narrow tokens rather than one broad one, so a prompt injection that talks the agent into the wrong domain is refused at Kong rather than succeeding quietly. a2a-sdk rather than FastA2A, revising the May decision. That decision rested on Agent.to_a2a() being removed in PydanticAI v2 — which has now happened, so the argument no longer separates them. With four other runtimes due to interoperate, the protocol author's implementation is the safer base. httpx2 rather than httpx, which PydanticAI deprecates for OpenAI-compatible providers and drops in v3. Four things about a2a-sdk 1.1 that no documentation gave and that were established against the running library, all recorded where they bite: a2a.types are protobuf, not pydantic; DefaultRequestHandler speaks 0.3 and V2 is needed for 1.0; a client must send A2A-Version: 1.0 or the server assumes 0.3 and answers VERSION_NOT_SUPPORTED on a perfectly valid request; and an executor must enqueue a Task before any status update. Verified: the app builds with no deprecation warnings, serves its Agent Card, and fails a turn cleanly with "no bearer token" rather than answering from the model's own knowledge — which would hide a broken identity chain behind a plausible reply. Seven tests cover the exchange shape (scope not audience, per-audience caching, refusal) and the card. The Keycloak client does not exist yet, so no end-to-end run has happened. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
57 lines
2.0 KiB
Python
57 lines
2.0 KiB
Python
"""The A2A surface: the Agent Card, and how the subject token is read."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from catalogue_agent.a2a_server import _subject_token, build_agent_card
|
|
from catalogue_agent.config import Settings
|
|
|
|
|
|
class _Call:
|
|
def __init__(self, headers: dict[str, str]) -> None:
|
|
self.state = {"headers": headers}
|
|
|
|
|
|
class _Context:
|
|
def __init__(self, headers: dict[str, str] | None) -> None:
|
|
self.call_context = _Call(headers) if headers is not None else None
|
|
|
|
|
|
def _settings() -> Settings:
|
|
return Settings(client_secret="s3cret") # type: ignore[call-arg]
|
|
|
|
|
|
def test_agent_card_exposes_a_decision_shaped_skill() -> None:
|
|
"""Never a generic `query`.
|
|
|
|
An agent that offers "ask me anything about my domain" has become a data
|
|
proxy, and the per-domain scoping the estate relies on stops meaning
|
|
anything.
|
|
"""
|
|
card = build_agent_card(_settings())
|
|
ids = [s.id for s in card.skills]
|
|
assert ids == ["describe_catalog"]
|
|
assert not any(s.id in {"query", "search", "execute"} for s in card.skills)
|
|
|
|
|
|
def test_agent_card_declares_protocol_1_0() -> None:
|
|
"""Without this the SDK assumes 0.3 and refuses 1.0 traffic."""
|
|
iface = build_agent_card(_settings()).supported_interfaces[0]
|
|
assert iface.protocol_version == "1.0"
|
|
assert iface.protocol_binding == "JSONRPC"
|
|
|
|
|
|
def test_bearer_prefix_is_stripped_case_insensitively() -> None:
|
|
assert _subject_token(_Context({"authorization": "Bearer abc"})) == "abc"
|
|
assert _subject_token(_Context({"Authorization": "bearer abc"})) == "abc"
|
|
assert _subject_token(_Context({"authorization": "abc"})) == "abc"
|
|
|
|
|
|
def test_absent_token_yields_none_rather_than_an_empty_string() -> None:
|
|
"""The executor branches on None to fail the task loudly.
|
|
|
|
An empty string would be sent to Keycloak and produce a confusing 400
|
|
instead of a clear "no token on the request".
|
|
"""
|
|
assert _subject_token(_Context({})) is None
|
|
assert _subject_token(_Context(None)) is None
|