Agent Mesh
Go a2aa2a-protocolagent-meshagentic-aiinferencemcpmeshmesh-networknetwork-securitynetworking-aip2p-network
node: keep the agent's streaming capability in the A2A card
Vitalii Cherepanov7cbd5c9fbe45
diff --git a/internal/node/a2a_service.go b/internal/node/a2a_service.goindex 042f43b9..666d81ee 100644--- a/internal/node/a2a_service.go+++ b/internal/node/a2a_service.go@@ -239,8 +239,11 @@ func fetchRemoteAgentCard(node *AgentMeshNode, rt http.RoundTripper, r *http.Req// regenerateAgentCardForMesh rebuilds a fetched agent card for mesh use:// interface URLs point back at the mesh path, bindings the mesh cannot carry-// (gRPC) are dropped, streaming is advertised off until verified, and the-// original signatures are removed since they no longer match the content.+// (gRPC) are dropped, and the original signatures are removed since they no+// longer match the content. Capabilities stay as the agent declares them:+// the egress proxy relays an SSE stream as it arrives, and a card that turned+// streaming off would oblige the agent behind it to refuse SendStreamingMessage+// and SubscribeToTask (A2A 1.0, section 3.3.4), which it does not do.func regenerateAgentCardForMesh(card *a2a.AgentCard, base string) error {kept := make([]*a2a.AgentInterface, 0, len(card.SupportedInterfaces))for _, iface := range card.SupportedInterfaces {@@ -254,7 +257,6 @@ func regenerateAgentCardForMesh(card *a2a.AgentCard, base string) error {return fmt.Errorf("agent card advertises no supported interface the mesh can carry (JSONRPC or HTTP+JSON); is the agent serving a pre-1.0 A2A card?")}card.SupportedInterfaces = kept- card.Capabilities.Streaming = falsecard.Signatures = nil// Required list fields must stay arrays: encoding/json marshals nil// slices as null, which strict SDK card parsers (pydantic) reject.diff --git a/internal/node/a2a_service_test.go b/internal/node/a2a_service_test.goindex 94d6bcbf..520d48b1 100644--- a/internal/node/a2a_service_test.go+++ b/internal/node/a2a_service_test.go@@ -218,8 +218,8 @@ func TestA2AServeAgentCardRegenerates(t *testing.T) {if card.SupportedInterfaces[0].ProtocolBinding != a2a.TransportProtocolJSONRPC {t.Errorf("binding = %q, want JSONRPC", card.SupportedInterfaces[0].ProtocolBinding)}- if card.Capabilities.Streaming {- t.Error("streaming must be advertised off through the mesh")+ if !card.Capabilities.Streaming {+ t.Error("streaming must stay as the agent declares it")}if len(card.Signatures) != 0 {t.Error("stale signatures must be dropped from the regenerated card")diff --git a/site/content/docs/use-cases/chat-a2a.md b/site/content/docs/use-cases/chat-a2a.mdindex 14c37a2b..3fd8be45 100644--- a/site/content/docs/use-cases/chat-a2a.md+++ b/site/content/docs/use-cases/chat-a2a.md@@ -28,8 +28,8 @@ So the caller's node stands in for the card endpoint. It holds the client'srequest, fetches the card from the agent over the mesh, and serves aregenerated card whose interface URLs point back at the mesh path that theclient fetched from. Protocol bindings that the mesh cannot carry are-dropped (gRPC needs its own end-to-end connection), and streaming is-advertised as off. The client follows the regenerated card as it would for+dropped (gRPC needs its own end-to-end connection). Capabilities such as+streaming stay as the agent declares them. The client follows the regenerated card as it would forany A2A server. Discovery, sending messages and `contextId` round-trippingall work without changes, while the traffic flows over libp2p between thenodes.@@ -122,8 +122,7 @@ curl -s -H 'X-Mesh-Authentication: Bearer devtoken' \The interface URLs in the response point back at this`/mesh/{peer}/a2a/chat` path, and not at the agent's own `127.0.0.1:7777`.-`capabilities.streaming` is `false`. That regenerated card is what makes the-example work.+That regenerated card is what makes the example work.### 6. Chatdiff --git a/tests/e2e/a2a_mesh.bats b/tests/e2e/a2a_mesh.batsindex 8d68ec17..163ba5de 100644--- a/tests/e2e/a2a_mesh.bats+++ b/tests/e2e/a2a_mesh.bats@@ -66,7 +66,8 @@ teardown() {local mesh_base="http://${MESH_PREFIX}-node-1:8080/mesh/${node2_peer_id}/a2a/echo"# Stock python client: resolves the card through the mesh (client.py asserts- # the regenerated URLs, the gRPC drop and streaming-off) and gets an echo.+ # the regenerated URLs, the gRPC drop and that streaming is kept) and gets+ # an echo over a streamed message/send.echo "[$(date +%T)] Running stock a2a-sdk client against ${mesh_base}"run docker run --rm --network "${MESH_NETWORK}" \-e AGENTMESH_API_TOKEN="secret-token" \diff --git a/tests/e2e/docker/a2a-echo/agent.py b/tests/e2e/docker/a2a-echo/agent.pyindex 98c49fd6..63901b00 100644--- a/tests/e2e/docker/a2a-echo/agent.py+++ b/tests/e2e/docker/a2a-echo/agent.py@@ -1,7 +1,8 @@"""Stock a2a-sdk echo agent for the e2e mesh CUJ: deterministic, no external APIs.The card deliberately advertises a gRPC interface and streaming so the test-can verify the mesh regenerates the card (drops gRPC, turns streaming off).+can verify the mesh regenerates the card (drops gRPC, keeps streaming) and+that the stock client's streamed message/send crosses the mesh."""import uuiddiff --git a/tests/e2e/docker/a2a-echo/client.py b/tests/e2e/docker/a2a-echo/client.pyindex d98eb21f..6e5329e7 100644--- a/tests/e2e/docker/a2a-echo/client.py+++ b/tests/e2e/docker/a2a-echo/client.py@@ -25,7 +25,7 @@ async def main(url: str, text: str) -> None:assert "GRPC" not in bindings, f"gRPC interface not dropped: {bindings}"assert all(i.url == url for i in card.supported_interfaces), \f"interface URLs not regenerated to {url}: {card.supported_interfaces}"- assert not card.capabilities.streaming, "streaming not advertised off"+ assert card.capabilities.streaming, "streaming not kept as the agent declares it"client = await create_client(card, client_config=ClientConfig(httpx_client=http))message = Message(role=Role.ROLE_USER,diff --git a/tests/integration/a2a_test.go b/tests/integration/a2a_test.goindex a530e204..33a534fe 100644--- a/tests/integration/a2a_test.go+++ b/tests/integration/a2a_test.go@@ -68,9 +68,10 @@ func TestA2ACUJ(t *testing.T) {// Stock-SDK A2A agent on node A's side: a2asrv serving its card and// echoing message/send. The card deliberately advertises a gRPC- // interface, streaming, and a stale signature: the mesh must drop all- // three on regeneration. The backend exists before the node: services- // are declared in the node's configuration, never registered at runtime.+ // interface and a stale signature, which the mesh must drop on+ // regeneration, and streaming, which it must keep and carry. The backend+ // exists before the node: services are declared in the node's+ // configuration, never registered at runtime.var sendCount atomic.Int32var sawLabelsHeader atomic.Boolecho := a2asrv.AgentExecutorFunc(func(ctx context.Context, ec *a2asrv.ExecutorContext) iter.Seq2[a2a.Event, error] {@@ -154,8 +155,8 @@ func TestA2ACUJ(t *testing.T) {if card.SupportedInterfaces[0].ProtocolBinding != a2a.TransportProtocolJSONRPC {t.Errorf("binding = %q, want JSONRPC", card.SupportedInterfaces[0].ProtocolBinding)}- if card.Capabilities.Streaming {- t.Error("streaming must be advertised off through the mesh")+ if !card.Capabilities.Streaming {+ t.Error("streaming must stay as the agent declares it")}if len(card.Signatures) != 0 {t.Error("stale signatures must be dropped from the regenerated card")@@ -189,6 +190,22 @@ func TestA2ACUJ(t *testing.T) {t.Fatalf("unexpected reply: %+v", reply)}+ // CUJ step 2b: the card keeps streaming, so the same client may stream+ // the exchange; the SSE response must cross the mesh as it is.+ var streamed []a2a.Event+ for event, err := range euClient.SendStreamingMessage(ctx, req) {+ if err != nil {+ t.Fatalf("streamed message/send failed: %v", err)+ }+ streamed = append(streamed, event)+ }+ if len(streamed) != 1 {+ t.Fatalf("streamed %d events, want the one echo: %+v", len(streamed), streamed)+ }+ if msg, ok := streamed[0].(*a2a.Message); !ok || len(msg.Parts) == 0 || msg.Parts[0].Text() != "echo from eu" {+ t.Fatalf("unexpected streamed event: %+v", streamed[0])+ }+// CUJ step 3: a mismatched label refuses fail-closed BEFORE egress —// the agent backend must never see the request.before := sendCount.Load()