Skip to content

Agent Mesh

testnet: SDK canaries and probes run agents reached by peer ID

Antonio Ojeac47424e6ad54
diff --git a/.github/k8s/sam-probe-cronjob-template.yaml b/.github/k8s/sam-probe-cronjob-template.yaml
index 2b3943de..950f7215 100644
--- a/.github/k8s/sam-probe-cronjob-template.yaml
+++ b/.github/k8s/sam-probe-cronjob-template.yaml
@@ -1,10 +1,10 @@
# The cold path, on a schedule: a node with no identity enrolls with the
# control plane, authenticates to a router, finds a service on the mesh and
-# speaks MCP to it through the mesh, then reaches the services the SDK
-# canaries serve, and exits. The long-lived canaries only do this when a pod
+# speaks MCP to it through the mesh, then reaches an agent written with each
+# SDK by peer ID, and exits. The long-lived canaries only do this when a pod
# restarts, so between rollouts nobody re-checks that a new user could still
-# join. Each run enrolls a fresh identity; the control plane's
-# --node-retention sweep reclaims the rows.
+# join. Each run enrolls fresh identities, the node's and the agents'; the
+# control plane's --node-retention sweep reclaims the rows.
apiVersion: batch/v1
kind: CronJob
metadata:
@@ -21,7 +21,7 @@ spec:
# measure. A failed Job is the signal.
backoffLimit: 0
# 180s to be ready, 120s to reach a provider, 120s for the SDK
- # canaries, with headroom.
+ # agents, with headroom.
activeDeadlineSeconds: 480
template:
metadata:
@@ -32,9 +32,12 @@ spec:
# is what lets the probe call the canaries' services.
serviceAccountName: sam-node-sa
restartPolicy: Never
+ # The agent sidecars run under a shell that pipes to tee; the shell
+ # gets the SIGTERM, the agent the SIGKILL that follows.
+ terminationGracePeriodSeconds: 10
initContainers:
- # A native sidecar: it stays up for the probe container's lifetime
- # and is stopped when that container exits, so the Job completes.
+ # Native sidecars: they stay up for the probe container's lifetime
+ # and are stopped when that container exits, so the Job completes.
- name: sam-node
restartPolicy: Always
image: ghcr.io/google/sam-node:${IMAGE_TAG}
@@ -64,6 +67,73 @@ spec:
readOnly: true
- name: sam-uds
mountPath: /var/run/sam
+ # An agent written with each SDK (sdk/js/examples/agent.ts,
+ # sdk/python/examples/agent.py), the programs the docs embed. Each
+ # accepts A2A requests for a2a://agent and publishes nothing; its
+ # stdout goes to the container log and to the shared volume, where
+ # the probe reads its peer ID.
+ - name: js-agent
+ restartPolicy: Always
+ image: ghcr.io/google/sam-sdk-js:${IMAGE_TAG}
+ command: ["/bin/sh", "-c", "node build/examples/agent.js 2>&1 | tee /var/run/sam-agents/js-agent.log"]
+ env:
+ - name: SAM_CONTROL_PLANE_URL
+ value: "http://sam-control-plane-${ENV_NAME}.${NAMESPACE}.svc.cluster.local:8080"
+ - name: SAM_INSECURE_CONTROL_PLANE
+ value: "true"
+ - name: SAM_JWT_PATH
+ value: /var/run/secrets/tokens/sam-token
+ - name: SAM_STATE_DIR
+ value: /var/run/sam-agents/js-agent
+ securityContext:
+ allowPrivilegeEscalation: false
+ capabilities:
+ drop: ["ALL"]
+ resources:
+ requests:
+ cpu: 50m
+ memory: 128Mi
+ limits:
+ cpu: 500m
+ memory: 512Mi
+ volumeMounts:
+ - name: sam-token
+ mountPath: /var/run/secrets/tokens
+ readOnly: true
+ - name: sam-agents
+ mountPath: /var/run/sam-agents
+ - name: python-agent
+ restartPolicy: Always
+ image: ghcr.io/google/sam-sdk-python:${IMAGE_TAG}
+ command: ["/bin/sh", "-c", "python examples/agent.py 2>&1 | tee /var/run/sam-agents/python-agent.log"]
+ env:
+ - name: SAM_CONTROL_PLANE_URL
+ value: "http://sam-control-plane-${ENV_NAME}.${NAMESPACE}.svc.cluster.local:8080"
+ - name: SAM_INSECURE_CONTROL_PLANE
+ value: "true"
+ - name: SAM_JWT_PATH
+ value: /var/run/secrets/tokens/sam-token
+ - name: SAM_STATE_DIR
+ value: /var/run/sam-agents/python-agent
+ - name: PYTHONUNBUFFERED
+ value: "1"
+ securityContext:
+ allowPrivilegeEscalation: false
+ capabilities:
+ drop: ["ALL"]
+ resources:
+ requests:
+ cpu: 50m
+ memory: 128Mi
+ limits:
+ cpu: 500m
+ memory: 512Mi
+ volumeMounts:
+ - name: sam-token
+ mountPath: /var/run/secrets/tokens
+ readOnly: true
+ - name: sam-agents
+ mountPath: /var/run/sam-agents
containers:
- name: probe
image: alpine/curl:8.12.1
@@ -80,10 +150,9 @@ spec:
# The everything canary's MCP server (sam-node-everything-template.yaml):
# a real server, so the node advertises it and initialize succeeds.
value: everything
- - name: SDK_SERVICES
- # What the SDK canaries publish (sam-sdk-canary-template.yaml),
- # each with a `greet` tool and an A2A endpoint.
- value: "greeter-js greeter-py"
+ - name: SDK_AGENTS
+ # The agent sidecars above, by the log each prints its peer ID to.
+ value: "js python"
resources:
requests:
cpu: 10m
@@ -94,6 +163,9 @@ spec:
volumeMounts:
- name: sam-uds
mountPath: /var/run/sam
+ - name: sam-agents
+ mountPath: /var/run/sam-agents
+ readOnly: true
command: ["/bin/sh", "-c"]
args:
- |
@@ -163,63 +235,49 @@ spec:
done
REACH_S=$(( $(date +%s) - REACH_START ))
- # 4. A service an SDK member serves (sam-sdk-canary-template.yaml)
- # is reachable from a node the way an agent behind a node
- # reaches it: its MCP tool through the node's own MCP API
- # (call_remote_tool opens /sam/mcp/1.0.0 to the provider), and
- # its A2A endpoint through the egress proxy. The node's MCP
- # endpoint is stateful, so one session is opened first.
- MCP=http://localhost/mcp
- SESSION=""
- mcp_post() {
- curl -s --unix-socket "$SOCK" -o "$2" -D /tmp/mcp.hdr -X POST "$MCP" \
- -H 'Content-Type: application/json' -H 'Accept: application/json, text/event-stream' \
- ${SESSION:+-H "Mcp-Session-Id: $SESSION"} -d "$1"
- }
- mcp_post '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-06-18","capabilities":{},"clientInfo":{"name":"sam-probe","version":"0"}}}' /tmp/mcp-init.out \
- || fail sdk "initialize on the node's MCP API failed"
- SESSION=$(grep -i '^mcp-session-id:' /tmp/mcp.hdr | tr -d '\r' | cut -d' ' -f2)
- [ -n "$SESSION" ] || fail sdk "the node's MCP API returned no session"
- mcp_post '{"jsonrpc":"2.0","method":"notifications/initialized"}' /dev/null
-
+ # 4. An agent written with each SDK, reachable by peer ID alone:
+ # it published nothing, so there is nothing to discover, and the
+ # node finds the path through the router by itself. The probe
+ # reads the peer ID from the line the agent printed, then calls
+ # its A2A endpoint through the egress proxy, the way an agent
+ # behind this node reaches another agent. The answer names the
+ # verified caller.
SDK_START=$(date +%s)
- SDK_PROVIDERS=""
- for svc in ${SDK_SERVICES}; do
- SDK_PEER=""
+ SDK_PEERS=""
+ for lang in ${SDK_AGENTS}; do
+ AGENT_LOG=/var/run/sam-agents/${lang}-agent.log
+ AGENT_PEER=""
+ while [ -z "$AGENT_PEER" ]; do
+ AGENT_PEER=$(grep -o 'accepting a2a://agent as [^ ]*' "$AGENT_LOG" 2>/dev/null | tail -1 | cut -d' ' -f4)
+ [ -n "$AGENT_PEER" ] && break
+ [ $(( $(date +%s) - SDK_START )) -ge 120 ] && fail sdk "the ${lang} agent announced no peer ID in 120s"
+ sleep 2
+ done
LAST_ERR=""
- while [ -z "$SDK_PEER" ]; do
- if curl -sf --unix-socket "$SOCK" -o /tmp/sdk-providers.json \
- "http://localhost/sam/service/discover?type=mcp&name=${svc}&timeout=20s"; then
- for p in $(grep -oE '"peer_id":"[^"]+"' /tmp/sdk-providers.json | cut -d'"' -f4); do
- mcp_post '{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"call_remote_tool","arguments":{"peer_id":"'"$p"'","tool_name":"mcp://'"$svc"'/greet","arguments":{"name":"sam-probe"}}}}' /tmp/sdk-call.out
- if grep -q 'hello sam-probe' /tmp/sdk-call.out; then
- CODE=$(curl -s --unix-socket "$SOCK" -o /tmp/sdk-card.out -w '%{http_code}' "http://localhost/sam/${p}/a2a/${svc}/card")
- if [ "$CODE" = "200" ] && grep -q '"caller"' /tmp/sdk-card.out; then
- SDK_PEER=$p
- break
- fi
- LAST_ERR="${p}: a2a card HTTP ${CODE} $(head -c 120 /tmp/sdk-card.out | tr -d '"\n')"
- else
- LAST_ERR="${p}: $(head -c 160 /tmp/sdk-call.out | tr -d '"\n')"
- fi
- done
+ CALL_START=$(date +%s)
+ while :; do
+ CODE=$(curl -s --unix-socket "$SOCK" -o /tmp/sdk-card.out -w '%{http_code}' "http://localhost/sam/${AGENT_PEER}/a2a/agent/card")
+ if [ "$CODE" = "200" ] && grep -q '"caller"' /tmp/sdk-card.out; then
+ break
fi
- [ -n "$SDK_PEER" ] && break
- [ $(( $(date +%s) - SDK_START )) -ge 120 ] && fail sdk "no provider of ${svc} answered greet and its card in 120s (last: ${LAST_ERR:-none discovered})"
+ LAST_ERR="HTTP ${CODE} $(head -c 160 /tmp/sdk-card.out | tr -d '"\n')"
+ [ $(( $(date +%s) - CALL_START )) -ge 120 ] && fail sdk "the ${lang} agent ${AGENT_PEER} did not answer its card in 120s (last: ${LAST_ERR})"
sleep 5
done
- SDK_PROVIDERS="${SDK_PROVIDERS}${SDK_PROVIDERS:+,}\"${svc}\":\"${SDK_PEER}\""
+ SDK_PEERS="${SDK_PEERS}${SDK_PEERS:+,}\"${lang}\":\"${AGENT_PEER}\""
done
SDK_S=$(( $(date +%s) - SDK_START ))
- printf '{"probe":"sam-cold-path","ok":true,"ready_s":%d,"router_latency_ms":%s,"connected_peers":%s,"reach_s":%d,"providers_tried":%d,"call_s":%s,"provider":"%s","sdk_s":%d,"sdk_providers":{%s},"elapsed_s":%d}\n' \
- "$READY_S" "${ROUTER_MS:-null}" "${PEERS:-null}" "$REACH_S" "$TRIED" "$CALL_S" "$PEER" "$SDK_S" "$SDK_PROVIDERS" "$(( $(date +%s) - START ))"
+ printf '{"probe":"sam-cold-path","ok":true,"ready_s":%d,"router_latency_ms":%s,"connected_peers":%s,"reach_s":%d,"providers_tried":%d,"call_s":%s,"provider":"%s","sdk_s":%d,"sdk_agents":{%s},"elapsed_s":%d}\n' \
+ "$READY_S" "${ROUTER_MS:-null}" "${PEERS:-null}" "$REACH_S" "$TRIED" "$CALL_S" "$PEER" "$SDK_S" "$SDK_PEERS" "$(( $(date +%s) - START ))"
volumes:
- name: config-volume
configMap:
name: sam-probe-config-${ENV_NAME}
- name: sam-uds
emptyDir: {}
+ - name: sam-agents
+ emptyDir: {}
- name: sam-token
projected:
sources:
diff --git a/.github/k8s/sam-sdk-canary-template.yaml b/.github/k8s/sam-sdk-canary-template.yaml
index 16fb75d7..e4988f5f 100644
--- a/.github/k8s/sam-sdk-canary-template.yaml
+++ b/.github/k8s/sam-sdk-canary-template.yaml
@@ -1,31 +1,37 @@
-# Two members with no sam-node beside them: the JavaScript and Python SDK
-# example servers (sdk/js/examples/serve.ts, sdk/python/examples/serve.py),
-# unchanged, each publishing mcp://greeter-<lang> and a2a://greeter-<lang>.
-# They enroll with the pod's projected service account token, the way every
-# other canary does, and keep their identity in an emptyDir, so a restart
-# resumes and a new pod enrolls afresh. What the mesh sees from them is what a
-# user of the packages gets.
+# Two long-lived pairs of SDK members with no sam-node beside them: an agent
+# written with one SDK and a caller written with the other, in one pod, both
+# example programs (sdk/js/examples, sdk/python/examples) unchanged. The agent
+# joins through a router and accepts A2A requests for a2a://agent; it publishes
+# nothing, so the caller learns its peer ID from the line it prints, through a
+# volume the pod shares, and calls it every few minutes. The caller is Ready
+# while its last call succeeded, so the Deployment's availability is the
+# answer to "can an agent written with one SDK still be reached by the other
+# after hours on the mesh": relay reservations renewed, credentials refreshed,
+# the control plane followed. Both enroll with the pod's projected service
+# account token, the way every other canary does, and keep their identity in
+# an emptyDir, so a container restart resumes and a new pod enrolls afresh.
apiVersion: apps/v1
kind: Deployment
metadata:
- name: js-canary-${ENV_NAME}
+ name: js-agent-canary-${ENV_NAME}
namespace: sam-canary-${ENV_NAME}
spec:
replicas: 1
selector:
matchLabels:
- app: js-canary-${ENV_NAME}
+ app: js-agent-canary-${ENV_NAME}
template:
metadata:
labels:
- app: js-canary-${ENV_NAME}
+ app: js-agent-canary-${ENV_NAME}
sam-canary: "true"
spec:
serviceAccountName: sam-node-sa
+ terminationGracePeriodSeconds: 10
containers:
- - name: sdk
+ - name: agent
image: ghcr.io/google/sam-sdk-js:${IMAGE_TAG}
- args: ["build/examples/serve.js", "greeter-js"]
+ command: ["/bin/sh", "-c", "node build/examples/agent.js 2>&1 | tee /var/run/sam/agent.log"]
env:
- name: SAM_CONTROL_PLANE_URL
value: "http://sam-control-plane-${ENV_NAME}.${NAMESPACE}.svc.cluster.local:8080"
@@ -34,7 +40,7 @@ spec:
- name: SAM_JWT_PATH
value: /var/run/secrets/tokens/sam-token
- name: SAM_STATE_DIR
- value: /var/run/sam/state
+ value: /var/run/sam/agent
securityContext:
allowPrivilegeEscalation: false
capabilities:
@@ -52,9 +58,56 @@ spec:
readOnly: true
- name: sam-state
mountPath: /var/run/sam
+ - name: caller
+ image: ghcr.io/google/sam-sdk-python:${IMAGE_TAG}
+ command: ["/bin/sh", "/etc/sam-canary/canary.sh"]
+ env:
+ - name: SAM_CONTROL_PLANE_URL
+ value: "http://sam-control-plane-${ENV_NAME}.${NAMESPACE}.svc.cluster.local:8080"
+ - name: SAM_INSECURE_CONTROL_PLANE
+ value: "true"
+ - name: SAM_JWT_PATH
+ value: /var/run/secrets/tokens/sam-token
+ - name: SAM_STATE_DIR
+ value: /var/run/sam/caller
+ - name: PYTHONUNBUFFERED
+ value: "1"
+ - name: CANARY
+ value: python-calls-js-agent
+ - name: CALL
+ value: "python examples/call.py"
+ readinessProbe:
+ exec:
+ command: ["test", "-f", "/var/run/sam/reachable"]
+ initialDelaySeconds: 20
+ periodSeconds: 30
+ failureThreshold: 1
+ securityContext:
+ allowPrivilegeEscalation: false
+ capabilities:
+ drop: ["ALL"]
+ resources:
+ requests:
+ cpu: 50m
+ memory: 128Mi
+ limits:
+ cpu: 500m
+ memory: 512Mi
+ volumeMounts:
+ - name: sam-token
+ mountPath: /var/run/secrets/tokens
+ readOnly: true
+ - name: sam-state
+ mountPath: /var/run/sam
+ - name: canary-script
+ mountPath: /etc/sam-canary
+ readOnly: true
volumes:
- name: sam-state
emptyDir: {}
+ - name: canary-script
+ configMap:
+ name: sam-sdk-canary-script-${ENV_NAME}
- name: sam-token
projected:
sources:
@@ -66,24 +119,25 @@ spec:
apiVersion: apps/v1
kind: Deployment
metadata:
- name: python-canary-${ENV_NAME}
+ name: python-agent-canary-${ENV_NAME}
namespace: sam-canary-${ENV_NAME}
spec:
replicas: 1
selector:
matchLabels:
- app: python-canary-${ENV_NAME}
+ app: python-agent-canary-${ENV_NAME}
template:
metadata:
labels:
- app: python-canary-${ENV_NAME}
+ app: python-agent-canary-${ENV_NAME}
sam-canary: "true"
spec:
serviceAccountName: sam-node-sa
+ terminationGracePeriodSeconds: 10
containers:
- - name: sdk
+ - name: agent
image: ghcr.io/google/sam-sdk-python:${IMAGE_TAG}
- args: ["examples/serve.py", "greeter-py"]
+ command: ["/bin/sh", "-c", "python examples/agent.py 2>&1 | tee /var/run/sam/agent.log"]
env:
- name: SAM_CONTROL_PLANE_URL
value: "http://sam-control-plane-${ENV_NAME}.${NAMESPACE}.svc.cluster.local:8080"
@@ -92,7 +146,7 @@ spec:
- name: SAM_JWT_PATH
value: /var/run/secrets/tokens/sam-token
- name: SAM_STATE_DIR
- value: /var/run/sam/state
+ value: /var/run/sam/agent
- name: PYTHONUNBUFFERED
value: "1"
securityContext:
@@ -112,9 +166,54 @@ spec:
readOnly: true
- name: sam-state
mountPath: /var/run/sam
+ - name: caller
+ image: ghcr.io/google/sam-sdk-js:${IMAGE_TAG}
+ command: ["/bin/sh", "/etc/sam-canary/canary.sh"]
+ env:
+ - name: SAM_CONTROL_PLANE_URL
+ value: "http://sam-control-plane-${ENV_NAME}.${NAMESPACE}.svc.cluster.local:8080"
+ - name: SAM_INSECURE_CONTROL_PLANE
+ value: "true"
+ - name: SAM_JWT_PATH
+ value: /var/run/secrets/tokens/sam-token
+ - name: SAM_STATE_DIR
+ value: /var/run/sam/caller
+ - name: CANARY
+ value: js-calls-python-agent
+ - name: CALL
+ value: "node build/examples/call.js"
+ readinessProbe:
+ exec:
+ command: ["test", "-f", "/var/run/sam/reachable"]
+ initialDelaySeconds: 20
+ periodSeconds: 30
+ failureThreshold: 1
+ securityContext:
+ allowPrivilegeEscalation: false
+ capabilities:
+ drop: ["ALL"]
+ resources:
+ requests:
+ cpu: 50m
+ memory: 128Mi
+ limits:
+ cpu: 500m
+ memory: 512Mi
+ volumeMounts:
+ - name: sam-token
+ mountPath: /var/run/secrets/tokens
+ readOnly: true
+ - name: sam-state
+ mountPath: /var/run/sam
+ - name: canary-script
+ mountPath: /etc/sam-canary
+ readOnly: true
volumes:
- name: sam-state
emptyDir: {}
+ - name: canary-script
+ configMap:
+ name: sam-sdk-canary-script-${ENV_NAME}
- name: sam-token
projected:
sources:
@@ -122,3 +221,47 @@ spec:
path: sam-token
expirationSeconds: 3600
audience: "sam-control-plane-audience"
+---
+apiVersion: v1
+kind: ConfigMap
+metadata:
+ name: sam-sdk-canary-script-${ENV_NAME}
+ namespace: sam-canary-${ENV_NAME}
+data:
+ canary.sh: |
+ #!/bin/sh
+ # Calls the agent beside this container every INTERVAL seconds by the
+ # peer ID it printed to /var/run/sam/agent.log, and keeps
+ # /var/run/sam/reachable present while the last call succeeded; the
+ # readiness probe reads it. One JSON line per call, for a log-based
+ # metric. The first call enrolls with the projected token; the later ones
+ # resume from SAM_STATE_DIR.
+ set -u
+ INTERVAL=${INTERVAL:-300}
+ LOG=/var/run/sam/agent.log
+ REACHABLE=/var/run/sam/reachable
+
+ verdict() {
+ printf '{"canary":"%s","ok":%s,"agent_peer":"%s","call_s":%d,"error":"%s"}\n' \
+ "$CANARY" "$1" "${AGENT_PEER:-}" "$2" "$(printf '%s' "$3" | tr -d '"\n' | cut -c1-300)"
+ }
+
+ while :; do
+ AGENT_PEER=$(grep -o 'accepting a2a://agent as [^ ]*' "$LOG" 2>/dev/null | tail -1 | cut -d' ' -f4)
+ if [ -z "$AGENT_PEER" ]; then
+ sleep 2
+ continue
+ fi
+ start=$(date +%s)
+ out=$($CALL "$AGENT_PEER" a2a://agent /card 2>&1); rc=$?
+ if [ $rc -eq 0 ] && printf '%s' "$out" | grep -q '"caller"'; then
+ touch "$REACHABLE"
+ verdict true $(( $(date +%s) - start )) ""
+ sleep "$INTERVAL"
+ else
+ rm -f "$REACHABLE"
+ verdict false $(( $(date +%s) - start )) "$(printf '%s' "$out" | tail -c 200)"
+ # A failed call is retried soon; the readiness probe already shows it.
+ sleep 30
+ fi
+ done
diff --git a/.github/k8s/sam-sdk-probe-cronjob-template.yaml b/.github/k8s/sam-sdk-probe-cronjob-template.yaml
index a02239b9..7ee33e2c 100644
--- a/.github/k8s/sam-sdk-probe-cronjob-template.yaml
+++ b/.github/k8s/sam-sdk-probe-cronjob-template.yaml
@@ -1,12 +1,14 @@
-# The cold path through the SDKs, on a schedule: a fresh identity enrolls with
-# the control plane through each SDK, joins through a router, and calls out
-# across every implementation boundary a user can cross: an MCP service a
-# sam-node serves (the everything canary), and an MCP tool and an A2A endpoint
-# the other language's SDK serves (the sdk canaries). The programs are the
-# examples the READMEs embed, unchanged; the shell around them only retries
-# discovery, which a member that joined seconds ago can miss, and prints one
-# verdict line. Each run enrolls a fresh identity per language; the control
-# plane's --node-retention sweep reclaims the rows.
+# The cold path through the SDKs, on a schedule. Four fresh identities enroll
+# with the control plane, two per SDK: an agent, which joins through a router
+# and accepts A2A requests for a2a://agent, and a caller, which reaches an MCP
+# service a sam-node serves (the everything canary) by name and the other
+# language's agent by peer ID. An agent publishes nothing; the caller learns
+# its peer ID from the line the agent prints, through a volume the pod shares.
+# The programs are the examples the READMEs embed, unchanged; the shell around
+# them only retries discovery, which a member that joined seconds ago can
+# miss, waits for the agent, and prints one verdict line. The agents are
+# native sidecars, stopped when both callers exit, so the Job completes. The
+# control plane's --node-retention sweep reclaims the rows.
apiVersion: batch/v1
kind: CronJob
metadata:
@@ -20,19 +22,87 @@ spec:
jobTemplate:
spec:
# One attempt: a retry would hide exactly the flakiness this exists to
- # measure. A failed Job is the signal; both containers must succeed.
+ # measure. A failed Job is the signal; both callers must succeed.
backoffLimit: 0
- # Three calls with up to 120s of discovery each, plus enrollment.
- activeDeadlineSeconds: 480
+ # Two calls with up to 120s each, plus enrollment.
+ activeDeadlineSeconds: 420
template:
metadata:
labels:
app: sam-sdk-probe-${ENV_NAME}
spec:
# Bound to the sam-canary role by deploy.yaml's policy seed, which
- # is what lets the probe call the canaries' services.
+ # is what lets the callers reach the canaries and the agents.
serviceAccountName: sam-node-sa
restartPolicy: Never
+ # The agent sidecars run under a shell that pipes to tee; the shell
+ # gets the SIGTERM, the agent the SIGKILL that follows.
+ terminationGracePeriodSeconds: 10
+ # The agents' stdout goes both to the container log and to the
+ # shared volume, where the callers read the peer ID from it.
+ initContainers:
+ - name: js-agent
+ restartPolicy: Always
+ image: ghcr.io/google/sam-sdk-js:${IMAGE_TAG}
+ command: ["/bin/sh", "-c", "node build/examples/agent.js 2>&1 | tee /var/run/sam/js-agent.log"]
+ env:
+ - name: SAM_CONTROL_PLANE_URL
+ value: "http://sam-control-plane-${ENV_NAME}.${NAMESPACE}.svc.cluster.local:8080"
+ - name: SAM_INSECURE_CONTROL_PLANE
+ value: "true"
+ - name: SAM_JWT_PATH
+ value: /var/run/secrets/tokens/sam-token
+ - name: SAM_STATE_DIR
+ value: /var/run/sam/js-agent
+ securityContext:
+ allowPrivilegeEscalation: false
+ capabilities:
+ drop: ["ALL"]
+ resources:
+ requests:
+ cpu: 50m
+ memory: 128Mi
+ limits:
+ cpu: 500m
+ memory: 512Mi
+ volumeMounts:
+ - name: sam-token
+ mountPath: /var/run/secrets/tokens
+ readOnly: true
+ - name: sam-state
+ mountPath: /var/run/sam
+ - name: python-agent
+ restartPolicy: Always
+ image: ghcr.io/google/sam-sdk-python:${IMAGE_TAG}
+ command: ["/bin/sh", "-c", "python examples/agent.py 2>&1 | tee /var/run/sam/python-agent.log"]
+ env:
+ - name: SAM_CONTROL_PLANE_URL
+ value: "http://sam-control-plane-${ENV_NAME}.${NAMESPACE}.svc.cluster.local:8080"
+ - name: SAM_INSECURE_CONTROL_PLANE
+ value: "true"
+ - name: SAM_JWT_PATH
+ value: /var/run/secrets/tokens/sam-token
+ - name: SAM_STATE_DIR
+ value: /var/run/sam/python-agent
+ - name: PYTHONUNBUFFERED
+ value: "1"
+ securityContext:
+ allowPrivilegeEscalation: false
+ capabilities:
+ drop: ["ALL"]
+ resources:
+ requests:
+ cpu: 50m
+ memory: 128Mi
+ limits:
+ cpu: 500m
+ memory: 512Mi
+ volumeMounts:
+ - name: sam-token
+ mountPath: /var/run/secrets/tokens
+ readOnly: true
+ - name: sam-state
+ mountPath: /var/run/sam
containers:
- name: js
image: ghcr.io/google/sam-sdk-js:${IMAGE_TAG}
@@ -49,9 +119,9 @@ spec:
value: sam-sdk-js
- name: CALL
value: "node build/examples/call.js"
- - name: PEER_SERVICE
- # The other SDK's canary (sam-sdk-canary-template.yaml).
- value: greeter-py
+ - name: AGENT_LOG
+ # Where the other SDK's agent prints its peer ID.
+ value: /var/run/sam/python-agent.log
securityContext:
allowPrivilegeEscalation: false
capabilities:
@@ -90,8 +160,8 @@ spec:
value: sam-sdk-python
- name: CALL
value: "python examples/call.py"
- - name: PEER_SERVICE
- value: greeter-js
+ - name: AGENT_LOG
+ value: /var/run/sam/js-agent.log
securityContext:
allowPrivilegeEscalation: false
capabilities:
@@ -135,12 +205,14 @@ metadata:
data:
probe.sh: |
#!/bin/sh
- # Runs the SDK's call example against three services and prints one JSON
- # verdict line. PROBE names the run, CALL is the example's command line,
- # PEER_SERVICE is the other SDK's canary. Discovery is retried: a member
- # that joined seconds ago has a thin routing table, and a provider record
- # can name a pod a rollout just replaced. The first call enrolls with the
- # projected token; the later ones resume from SAM_STATE_DIR.
+ # Runs the SDK's call example against a sam-node's MCP service and the
+ # other SDK's agent, and prints one JSON verdict line. PROBE names the
+ # run, CALL is the example's command line, AGENT_LOG is where the other
+ # SDK's agent prints "accepting a2a://agent as <peer>". Discovery is
+ # retried: a member that joined seconds ago has a thin routing table, and
+ # a provider record can name a pod a rollout just replaced. The first
+ # call enrolls with the projected token; the later ones resume from
+ # SAM_STATE_DIR.
set -u
START=$(date +%s)
@@ -167,17 +239,28 @@ data:
done
}
+ # wait_for_agent <log>: sets AGENT_PEER from the agent's accepting line.
+ wait_for_agent() {
+ wait_start=$(date +%s)
+ while :; do
+ AGENT_PEER=$(grep -o 'accepting a2a://agent as [^ ]*' "$1" 2>/dev/null | tail -1 | cut -d' ' -f4)
+ [ -n "$AGENT_PEER" ] && return 0
+ [ $(( $(date +%s) - wait_start )) -ge 120 ] && fail agent "no agent announced itself in $1 within 120s"
+ sleep 2
+ done
+ }
+
# 1. Enroll, join and call an MCP service a sam-node serves.
call node-mcp 'Echo: sam-sdk-probe' mcp://everything echo '{"message": "sam-sdk-probe"}'
NODE_PEER=$PROVIDER
NODE_S=$(( $(date +%s) - START ))
- # 2. The other SDK's MCP tool, then its A2A endpoint over /libp2p-http.
- SDK_START=$(date +%s)
- call sdk-mcp 'hello sam-sdk-probe' "mcp://${PEER_SERVICE}" greet '{"name": "sam-sdk-probe"}'
- SDK_PEER=$PROVIDER
- call sdk-a2a '"caller"' "a2a://${PEER_SERVICE}" /card
- SDK_S=$(( $(date +%s) - SDK_START ))
+ # 2. The other SDK's agent, by peer ID, over /libp2p-http through the
+ # router: the agent names the verified caller in its answer.
+ wait_for_agent "$AGENT_LOG"
+ A2A_START=$(date +%s)
+ call sdk-a2a '"caller"' "$AGENT_PEER" a2a://agent /card
+ A2A_S=$(( $(date +%s) - A2A_START ))
- printf '{"probe":"%s","ok":true,"node_s":%d,"node_provider":"%s","sdk_s":%d,"sdk_provider":"%s","elapsed_s":%d}\n' \
- "$PROBE" "$NODE_S" "$NODE_PEER" "$SDK_S" "$SDK_PEER" "$(( $(date +%s) - START ))"
+ printf '{"probe":"%s","ok":true,"node_s":%d,"node_provider":"%s","a2a_s":%d,"agent_peer":"%s","elapsed_s":%d}\n' \
+ "$PROBE" "$NODE_S" "$NODE_PEER" "$A2A_S" "$AGENT_PEER" "$(( $(date +%s) - START ))"
diff --git a/.github/workflows/deploy.yaml b/.github/workflows/deploy.yaml
index 84425cc3..73b879ff 100644
--- a/.github/workflows/deploy.yaml
+++ b/.github/workflows/deploy.yaml
@@ -806,9 +806,9 @@ jobs:
exit 1
}
- # Two members with no sam-node: the SDK example servers, each
- # publishing an MCP tool and an A2A endpoint. What the probes below
- # reach from a node and from the other SDK.
+ # Two long-lived pairs with no sam-node: an agent written with one SDK
+ # and a caller written with the other, reaching it by peer ID every few
+ # minutes. The caller's readiness is the last call's outcome.
- name: Deploy SDK Canaries
env:
VAR_ENV_NAME: ${{ vars.ENV_NAME }}
@@ -819,18 +819,23 @@ jobs:
export NAMESPACE="sam-${ENV_NAME}"
export IMAGE_TAG="${VAR_IMAGE_TAG}"
+ # The SDK canaries that published services, replaced by these.
+ kubectl delete deployment js-canary-${ENV_NAME} python-canary-${ENV_NAME} -n ${CANARY_NAMESPACE} --ignore-not-found
envsubst '${ENV_NAME} ${NAMESPACE} ${IMAGE_TAG}' < .github/k8s/sam-sdk-canary-template.yaml | kubectl apply -f -
for lang in js python; do
- kubectl rollout status deployment/${lang}-canary-${ENV_NAME} -n ${CANARY_NAMESPACE} --timeout=180s || {
- echo "${lang} SDK canary deployment failed!"
- kubectl describe deployment/${lang}-canary-${ENV_NAME} -n ${CANARY_NAMESPACE} || true
- kubectl get pods -n ${CANARY_NAMESPACE} -l app=${lang}-canary-${ENV_NAME} -o wide || true
- kubectl describe pods -n ${CANARY_NAMESPACE} -l app=${lang}-canary-${ENV_NAME} || true
- kubectl logs -n ${CANARY_NAMESPACE} -l app=${lang}-canary-${ENV_NAME} --tail=-1 || true
-
- echo "Rolling back ${lang} SDK canary deployment..."
- kubectl rollout undo deployment/${lang}-canary-${ENV_NAME} -n ${CANARY_NAMESPACE}
- kubectl rollout status deployment/${lang}-canary-${ENV_NAME} -n ${CANARY_NAMESPACE} || true
+ kubectl rollout status deployment/${lang}-agent-canary-${ENV_NAME} -n ${CANARY_NAMESPACE} --timeout=180s || {
+ echo "${lang} agent canary deployment failed: the other SDK's caller could not reach the agent."
+ kubectl describe deployment/${lang}-agent-canary-${ENV_NAME} -n ${CANARY_NAMESPACE} || true
+ kubectl get pods -n ${CANARY_NAMESPACE} -l app=${lang}-agent-canary-${ENV_NAME} -o wide || true
+ kubectl describe pods -n ${CANARY_NAMESPACE} -l app=${lang}-agent-canary-${ENV_NAME} || true
+ for c in agent caller; do
+ echo "==== ${c} log ===="
+ kubectl logs -n ${CANARY_NAMESPACE} -l app=${lang}-agent-canary-${ENV_NAME} -c ${c} --tail=-1 || true
+ done
+
+ echo "Rolling back ${lang} agent canary deployment..."
+ kubectl rollout undo deployment/${lang}-agent-canary-${ENV_NAME} -n ${CANARY_NAMESPACE}
+ kubectl rollout status deployment/${lang}-agent-canary-${ENV_NAME} -n ${CANARY_NAMESPACE} || true
exit 1
}
done
@@ -888,11 +893,11 @@ jobs:
exit 1
}
- # A fresh node enrolls, reaches a router and calls the everything
- # canary's MCP server through the mesh: what a new user does. The
- # CronJob keeps doing it every 15 minutes; running it once here, after
- # every canary is up, makes the rollout prove it before the deploy is
- # called good.
+ # A fresh node enrolls, reaches a router, calls the everything
+ # canary's MCP server through the mesh and reaches an agent written
+ # with each SDK by peer ID: what a new user does. The CronJob keeps
+ # doing it every 15 minutes; running it once here, after every canary
+ # is up, makes the rollout prove it before the deploy is called good.
- name: Deploy and run the cold-path probe
env:
VAR_ENV_NAME: ${{ vars.ENV_NAME }}
@@ -926,19 +931,22 @@ jobs:
case "${status:-}" in
*Complete=True*) echo "Cold-path probe passed." ;;
*)
- echo "Cold-path probe did not pass: a fresh node could not enroll, reach a router, or call a mesh service."
- echo "==== sam-node sidecar log ===="
- kubectl logs "job/${JOB}" -n "${CANARY_NAMESPACE}" -c sam-node --tail=200 || true
+ echo "Cold-path probe did not pass: a fresh node could not enroll, reach a router, call a mesh service, or reach an SDK agent."
+ for c in sam-node js-agent python-agent; do
+ echo "==== ${c} sidecar log ===="
+ kubectl logs "job/${JOB}" -n "${CANARY_NAMESPACE}" -c "${c}" --tail=200 || true
+ done
kubectl describe job "${JOB}" -n "${CANARY_NAMESPACE}" || true
exit 1
;;
esac
- # The same cold path through each SDK: a fresh identity enrolls with
- # the JavaScript and the Python SDK, reaches the everything canary's
- # MCP server (a sam-node) and the other SDK's canary, MCP and A2A. With
- # the node probe above, every pair of implementations is crossed in
- # both directions on every rollout and every 15 minutes after.
+ # The same cold path through each SDK: an agent and a caller enroll
+ # with the JavaScript and the Python SDK; each caller reaches the
+ # everything canary's MCP server (a sam-node) by name and the other
+ # SDK's agent by peer ID. With the node probe above, every pair of
+ # implementations is crossed in both directions on every rollout and
+ # every 15 minutes after.
- name: Deploy and run the SDK cold-path probe
env:
VAR_ENV_NAME: ${{ vars.ENV_NAME }}
@@ -972,7 +980,11 @@ jobs:
case "${status:-}" in
*Complete=True*) echo "SDK cold-path probe passed." ;;
*)
- echo "SDK cold-path probe did not pass: an SDK could not enroll, reach a router, or call a service a node or the other SDK serves."
+ echo "SDK cold-path probe did not pass: an SDK could not enroll, reach a router, call a service a node serves, or reach the other SDK's agent."
+ for lang in js python; do
+ echo "==== ${lang} agent sidecar log ===="
+ kubectl logs "job/${JOB}" -n "${CANARY_NAMESPACE}" -c "${lang}-agent" --tail=200 || true
+ done
kubectl describe job "${JOB}" -n "${CANARY_NAMESPACE}" || true
exit 1
;;
diff --git a/.github/workflows/sdk.yml b/.github/workflows/sdk.yml
index 1e83b8bf..0e9cebcb 100644
--- a/.github/workflows/sdk.yml
+++ b/.github/workflows/sdk.yml
@@ -98,5 +98,9 @@ jobs:
run: |
docker build -f Dockerfile.sam-sdk-js -t sam-sdk-js:ci .
docker build -f Dockerfile.sam-sdk-python -t sam-sdk-python:ci .
+ # Without a token every example stops at enrollment with this
+ # message: the default command (the agent) and the caller both.
+ docker run --rm sam-sdk-js:ci 2>&1 | grep -q 'exactly one of'
+ docker run --rm sam-sdk-python:ci 2>&1 | grep -q 'exactly one of'
docker run --rm sam-sdk-js:ci build/examples/call.js 2>&1 | grep -q 'exactly one of'
docker run --rm sam-sdk-python:ci examples/call.py 2>&1 | grep -q 'exactly one of'
diff --git a/Dockerfile.sam-sdk-js b/Dockerfile.sam-sdk-js
index c9b6fd0a..b2dfe3ba 100644
--- a/Dockerfile.sam-sdk-js
+++ b/Dockerfile.sam-sdk-js
@@ -1,9 +1,10 @@
# The JavaScript SDK with its example programs, as the testnet canaries run
-# them: `node build/examples/serve.js <name>` publishes services on the mesh,
-# `node build/examples/call.js <service> <tool|path> [args]` calls one. The
-# examples import "@sam-mesh/sdk" by name and resolve it through the package's
-# own exports, so the image keeps the package layout: package.json, dist/,
-# build/examples/ and the production node_modules/.
+# them: `node build/examples/agent.js [url]` joins as an agent that accepts
+# A2A requests, `node build/examples/call.js [peer] <service> <tool|path>
+# [args]` calls a service or an agent. The examples import "@sam-mesh/sdk"
+# by name and resolve it through the package's own exports, so the image
+# keeps the package layout: package.json, dist/, build/examples/ and the
+# production node_modules/.
# Stage 1: Build
FROM node:22-bookworm-slim@sha256:43ac6c60b8f89723f746e8a92ce91abd5017e627ce1ddfe4238355d3a30b772c AS builder
@@ -23,4 +24,4 @@ COPY --from=builder --chown=node:node /src/node_modules ./node_modules
USER node
ENV HOME=/home/node
ENTRYPOINT ["node"]
-CMD ["build/examples/serve.js"]
+CMD ["build/examples/agent.js"]
diff --git a/Dockerfile.sam-sdk-python b/Dockerfile.sam-sdk-python
index d7ba4094..8376440f 100644
--- a/Dockerfile.sam-sdk-python
+++ b/Dockerfile.sam-sdk-python
@@ -1,8 +1,9 @@
# The Python SDK with its example programs, as the testnet canaries run them:
-# `python examples/serve.py <name>` publishes services on the mesh,
-# `python examples/call.py <service> <tool|path> [args]` calls one. fastecdsa,
-# a py-libp2p dependency, builds from source against GMP, so the build stage
-# carries a compiler and the final image only libgmp10.
+# `python examples/agent.py [url]` joins as an agent that accepts A2A
+# requests, `python examples/call.py [peer] <service> <tool|path> [args]`
+# calls a service or an agent. fastecdsa, a py-libp2p dependency, builds from
+# source against GMP, so the build stage carries a compiler and the final
+# image only libgmp10.
# Stage 1: Build
FROM python:3.12-slim-bookworm@sha256:392307d22300de8b5986851a12d9176dfc0fc073e65bf6523ebd7dcbeb23564e AS builder
@@ -20,4 +21,4 @@ COPY --chown=nonroot:nonroot sdk/python/examples ./examples
USER nonroot:nonroot
ENV PATH=/opt/venv/bin:$PATH
ENTRYPOINT ["python"]
-CMD ["examples/serve.py"]
+CMD ["examples/agent.py"]