A migration plan for moving a MuleSoft Agent Fabric agent network from v1 (schemaVersion 1.0.0 agent-network.yaml, generated Mule broker) to Agent Network 2.0 (agentNetwork 2.0.0 with kind AgentScript brokers in brokers/*.agent). Covers generating v2 from v1 so behavior stays the source of truth, porting instructions, A2A links and MCP allowlists one to one, declaring governance policies (kill switch, rogue agent detection, regex prompt guard, PII guards, token rate limit, CORS, A2A schema validation) in the project YAML, per-broker LLM connections for metering, a semantic-routing pilot, the A2A 0.3 to 1.0 client change, and running both networks side by side with distinct names, gateways, and paths until cutover. Includes real v1 vs v2 snippets, deterministic checks, rollout phases, and troubleshooting for gateway capacity, stale publish artifacts, LLM 404s, and metering gaps.
Tags: broker, cross-industry, flex-gateway, agent-script, blue-green, llm-metering, governance, a2a, migration, semantic-routing, agent-network, anypoint-cli, mcp, agent-fabric
Agent Fabric v1 to v2 Broker Migration: Agent Script, Declared Governance, and Side-by-Side Cutover
Deliverable: A v2 Agent Network project (agentNetwork: 2.0.0) that reproduces your v1 broker network as Agent Script brokers, with governance policies declared in YAML, one metered LLM connection per broker, and a semantic-routing pilot. It runs next to v1 until a measured cutover, with v1 untouched as the rollback.
Objective: A v1 network (schemaVersion: 1.0.0, brokers described by an LLM spec and compiled into a generated Mule app) works, but its governance is attached by hand in API Manager and lost on redeploy, its LLM calls show zero tokens in cost views, and its model choice is invisible to the platform. v2 expresses brokers as Agent Script programs and declares policies in the project file. The risk is a cutover that silently changes broker behavior, the client protocol (A2A 0.3 to 1.0), or gateway capacity. This plan treats v1 as the behavioral source of truth, generates v2 from it, and proves parity before any client moves.
What's Getting Built
- v1 network (kept, unchanged) —
agent-network.yaml with brokers, agents, mcpServers, connections; A2A 0.3 · POST /<broker>/ (message/send)
- Generator script (build tooling you write; for example
make_v2_agentscript.py) — reads v1 YAML and writes the whole v2 project (registry, connections, policies, brokers, exchange.json variables and one .agent file per broker), so v2 is never hand-edited
- v2 project —
agent-network.yaml (registry, context.connections, context.policies, brokers), exchange.json (descriptor, pinned policy dependencies, variables), one brokers/<name>_as.agent per broker.
- Six Agent Script brokers (example shape: margin guardrail, persona/concept, supply shock, order validation, shelf recovery, supplier resilience) — each is trigger, one orchestrator, echo ·
POST /<broker>_as/ (SendMessage, A2A 1.0)
- 12 A2A agents and 11 MCP servers (shared) — 24
context.connections, named <name>_as_conn.
- Declared policies — kill switch, rogue agent detection, regex prompt guard, LLM PII detection, token rate limit,
llm-proxy-core, semantic routing (pilot only), CORS, A2A schema validation, A2A PII guard.
- Per-broker LLM connections (
llm_<broker>_as_conn) and a second Flex Gateway dedicated to v2.
Prerequisites
- Anypoint org with Agent Fabric, API Manager, Flex Gateway (CloudHub 2.0), and the
llmProxy entitlement (without it, LLM metering stays at zero).
- A current Agent Fabric CLI plugin with Agent Network 2.0
project build | publish | deploy.
- An LLM endpoint the gateway can reach; allowlist egress IPs if it is firewalled.
- A regression prompt set per broker (skill examples plus fail-closed and answer-shape cases) and the LLM key supplied at deploy time from a secret store.
Choose your path
- Generate v2 from v1 (this plan) — Choose this when v1 behavior is proven and v2 should be a mechanical port.
- Hand-author v2 — Choose this when redesigning broker logic.
Architecture
1. Freeze v1 and generate v2
- Leave v1 as is. Capture a baseline run of the regression prompts (state, answer shape, tool calls); without it "v2 works" means nothing. The generator carries over
instructions, links, allowed tools, loop, error, and timeout limits, and the model.
- Generate
v2/agent-network.yaml, v2/exchange.json, and v2/brokers/<broker>_as.agent from v1. Treat them as read-only so the two cannot drift.
- Suffix every registry key, connection, broker, and Exchange asset (
_as) so both networks coexist.
- Each v1 agent becomes
registry.agents.<name>_as and must carry an interfaces.a2a card. Each MCP server keeps its tools with transport.kind: streamableHttp. Emit one context.connections entry per registry entry with url: ${<name>.url} and a matching exchange.json variable; the LLM key variable is a secret with an empty default.
- Pin the model per broker in the generator; in some runtimes the registry LLM's model list wins over
.agent model:.
project build is your validator: it checks the schema, compiles each .agent, matches trigger targets to broker keys, resolves connections, and validates every policy configuration against its published schema.json.
2. Port each broker to Agent Script
v1 (trimmed):
brokers:
margin_guardrail:
card: { protocolVersion: 0.3.0, name: margin-guardrail }
spec:
llm: { ref: { name: open-ai }, configuration: { model: gpt-4o } }
instructions:
- >-
FAIL-CLOSED RULE: if any agent or MCP tool returns no data, return
state input-required and do not fabricate values.
links:
- agent: { ref: { name: margin_analyst_agent },
headersToPropagate: [traceparent, X-Correlation-Id] }
tools:
- mcp: { ref: { name: trade_spend_mcp },
allowed: [analyze_promotion, calculate_roi, block_promotion] }
maxNumberOfLoops: 12 # plus maxConsecutiveErrors, taskTimeoutSecs
v2 (trimmed, dialect AGENTFABRIC=1.2):
# @dialect: AGENTFABRIC=1.2
config: { agent_name: "margin_guardrail_as", default_llm: @llm.broker_llm }
llm:
broker_llm: { target: "llm://llm_margin_guardrail_as_conn", kind: "OpenAI", model: "gpt-4o" }
actions:
margin_analyst_agent: { target: "a2a://margin_analyst_agent_as_conn", kind: "a2a:send_message" }
analyze_promotion: { target: "mcp://trade_spend_mcp_as_conn", kind: "mcp:tool", tool_name: "analyze_promotion" }
# calculate_roi, block_promotion: same mcp:tool shape
trigger brokerTrigger:
kind: "a2a"
target: "brokers://margin_guardrail_as/a2a"
on_message: ->
transition to @orchestrator.main
orchestrator main:
system:
instructions: |
FAIL-CLOSED RULE: if any agent or MCP tool returns no data, return state input-required ...
reasoning:
instructions: ->
| {!@request.payload.message.parts[0].text}
actions:
margin_analyst_agent: @actions.margin_analyst_agent
analyze_promotion: @actions.analyze_promotion
# calculate_roi, block_promotion: same pattern
max_number_of_loops: 12 # plus max_consecutive_errors, task_timeout_secs
on_exit: ->
transition to @echo.answer
echo answer:
kind: "a2a:status_update_event"
state: "TASK_STATE_COMPLETED"
message: a2a.message({messageId: uuid(), parts: [a2a.textPart(@orchestrator.main.output)]})
- Instructions carry over verbatim. v1
links become a2a:send_message actions; v1 allowed tools become the same mcp:tool actions under their v1 names. Allowlists stay 1:1, never wider.
- Keep the shape trigger, one orchestrator, echo. Shipped runtimes have been observed collapsing
executor and router nodes into one reasoning loop, so enforce in instructions and allowlists.
3. Declare governance policies in YAML
Declare under context.policies; bind ingress policies in brokers.<name>.policies.inbound; attach LLM-path policies to each broker's LLM connection. Versions and required fields come from each policy's schema.json.
context:
policies:
agent_kill_switch:
ref: { name: agent-kill-switch, namespace: "{mulesoft-policy-org-id}" }
configuration: { agentIdField: claims.act.sub, agentIds: '' } # blocks nobody until you quarantine
rogue_agent_detection:
ref: { name: rogue-agent-detection, namespace: "{mulesoft-policy-org-id}" }
configuration:
agentIdField: claims.act.sub
anomalies: [ {category: Prompt Injection}, {category: PII Leak}, {category: Privilege Escalation} ]
regex_prompt_guard:
ref: { name: regex-prompt-guard-policy, namespace: "{mulesoft-policy-org-id}" }
configuration:
denyPatterns:
- { name: ignore-instructions, pattern: '(?i)ignore.{0,40}(previous|above|prior).{0,40}instructions' }
llm_token_rate_limit:
ref: { name: llm-token-rate-limit, namespace: "{mulesoft-policy-org-id}" }
configuration: { maximumTokens: 2000000, timePeriodInMilliseconds: 3600000, keySelector: "#['{network-name}']" }
a2a_pii_guard:
ref: { name: a2a-v1-pii-detector, namespace: "{mulesoft-policy-org-id}" }
configuration: { entities: [US SSN, Credit Card], action: Reject }
- LLM connection: kill switch, rogue agent, regex prompt guard, LLM PII detection (
Log where legitimate prompts carry emails or phones), token rate limit. Broker ingress: CORS, A2A schema validation, A2A PII guard (Reject for SSN and card numbers).
- Move hand-attached v1 policies (for example CORS) into YAML and pin every declared policy in
exchange.json dependencies.
4. Close the identity gap
- Kill switch and rogue-agent read the agent ID from JWT claims (
claims.act.sub, the on-behalf-of actor). An anonymous ingress carries no JWT, so the selector resolves nothing: the kill switch cannot target one broker and findings show an empty agent_id.
- Either require JWT auth on ingress through an IdP with token exchange (every client then needs a token), or ask the vendor whether the selector accepts a header expression. Until then the prompt and PII guards are your enforced controls; do not claim a kill switch you have not tested.
- If a CLI build rejects
interfaces.a2a.authorization, omit it; ingress falls back to anonymous, and get-task and cancel-task are unavailable while one-shot SendMessage works.
5. LLM metering and semantic routing
- One LLM connection per broker (
llm_<broker>_as_conn), sharing one registry LLM and upstream.
- Declare
llm-proxy-core first on each, with inputFormat: openai and constant clientIdentifier, clientId, agentId (for example #['margin_guardrail_as']). The default expressions resolve to nothing when the broker presents no client credentials.
- Verify metering against a known prompt count; a provider label of
unknown is not a failure.
- Semantic routing is a pilot on one broker:
lookup routes to a small model, decision to a stronger one, and a fallback keeps today's default. Compute topic embeddings offline from real example prompts, tune the threshold on held-out prompts (0.35 worked where they scored 0.20 to 0.62), and attach it last so blocked prompts cost no embedding call.
- The policy sets routing headers rather than rewriting the body, and skips silently unless
llm-proxy-core set x-input-format. Your upstream must honor the requested model; log requested versus served. Roll back by removing the policy.
6. Gateway sizing and side-by-side deploy
- Every connection and broker is an API instance: 24 plus 6 is 30, and 6 per-broker LLM connections instead of 1 make 35. A small gateway caps at 50, so two networks cannot share one; give v2 its own.
- Sequence:
project build, project publish, project deploy. Deploy resolves brokers from the published Exchange version, so skipping publish ships a stale network; bump the exchange.json version each attempt.
- A first deploy can crash-loop about a minute on "unreachable connections" until routes load. Afterwards read back attached policies per instance and diff against the declared list.
7. Client protocol change and cutover
- v2 speaks A2A 1.0. Clients send header
A2A-Version: 1.0 (without it: HTTP 200 with JSON-RPC error -32009 "Unsupported A2A version: missing"), method SendMessage, role ROLE_USER, and read result.task.status.state == "TASK_STATE_COMPLETED" with text in result.task.status.message.parts[0].text, an artifact, or a direct result.message.
- v2 is opt-in (new gateway,
/<broker>_as/ paths); v1 clients change nothing. Allow A2A-Version and traceparent in the CORS preflight.
- Move one client at a time; retire v1 only later, by an explicitly confirmed
project undeploy (dry-run first).
8. Security and compliance
- Three layers: ingress, LLM connection, per-broker allowlists. A migration must never widen an allowlist.
- No keys in YAML, defaults, scripts, or logs; never log the matched value of a rejected request, only the pattern or type name. Policy changes go through the generator and a reviewed diff.
Sample payload - A2A 1.0 request and completed response
{"jsonrpc":"2.0","id":"{message-id}","method":"SendMessage",
"params":{"message":{"messageId":"{message-id}","role":"ROLE_USER",
"parts":[{"text":"Analyze promotion {promotion-id}. Should we run it?"}]}}}
Header A2A-Version: 1.0. Completed answer:
{"jsonrpc":"2.0","id":"{message-id}",
"result":{"task":{"status":{"state":"TASK_STATE_COMPLETED",
"message":{"parts":[{"text":"{\"verdict\":\"BLOCKED\",\"net_roi\":0.46,\"roi_threshold\":1.5}"}]}}}}}
Deterministic checks
project build exits 0 with no schema, trigger-target, connection, or policy-schema errors; regenerating from unchanged v1 yields a byte-identical v2 tree.
- Each v2 broker's actions equal its v1
links plus allowed tools exactly; loop, error, and timeout limits match.
- Each broker's agent card returns
200, and one skill-example prompt per broker returns TASK_STATE_COMPLETED.
- A request without
A2A-Version: 1.0 gets -32009, not processing.
- A prompt with a specimen SSN is rejected at ingress (HTTP 403,
-32600). A canary prompt that matches the ignore-instructions deny pattern (keep the exact string in your test fixtures, not in this plan) is blocked by the regex guard before any upstream call; the client sees TASK_STATE_FAILED.
- Policy read-back per instance equals the declared list (routing only on the pilot connection).
- Unparseable or out-of-policy model output, or an empty tool result, yields input-required (naming the missing ID) or failed, never a fabricated field or substituted record.
- Platform LLM token totals match the upstream log; the v1 regression suite still passes unchanged.
Testing and validation
- Parity: replay the baseline on both; compare state, answer keys, and tools called. Wording may differ.
- Edge case that breaks naive ports: parallel tool calls. A proxy converting between response formats can split them into separate assistant messages, which Azure OpenAI rejects with 400 ("tool_calls must be followed by tool messages"); the client sees only a generic failed task. Test a two-tool prompt.
- Repeat the set: loop-iteration ceilings make multi-tool prompts flaky; track pass rate and reduce tools per broker.
- Governance drill: send an injection prompt, confirm rejection and the finding, quarantine and restore, and record whether the agent ID populated.
- Pre-flight before each deploy: upstream health, LLM ping with non-zero tokens, gateway
APPLIED, deployments RUNNING.
Phased rollout
Phase 1 - Connect
- Capture baselines, create the v2 gateway, write the generator, deploy with policies, and prove one broker.
Phase 2 - Map and validate
- Run parity and governance suites, verify metering, pilot routing on one broker, resolve the identity gap. Fix gaps in the generator.
Phase 3 - Production
- Move clients one at a time, keep v1 warm for an agreed window, then retire it with a confirmed step.
Success metrics
- Regression parity pass rate on v2 versus the v1 baseline, and run-to-run stability.
- Task completion rate, p50 and p95 latency, and loop-limit failures per broker.
- Share of LLM tokens attributed to a named broker (v1 reported none), and declared-versus-attached policy drift (target zero).
Troubleshooting
- Deploy fails
3055, connections unregistered — Likely cause: two networks exceeding one gateway's instance cap. Fix: give v2 its own gateway, undeploy, redeploy.
- Fixed source, but the deployed broker crash-loops on the old bug — Likely cause: deploy used a cached build or older published version. Fix: build, publish a bumped version, deploy.
3025 on every broker after one 429, or 3018 timeout — Likely cause: fixed retry cap and 15-minute client watch; brokers may be healthy. Fix: find the first real failure, wait out the rate limit, re-run.
- Broker crash-loops with LLM
HTTP 404 — Likely cause: the LLM instance upstream was registered as a bare host but the provider serves under a path like /openai/v1/ (403 means firewall). Fix: patch the upstream, redeploy that API instance so the gateway re-syncs (a broker restart alone does not), wait about 90 seconds, restart the broker.
- LLM tokens read 0 — Likely cause: hand-made proxy without the default policy chain, missing
llmProxy entitlement, or no llm-proxy-core. Fix: let the v2 deploy create the LLM instance and declare the policy.
- Rogue-agent finding has an empty agent — Likely cause: anonymous ingress. Fix: Step 4.
- Routing logs "skipping" or the default always serves — Likely cause: no
x-input-format, or the upstream ignores the model header. Fix: llm-proxy-core first; make the upstream honor the requested model.
- Routing policy crash-loops the gateway — Likely cause: very large embedding payload. Fix: fewer examples per topic, rounded vectors, or remove the policy.