LLM mocks
Mock an LLM provider in A²D. An LLM mock exposes an OpenAI Responses and Chat Completions API (OpenAI, Azure OpenAI or Bedrock), an Anthropic Messages API, or a Google Gemini generateContent endpoint, so an agent or the MuleSoft Agent Network broker can point its LLM base URL at it and get deterministic, scenario-driven answers, tool calls, errors and delays. No real model or token spend is involved.
LLM mocks are in beta. Streaming (stream: true, streamGenerateContent) is supported for every format; see Streaming.
Overview
Each LLM mock has a provider (OpenAI with the openai, azure_openai or bedrock_openai flavor, Anthropic, or Gemini), a list of advertised models, an API key mode, and an ordered list of scenarios. When a request arrives, A²D normalises it (instructions, messages, tools, last tool result, turn count, structured-output schema) and evaluates the scenarios by priority. The first match produces the response. If nothing matches, the mock uses its fallback response or the built-in fallback.
Traffic is served at:
{deployment}/api/platform/{llmMockId}/llm/v1/responses # OpenAI Responses
{deployment}/api/platform/{llmMockId}/llm/v1/chat/completions # OpenAI Chat Completions
{deployment}/api/platform/{llmMockId}/llm/openai/v1/responses # Azure OpenAI
{deployment}/api/platform/{llmMockId}/llm/openai/v1/chat/completions # Azure OpenAI Chat Completions
{deployment}/api/platform/{llmMockId}/llm/v1/messages # Anthropic Messages
{deployment}/api/platform/{llmMockId}/llm/v1beta/models/{model}:generateContent # Gemini
{deployment}/api/platform/{llmMockId}/llm/v1beta/models/{model}:streamGenerateContent?alt=sse # Gemini streamingThe models endpoints (GET …/v1/models, GET …/v1beta/models) list the advertised models.
OpenAI Chat Completions
OpenAI-provider mocks (all three flavors) also serve POST …/chat/completions (and the Azure openai/deployments/{deployment}/chat/completions form). The mock reads messages (system, developer, user, assistant with tool_calls, tool), tools of type function, and response_format (json_schema or json_object), then answers with a chat.completion object: choices[0].message.content or tool_calls, finish_reason (stop or tool_calls) and usage. Errors use the OpenAI error envelope. Scenarios are shared with the Responses endpoint, so one mock serves both. The legacy /completions endpoint is not supported.
Anthropic Messages
An Anthropic mock serves POST …/v1/messages and GET …/v1/models. The key is read from the x-api-key header (the anthropic-version header is accepted and ignored). model, max_tokens and a non-empty messages array are required, as in the real API. The mock reads system (string or text blocks), messages with text, tool_use and tool_result blocks, tools, tool_choice and thinking, and answers with a message object: text, tool_use and (when thinking is enabled and the scenario has a reasoning summary) thinking blocks, stop_reason (end_turn or tool_use) and usage. A forced tool_choice combined with a structured-answer scenario returns that tool call with the answer as its input. Errors use { "type": "error", "error": { "type", "message" } }.
Streaming
Set stream: true on Responses, Chat Completions and Anthropic requests, or call Gemini :streamGenerateContent?alt=sse, to receive text/event-stream instead of JSON. The mock builds the stream from the matched scenario, so streaming and non-streaming requests return the same content.
| Format | Events |
|---|---|
| OpenAI Responses | response.created, response.in_progress, response.output_item.added, response.content_part.added, response.output_text.delta (many), response.output_text.done, function-call argument deltas, response.output_item.done, response.completed |
| Chat Completions | chat.completion.chunk objects (role, content or tool-call deltas, a final finish_reason chunk, and a usage chunk with stream_options.include_usage) followed by data: [DONE] |
| Anthropic | message_start, ping, content_block_start, content_block_delta (text_delta, input_json_delta, thinking_delta), content_block_stop, message_delta, message_stop |
| Gemini | Chunked GenerateContentResponse objects; the last chunk carries finishReason and usageMetadata |
The existing scenario and default delay apply before the first byte. For realistic cadence, a mock can also carry optional streaming timings, timeToFirstTokenMs (wait before the first delta) and chunkDelayMs (wait between deltas). Both default to 0. Set them with the streaming field of the Platform MCP design_llm_mock and update_llm_mock tools.
Error scenarios and validation errors are returned as normal JSON error responses, never as a stream.
Creating an LLM mock
Open LLM Mocks in the Design Lab section of the sidebar and click New LLM mock. Choose the provider and flavor (the provider can’t be changed after creation), name the mock, and list the models it should advertise. On the detail page:
- Scenarios — Build scenarios, or start from a broker preset (see below)
- Settings — Name, description, models, API key mode, default delay, default response headers, and draft/published status
- Connect — Base URL, auth header, and copy-ready snippets
- Playground — Send a request against the saved mock and inspect the matched scenario, warnings and delay
- Environments, Test Cases, Exploratory — Test Lab integration
API key modes
| Mode | Behaviour |
|---|---|
| Any non-empty key | Any key in the provider’s auth header is accepted (default) |
| A specific key | Only the configured key (at least 8 characters, stored hashed) is accepted |
| No key required | Requests without a key are accepted |
The auth header follows the provider: Authorization: Bearer <key> (OpenAI), api-key: <key> (Azure OpenAI), x-api-key: <key> (Anthropic), or x-goog-api-key: <key> (Gemini).
Scenarios
A scenario has a priority (lower runs first), conditions joined by AND or OR, a response, an optional delay (fixed or a random range) and optional response headers.
Condition sources: model, instructions, last_user_text, tool_available, last_tool_name, last_tool_output (with an optional JSON path), turn_count, header (by name), and body (by JSON path). Operators are the same as for REST mocks, for example ===, contains, starts_with, matches and exists.
Response kinds:
| Kind | Result |
|---|---|
text | A plain assistant message |
structured_answer | A JSON answer. With the broker schema these are the LLMOutput fields result, reasoning, goalComplete, goalFailed, additionalInputRequired and authRequired |
tool_call | A function call (MCP tools, JSON arguments) or a custom tool call (A2A tools, free-text input) |
error | A provider-shaped error with the given HTTP status, for example 429 or 503 |
Text, answers and arguments support placeholders: {{input}}, {{model}}, {{instructions}}, {{turn_count}}, {{last_tool_name}}, {{last_tool_output.path}}, {{header.name}} and {{body.path}}. Token usage is estimated unless you override it, and an optional reasoning summary can be attached to any response.
When no scenario matches, the built-in fallback returns a goalFailed structured answer if the broker schema was requested, and a short text otherwise.
Broker presets
Apply a preset from the Scenarios tab to start with a typical Agent Network broker conversation:
| Preset | What it simulates |
|---|---|
| Final answer | Completes the goal immediately, echoing the user input |
| Tool call, then answer | Calls a named tool, then answers from the tool result |
| Input required | Asks for more input on the first turn, completes afterwards |
| Goal failed | Every request reports goalFailed |
| Auth required | Reports authRequired with additionalInputRequired |
| Transient 429 / 503, then success | Exercises retry handling |
| Slow LLM | Completes after a random 3–8 second delay, to test timeouts |
Connecting a client
The Connect tab shows the base URL (the value an SDK’s baseURL takes), the auth header, and snippets for curl, the OpenAI, Anthropic or Google Gen AI SDKs (TypeScript and Python), and the Agent Network broker:
llm:
provider: openai
url: https://www.a2d-ai.com/api/platform/<llmMockId>/llm/v1
model: gpt-5-mini
apiKey: ${A2D_LLM_MOCK_KEY}import OpenAI from 'openai';
const client = new OpenAI({ apiKey: 'any-key', baseURL: 'https://www.a2d-ai.com/api/platform/<llmMockId>/llm/v1' });
const res = await client.responses.create({ model: 'gpt-5-mini', input: 'Hello' });
console.log(res.output_text);For OpenAI mocks, POST {base}/responses with an empty {} body returns 400 without needing a key, so you can use it as a connectivity probe.
Testing in the Protocol Tester
The Protocol Tester has an LLM protocol. Select an LLM mock from the asset dropdown (or paste any provider base URL, such as https://api.openai.com/v1), then fill in the provider, model, system instructions, user message, optional function tools (a JSON array), and structured output (none, the Agent Broker LLMOutput schema, or a custom JSON schema). You can also switch to Edit raw JSON body.
Click Send. LLM mode never sends automatically. The response view shows the result kind (text, structured answer, tool call or error), the broker flags, any tool call and its arguments, the reasoning summary, token usage, the raw JSON, and the headers. With Bearer auth the token is sent in the provider’s key header. With None, a placeholder key is sent, which mocks in “any key” mode accept.
The Protocol Tester’s LLM mode currently sends OpenAI Responses and Gemini generateContent requests. Chat Completions, Anthropic and streaming rendering in the tester are planned follow-ups; use curl or an SDK for those formats meanwhile.
LLM tester tabs are kept in the tab state but can’t be saved to My Library or the desktop Local Workspace yet.
Test Lab
LLM mocks take part in the Test Lab like other assets:
- Environments — The mocked environment points at the mock. Add a pre-prod or prod environment with a real provider base URL and use its API key as the bearer token to run the same tests against a real LLM.
- Test cases — Each request is sent as an OpenAI Responses or Gemini
generateContentcall. Expectations target a provider-neutral summary:kind,text,answer.<field>,toolCall.name,toolCall.arguments,reasoning,model,headers.<name>andlatencyMs, plus an optional latency window. - Materialize — Turn each scenario into a test that asserts its response kind and key fields.
- Exploratory sessions — Invited testers chat with the mock in the tester’s LLM mode and leave feedback.
Platform MCP
The Platform MCP exposes list_llm_mocks, search_llm_mocks, get_llm_mock, design_llm_mock, update_llm_mock, delete_llm_mock, duplicate_llm_mock and get_llm_mock_connection_info. The shared scenario tools (list_mock_scenarios, add_mock_scenario, update_mock_scenario, remove_mock_scenario) accept the llm_mock scope, and materialize_scenarios_to_tests, get_compliance_report and the project tools accept the llm_mock asset type.
Next Steps
- Using the Tester — Send requests to an LLM mock interactively
- Test Lab — Environments, test cases and runs
- Exploratory Testing — Invite testers to chat with a mock
- Platform MCP — Automate LLM mocks from an agent or IDE
Use LLM mocks to test agents and brokers against predictable model behaviour before you pay for real tokens.