Mock LLM Backend
backends/mock-llm
Section titled “backends/mock-llm”Interfaces
Section titled “Interfaces”MockLLMBackendOptions
Section titled “MockLLMBackendOptions”Defined in: types/backends.ts:35
Options for Mock LLM backend
Properties
Section titled “Properties”finishReason?
Section titled “finishReason?”
optionalfinishReason:string
Defined in: types/backends.ts:45
Override finishReason in done events (default: “stop”)
latency?
Section titled “latency?”
optionallatency:MockLLMLatency
Defined in: types/backends.ts:41
Latency simulation — delay before each response
optionalmode:MockLLMResponseMode
Defined in: types/backends.ts:37
Response mode configuration
models?
Section titled “models?”
optionalmodels:object[]
Defined in: types/backends.ts:39
Models to advertise from listModels()
description?
Section titled “description?”
optionaldescription:string
id:
string
optionalname:string
permissions?
Section titled “permissions?”
optionalpermissions:MockLLMPermissionOptions
Defined in: types/backends.ts:47
Permission simulation for tool calls
streaming?
Section titled “streaming?”
optionalstreaming:MockLLMStreamingOptions
Defined in: types/backends.ts:43
Streaming behavior control
structuredOutput?
Section titled “structuredOutput?”
optionalstructuredOutput:unknown
Defined in: types/backends.ts:51
Structured output — return specific JSON from runStructured()
toolCalls?
Section titled “toolCalls?”
optionaltoolCalls:MockLLMToolCall[]
Defined in: types/backends.ts:49
Tool call simulation — emit tool_call_start/end events during streaming
MockLLMPermissionOptions
Section titled “MockLLMPermissionOptions”Defined in: types/backends.ts:75
Permission simulation options
Properties
Section titled “Properties”autoApprove?
Section titled “autoApprove?”
optionalautoApprove:boolean
Defined in: types/backends.ts:79
Auto-approve all permission requests (default: false — uses supervisor callback)
denyTools?
Section titled “denyTools?”
optionaldenyTools:string[]
Defined in: types/backends.ts:81
Tool names to always deny
toolNames
Section titled “toolNames”toolNames:
string[]
Defined in: types/backends.ts:77
Tool names to simulate permission requests for
MockLLMStreamingOptions
Section titled “MockLLMStreamingOptions”Defined in: types/backends.ts:67
Streaming chunk control
Properties
Section titled “Properties”chunkDelayMs?
Section titled “chunkDelayMs?”
optionalchunkDelayMs:number
Defined in: types/backends.ts:71
Delay in ms between chunks (default: 0)
chunkSize?
Section titled “chunkSize?”
optionalchunkSize:number
Defined in: types/backends.ts:69
Characters per chunk (default: word-boundary splitting)
MockLLMToolCall
Section titled “MockLLMToolCall”Defined in: types/backends.ts:85
Tool call simulation — emitted as tool_call_start/end events in stream
Properties
Section titled “Properties”
optionalargs:Record<string,unknown>
Defined in: types/backends.ts:89
Tool call arguments
result?
Section titled “result?”
optionalresult:unknown
Defined in: types/backends.ts:91
Tool execution result
toolCallId?
Section titled “toolCallId?”
optionaltoolCallId:string
Defined in: types/backends.ts:93
Tool call ID (auto-generated if not provided)
toolName
Section titled “toolName”toolName:
string
Defined in: types/backends.ts:87
Tool name (e.g. “bash”, “file_write”)
Type Aliases
Section titled “Type Aliases”MockLLMLatency
Section titled “MockLLMLatency”MockLLMLatency = {
ms:number;type:"fixed"; } | {maxMs:number;minMs:number;type:"random"; }
Defined in: types/backends.ts:62
Latency simulation configuration
MockLLMResponseMode
Section titled “MockLLMResponseMode”MockLLMResponseMode = {
type:"echo"; } | {response:string;type:"static"; } | {loop?:boolean;responses:string[];type:"scripted"; } | {code?:string;error:string;recoverable?:boolean;type:"error"; }
Defined in: types/backends.ts:55
Response mode — determines how the mock agent generates responses
Functions
Section titled “Functions”createMockLLMService()
Section titled “createMockLLMService()”createMockLLMService(
options?):IAgentService
Defined in: backends/mock-llm.ts:418
Create a mock LLM backend service for automated testing.
Unlike the lightweight createMockAgentService (from @witqq/agent-sdk/testing),
this backend extends BaseAgent and participates in the full agent lifecycle:
retry, heartbeat, activity timeout, middleware pipeline, and usage enrichment.
Parameters
Section titled “Parameters”options?
Section titled “options?”Returns
Section titled “Returns”Example
Section titled “Example” import { createMockLLMService } from "@witqq/agent-sdk/mock-llm";
// Basic echo mode const service = createMockLLMService({ mode: { type: "echo" } });
// With latency simulation and streaming control const realisticService = createMockLLMService({ mode: { type: "static", response: "Hello!" }, latency: { type: "fixed", ms: 100 }, streaming: { chunkSize: 5, chunkDelayMs: 10 }, finishReason: "stop", });
// With permission simulation const permService = createMockLLMService({ mode: { type: "echo" }, permissions: { toolNames: ["bash", "file_write"], autoApprove: true }, });