The agent that grows with you
Python aiai-agentai-agentsanthropicchatgptclaudeclaude-codecodexhermeshermes-agentllmnous-researchopenai
fix(a2a): bind and advertise IPv6 hosts such as ::1
John Paul Soliva9f908ca3ddfd
diff --git a/plugins/platforms/a2a/adapter.py b/plugins/platforms/a2a/adapter.pyindex a4dcb9a19a5..0d295f9cfdb 100644--- a/plugins/platforms/a2a/adapter.py+++ b/plugins/platforms/a2a/adapter.py@@ -121,6 +121,15 @@ def _profile_home(profile: str) -> Optional[str]:return None+class _ThreadingHTTPServerV6(ThreadingHTTPServer):+ address_family = socket.AF_INET6+++def _http_server_class(host: str) -> type:+ """``ThreadingHTTPServer`` is AF_INET only, so an IPv6 bind (``::1``, ``::``) needs the v6 family."""+ return _ThreadingHTTPServerV6 if ":" in host else ThreadingHTTPServer++def _daemon_thread(target, name: str) -> threading.Thread:t = threading.Thread(target=target, name=name, daemon=True)t.start()@@ -322,12 +331,8 @@ class A2AAdapter(BasePlatformAdapter):async def connect(self, **_kwargs) -> bool:# Capture the gateway loop so the HTTP thread can marshal events via run_coroutine_threadsafe.self._loop = asyncio.get_running_loop()- # A2A_HOST=:: wants one dual-stack (v4+v6) socket. The stdlib- # ThreadingHTTPServer is AF_INET-pinned and cannot bind "::" at all,- # so swap in the AF_INET6/V6ONLY=0 subclass for that case only.- _server_cls = _DualStackThreadingHTTPServer if str(self.host) == "::" else ThreadingHTTPServertry:- self._httpd = _server_cls((self.host, self.port), A2ARequestHandler)+ self._httpd = _http_server_class(self.host)((self.host, self.port), A2ARequestHandler)except OSError as e:logger.error("A2A: could not bind %s:%s — %s", self.host, self.port, e)self._set_fatal_error("bind_failed", f"A2A bind failed: {e}", retryable=True)@@ -435,7 +440,8 @@ class A2AAdapter(BasePlatformAdapter):return agentsdef _base_url(self, public_url: Optional[str]) -> str:- return (public_url or "").strip() or f"http://{self.host}:{self.port}/"+ host = f"[{self.host}]" if ":" in self.host else self.host # IPv6 literal+ return (public_url or "").strip() or f"http://{host}:{self.port}/"def _served_agent_summary(self, public_url: Optional[str] = None) -> list[dict]:base = self._base_url(public_url)diff --git a/tests/plugins/test_a2a_plugin.py b/tests/plugins/test_a2a_plugin.pyindex 41292b8b412..fadcb91fae7 100644--- a/tests/plugins/test_a2a_plugin.py+++ b/tests/plugins/test_a2a_plugin.py@@ -974,6 +974,25 @@ def _send_body(text, ctx="", extra_params=None):return {"jsonrpc": "2.0", "id": "1", "method": "message/send", "params": params}+def test_ipv6_loopback_bind_serves_and_advertises_a_bracketed_url(monkeypatch):+ """``A2A_HOST=::1`` is an accepted no-token bind: the listener must come up on it and the+ Agent Card must advertise a URL a peer can parse (IPv6 literal in brackets)."""+ monkeypatch.delenv("A2A_BEARER_TOKEN", raising=False)+ monkeypatch.delenv("A2A_PEER_TOKENS", raising=False)+ monkeypatch.setenv("A2A_HOST", "::1")+ adapter, _ = _make_live_adapter(monkeypatch)+ base = f"http://[::1]:{adapter.port}"++ async def run():+ assert await adapter.connect() is True+ try:+ return await asyncio.to_thread(_get_json, base + "/.well-known/agent-card.json")+ finally:+ await adapter.disconnect()++ assert asyncio.run(run())["url"].startswith(base + "/")++@pytest.mark.integrationclass TestInboundRoundTrip:def test_live_server_card_and_message_send(self, monkeypatch):diff --git a/website/docs/user-guide/messaging/a2a.md b/website/docs/user-guide/messaging/a2a.mdindex 3331a88455f..92b82caa29b 100644--- a/website/docs/user-guide/messaging/a2a.md+++ b/website/docs/user-guide/messaging/a2a.md@@ -123,7 +123,7 @@ Secure by default; every widening step is explicit:|---|---|---|| `A2A_PEER_TOKENS` | _(unset)_ | Per-peer credentials `name:token,…` (preferred) || `A2A_BEARER_TOKEN` | _(unset)_ | Shared token; identity falls back to caller IP |-| `A2A_HOST` | `127.0.0.1` | Bind host — only widens when a token is set |+| `A2A_HOST` | `127.0.0.1` | Bind host — only widens when a token is set. IPv6 literals such as `::1` or `::` work too || `A2A_PORT` | `9900` | Inbound port || `A2A_AGENT_NAME` | hostname-derived | Name on the Agent Card || `A2A_PUBLIC_URL` | _(unset)_ | Routable URL advertised on the card (reverse proxies / k8s) |