How to govern agents you did not build (open-source, partner, A2A) on a live Flex/Omni Gateway. Route the agent's LLM traffic through a Model Proxy (client-id-enforcement, llm-proxy-core, model-based-routing, llm-token-rate-limit) and front its A2A endpoint with an A2A instance carrying client-ID enforcement, agent-connection-telemetry, an A2A token rate limit and an agent-card rewrite. Includes a worked example configuring the open-source Hermes agent, a path-scoped policy table, allowed and refused A2A message/send results, deterministic checks, and troubleshooting for the pitfalls found live: methodRegex pointcuts silently ignored on A2A instances, A2A Schema Validation rejecting common JSON-RPC, the A2A policy family appearing only for A2A v1.0 assets, PII detector defaulting to detect-only, and A2A policies being UI-only.
Tags: cross-industry, agent-governance, third-party-agents, a2a, model-proxy, llm-proxy, flex-gateway, omni-gateway, api-manager, client-id-enforcement, token-rate-limit, agent-card, pii-detection, rogue-agent-detection, hermes
Governing Third-Party and A2A Agents at the Gateway: Model Proxy and A2A Policies on Flex/Omni Gateway
Deliverable: A live enforcement point for agents you did not build. An open-source agent (worked example: the Hermes agent from Nous Research) sends every model call through a Model Proxy that authenticates, meters and limits it, and its A2A endpoint sits behind an A2A instance with client-ID enforcement, telemetry, a token rate limit and an agent-card rewrite. Each control is verified with a request, not assumed from a screen.
Objective: Agents you did not write (open-source, partner, anything that speaks A2A) call models with provider keys you cannot rotate centrally and publish A2A endpoints that anyone with the URL can reach. You cannot add a policy to code you do not own, so the gateway is the only place left. Declaring policies in an agent-network file works for agents you build; this plan covers the other case: policies attached to live gateway instances, then proven with traffic that should pass and traffic that should be refused.
What's Getting Built
- Model Proxy instance (LLM proxy on Flex/Omni Gateway) — OpenAI-format front door for the agent's model calls, routed to one provider deployment ·
POST /llm-proxy-{agent}/chat/completions
- Model Proxy policy chain —
client-id-enforcement, cors, dataweave-headers-transformation, llm-proxy-core, model-based-routing, provider transcoding policy, optional llm-token-rate-limit
- A2A agent asset in Exchange — the agent's card published as type "A2A v1.0", which unlocks the A2A policy family
- A2A instance (Protocol = A2A, base path
/) — fronts the agent's endpoint · GET /.well-known/agent-card.json (public), POST / (JSON-RPC, gated)
- A2A policy chain —
client-id-enforcement (path-scoped), agent-connection-telemetry, a-two-a-v1-token-rate-limit, a-two-a-v1-agent-card
- Verification probes — allowed and refused requests, run around each policy
Prerequisites
- Anypoint org with API Manager and a Flex or Omni Gateway in connected mode. Creating LLM and A2A instances is UI-only; existing instances' policies can be read and changed through the API.
- A consumer application with a contract on each instance. Its
client_id and client_secret come from a secret store.
- A model provider deployment you control (the worked example uses Azure OpenAI) with enough tokens-per-minute headroom for large agent turns.
- The agent installed and configurable from the command line, and its A2A card as JSON.
- For public exposure: a tunnel or ingress you can repoint, and owner sign-off, since that changes who can reach the agent.
Choose your path
- LLM traffic only — Choose this when the agent calls models but nobody calls it. One instance and one config change give authentication, metering and token limits.
- A2A endpoint only — Choose this when its models are governed elsewhere but other agents call it.
- Both — Choose this for agents such as Hermes that call out and are called. The instances are independent; build the Model Proxy first, the simpler win.
Architecture
1. Route the agent's model calls through a Model Proxy
- Create the LLM proxy in API Manager: OpenAI format, model-based routing, and the right provider at creation (for Azure choose "Azure OpenAI"; "OpenAI" aimed at an Azure URL returns 404 from the wrong path shape, and editing the provider later fails, so recreate). A route pins one provider deployment, so plan one model per proxy; the request
model field cannot switch deployments.
- Chain in execution order:
client-id-enforcement, cors, dataweave-headers-transformation (accepts a combined id:secret and splits it), llm-proxy-core (captures token usage and sets clientIdentifier for attribution), model-based-routing, then the provider transcoding policy (injects API version and deployment ID).
- Add
llm-token-rate-limit for a per-consumer budget. In the reference proxy it was 1,000,000 tokens per 60 seconds keyed by client ID; over budget the gateway returns 429 and reports the remainder in the x-llm-proxy-ratelimit header.
- Prefer a classic LLM proxy where you need enforced authentication and token metering. On one enhanced Model Proxy instance, configuration edits never reached the runtime: client-ID enforcement and token counts stayed inert while request, latency and error monitoring worked. A classic proxy with the same chain enforced and metered. Verify rather than trust the screen (step 7).
- A policy changed over the API may need a UI Save & Apply to enforce; "registered" is not "enforcing".
2. Point the third-party agent at the proxy
Worked example, Hermes. The provider must be custom: with auto Hermes selects its own nous profile, which adds a top-level session_id field that Azure rejects with HTTP 400 Unknown parameter 'session_id'.
hermes config set model.provider custom
hermes config set model.default {model-name}
hermes config set model.base_url "{gateway-url}/llm-proxy-{agent}"
hermes config set model.api_key "{client_id}:{client_secret}" # from your secret store
hermes -z "Reply with exactly: gateway ok" --usage-file /tmp/usage.json
- The bearer is the consumer's
client_id:client_secret joined with a colon. hermes config set works without a TTY.
- Reasoning models reject
max_tokens; use max_completion_tokens in direct curl tests.
- Keep a break-glass fallback (the same
config set lines aimed at a local OpenAI-compatible server); it bypasses governance.
3. Publish the agent card as an "A2A v1.0" asset
- The A2A policy family appears only when the instance Protocol is A2A, which needs the Exchange asset type "A2A v1.0" (not "Other").
- A card in the older shape fails v1.0 validation until you strip top-level
url, capabilities.stateTransitionHistory, securitySchemes and security. In v1.0 the endpoint lives in supportedInterfaces[].url:
{
"name": "{agent-name}",
"version": "1.0.0",
"supportedInterfaces": [
{ "url": "{public-url}/", "protocolBinding": "JSONRPC", "protocolVersion": "1.0" }
],
"capabilities": { "streaming": true, "pushNotifications": true, "extendedAgentCard": false },
"defaultInputModes": ["text/plain"],
"defaultOutputModes": ["text/plain"]
}
- Generate the v1.0 copy from the source card so they cannot drift.
4. Create the A2A instance
- In API Manager add an agent instance with Protocol = A2A, base path
/, the agent endpoint as upstream, and a listener port that no other route uses (a / catch-all on a port already serving a proxy route collides with it).
- Keep the agent bound to loopback and let the gateway reach it (a container gateway on the same host uses the host alias); do not rebind the agent to all interfaces.
- Bind a contract for each calling application; client-ID enforcement admits only provisioned callers.
5. Attach A2A policies by path, not by method
| Order |
Policy |
Configuration |
| 1 |
client-id-enforcement |
default config reads client_id and client_secret headers; pointcutData=[{"methodRegex":null,"uriTemplateRegex":"^/quot;}] |
| 2 |
agent-connection-telemetry |
sourceAgentId = #[attributes.headers['X-ANYPOINT-API-INSTANCE-ID']] |
| 3 |
a-two-a-v1-token-rate-limit |
maximumTokens=1000000, timePeriodInMilliseconds=60000, keySelector=#['{agent}-a2a'] |
| 4 |
a-two-a-v1-agent-card |
consumerUrl={public-url} |
- A
methodRegex pointcut (for example POST) on an a2a_v1 instance is silently ignored: the policy does not attach and traffic falls through with no error. A uriTemplateRegex pointcut works; ^/$ matches the JSON-RPC root and leaves GET /.well-known/agent-card.json open. A blanket (null) pointcut gates the card too and breaks discovery.
client-id-enforcement reads headers, not Authorization, so it composes with the agent's own bearer: a caller needs both. If the agent's token is opaque rather than a JWT, a JWT-validation policy cannot validate it. This is a closed-caller model.
- The
keySelector above is a static literal, so all callers share one bucket. Advice: once contracts exist, put the consumer client ID in the selector so one noisy caller cannot exhaust the limit for everyone.
- Read configuration with
GET .../policies/{policy-id}; the list view echoes empty configurationData.
- Leave
a-two-a-v1-schema-validation off for agents that speak common A2A JSON-RPC (see Troubleshooting).
- On a connected self-managed gateway a change reaches the route in about 40 seconds; verify by sending a request.
6. Add content and abuse controls (verify availability first)
- The policy picker on your instance is ground truth, not the org-wide catalog. One A2A instance offered the
a2a-v1-* family (PII Detector, Agent Card, Prompt Decorator, Bedrock and Azure Guardrails, Quality Evaluation) but not Schema Validation or Token Rate Limit; another offered the a-two-a-v1-* set. Check before designing around a policy.
- A2A policies cannot be applied by API (the call returns 400 about requiring an A2A asset type). Add them in the UI, one at a time.
- A2A v1 PII Detector, applied without configuration, ran detect-only with no entities, and PII still reached the answer. Set Action to Mask and choose entities (email, US SSN), then re-probe.
- Rogue Agent Detection and Agent Kill Switch are LLM-asset policies, so they attach to the Model Proxy from step 1, not the A2A instance. Rogue Agent Detection needs
agentIdField, userIdField, anomalies and dedupWindowSecs, and it flags for review rather than blocking. Agent Kill Switch is the policy intended to stop an agent; rehearse scope, hard stop, restore and audit on a private listener before relying on it.
- Anything in release notes that you cannot attach is roadmap; do not claim it until a probe shows it working.
7. Verify with traffic before exposing anything
- Run the probe set before and after each policy and keep both results (see Testing).
- Run the governed path in parallel on a private listener while public traffic stays on the raw agent. Only when every expected status holds, repoint the tunnel or ingress to the gateway. Rollback is pointing it back; the agent's own bearer stays in force on both paths.
8. Security and compliance
- Two independent checks protect the A2A RPC path: the gateway credential and the agent's own bearer. Neither replaces the other.
- Keep consumer secrets and agent tokens in a secret store, read at runtime; never in committed config, tickets or chat.
- The worked-example agent may answer a peer with a security refusal; that is its own guardrail, and transport still returns 200.
- Log decision, policy and caller identity, not message bodies.
- Fail closed: if the gateway is down, callers get an error. The only bypass is the step 2 fallback; audit it.
Sample payload — allowed and denied A2A calls
curl -s -D - -X POST "{gateway-url}/" \
-H "Authorization: Bearer {agent-peer-token}" \
-H "client_id: {client_id}" -H "client_secret: {client_secret}" \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","id":1,"method":"message/send",
"params":{"message":{"role":"user","messageId":"probe-1",
"parts":[{"kind":"text","text":"hi"}]}}}'
Observed on the reference instance:
| Case |
Result |
| Valid gateway credential plus agent bearer |
200, header Server: Anypoint Flex Gateway (direct to the agent it names a different server, which proves gateway tracking) |
No client_id on the POST |
401 |
Wrong client_secret |
401 |
GET /.well-known/agent-card.json, no credentials |
200 |
Schema Validation enabled, message/send with role:user |
JSON-RPC -32601 or -32602, before the agent sees it |
A completed reply is v1.0-shaped: ROLE_AGENT, state TASK_STATE_COMPLETED, text in parts[].text. The exact A2A token-limit refusal was not captured in the evidence behind this plan, so record what you observe. The probe treats HTTP 429, a body containing "rate limit", or JSON-RPC -32005 as limited. On the Model Proxy the shape is known: HTTP 429 with x-llm-proxy-ratelimit: Token rate limit: {N} tokens remaining of {limit}.
Deterministic checks
- Model Proxy: no credentials returns
401; the consumer credential returns 200 with a completion.
- A2A: card
GET without credentials 200; RPC POST / without client_id 401, wrong secret 401, valid credentials plus agent bearer 200.
GET .../policies/{policy-id} on the client-ID policy shows uriTemplateRegex ^/$ and no methodRegex.
- Attached policies per instance equal the intended chain and order.
- A burst over the token budget is refused in the recorded shape; within-budget calls stay
200.
- Model Proxy token count for a known prompt is non-zero and matches the provider's record.
- A synthetic email and SSN do not appear in the answer once PII Action is Mask; a policy that is "applied" but leaks fails the check.
- An unreachable upstream yields an error to the caller, never a fabricated answer.
Testing and validation
- Baseline first, with no policies: normal call, malformed envelope, synthetic PII, a 12-call burst. In one baseline all 12 burst calls returned 200 and the PII round-tripped into the answer; each policy must change that.
- Re-run after each policy so one that silently fails to attach is caught on the step that added it.
- Edge case that breaks naive setups: a blanket client-ID policy passes every RPC test yet breaks card discovery. Always test the card
GET without credentials.
- A malformed-envelope probe is not a clean isolate: the upstream can reject it (
-32600) with no gateway policy, so compare against baseline.
- Latency: a locally hosted model that unloads when idle adds minutes to the first turn. A suspected 15 second gateway timeout was a model-eviction artifact; with the model resident, turns of 5 and 42.7 seconds both returned 200.
Phased rollout
Phase 1 — Connect
- Stand up the Model Proxy, point the agent at it, prove 401 without and 200 with credentials.
Phase 2 — Map and validate
- Publish the card, create the A2A instance, attach the chain by path, and run baseline and after-policy probes. Add PII masking and the kill switch rehearsal on a private listener.
Phase 3 — Production
- With sign-off, repoint public traffic and provision each real peer as a contract. Send a scheduled low-cost request so telemetry dashboards stay populated (they lag minutes to hours).
Success metrics
- Share of the agent's model calls through the proxy (target: all) and of A2A calls with a known client ID.
- Tokens attributed to a named consumer versus unattributed; declared-versus-attached policy drift (target zero).
- Weekly 401, 429 and masked-PII counts, and false refusals of legitimate peers.
Troubleshooting
- Provider
400 Unknown parameter 'session_id' — Likely cause: provider auto. Fix: set custom.
- LLM calls return
404 with an empty body — Likely cause: the proxy instance is undeployed on the gateway (a key problem gives 401, a network block gives a timeout). Fix: redeploy or recreate it in API Manager.
- Provider
401 invalid subscription key — Likely cause: provider key rotated. Fix: refresh it on the proxy and in the secret store.
- Provider
429 rate_limit_exceeded — Likely cause: the deployment's tokens-per-minute ceiling versus very large agent turns (tens of thousands of tokens), not the gateway. Fix: raise provider capacity.
- Requests visible, tokens read 0, auth accepts anything — Likely cause: enhanced Model Proxy instance not applying configuration. Fix: recreate as a classic LLM proxy with the same chain and rerun step 7.
- Client-ID policy attached but RPC POST returns 200 without credentials — Likely cause:
methodRegex pointcut ignored. Fix: uriTemplateRegex ^/$.
- Card
GET returns 401 — Likely cause: blanket pointcut. Fix: scope to ^/$.
- A2A policy family missing — Likely cause: card published as "Other" or Protocol not A2A. Fix: publish as "A2A v1.0" after stripping legacy fields.
- Every real call rejected
-32601 or -32602 — Likely cause: Schema Validation expects SendMessage and ROLE_USER, while the agent speaks message/send and role:user. Fix: disable it for that agent, or have callers use the transcoded dialect.
- PII still appears with the PII Detector applied — Likely cause: default detect-only, no entities. Fix: Action Mask plus entities, in the UI.
- Policy add by API returns 400 — Likely cause: API apply is gated for A2A. Fix: use the UI.
- Dashboards empty — Likely cause: ingestion lag or no traffic; gateway logs are error-only. Fix: wait, and send scheduled traffic.
- Hand-started agent dies at once — Likely cause: a supervisor already owns the port. Fix: cycle the supervisor, not a bare process.