AI agents · · 6 min read
AI SDK 7: test a quote worker’s tools without model credits
Use a mock model and real in-memory tools to check argument validation, result handoff and loop limits before connecting an AI quote workflow.
By Sociologix Editorial

Test the handoff before connecting a live model
This AI-assisted editorial guide includes five deterministic checks run on November 18, 2026 with Node 24.19.0, ai 7.0.107 and Zod 4.6.5. All passed. The model responses are scripted, the briefs are fictional and no model provider was contacted.
A quote worker might read a project brief, identify missing requirements and prepare a draft for team approval. Before evaluating its writing, check the plumbing: does the intended tool run, do bad arguments reach your code, and does the next generation step receive the tool result?
The AI SDK supplies MockLanguageModelV4 through ai/test. It lets you prescribe model responses and inspect model calls. Our example tests the orchestration around a brief lookup; it does not generate prices, approve agreements or send a quote. [1]
1. Create an isolated test folder
Use Node 24 for the lab commands below, which include --test-isolation=none. The AI SDK release itself accepts Node 22 or newer. The vercel/ai repository is Apache-2.0 licensed. These commands pin the versions tested here; we used the project’s already-installed packages for the experiment. [4][6]
Create quote-worker.test.mjs in the new folder. Copy the two JavaScript blocks below into it, in order. The built-in Node test runner executes the assertions; no framework or provider key is required. [5]
mkdir quote-worker-lab
cd quote-worker-lab
npm init -y
npm install --save-exact ai@7.0.107 zod@4.6.5
# Save the JavaScript below as quote-worker.test.mjs
node --test --test-isolation=none quote-worker.test.mjs2. Script the model and keep the tool in memory
The harness registers one lookupBrief tool. Its Zod inputSchema requires a nonempty string ID. Its execute function returns only a fictional six-page brief or a not-found status. The SDK validates tool-call inputs against the schema before the executor receives them. [2]
Mocking the language model does not replace tool implementations. Those callbacks are real JavaScript. Keep this harness detached from email, payment and CRM executors. The fetch guard also makes an unexpected network attempt fail the run.
The token counts in usage are synthetic fields required by the mock response format. They are not measured tokens or a cost estimate. The final sentence in done is also scripted; asserting it only verifies that the supplied response comes through.
import test, { after } from 'node:test';
import assert from 'node:assert/strict';
import { ToolLoopAgent, tool, isStepCount } from 'ai';
import { MockLanguageModelV4 } from 'ai/test';
import { z } from 'zod';
let networkAttempts = 0;
globalThis.fetch = async () => {
networkAttempts++;
throw new Error('Network calls are disabled in this test');
};
after(() => assert.equal(networkAttempts, 0));
const usage = {
inputTokens: { total: 1, noCache: 1, cacheRead: undefined, cacheWrite: undefined },
outputTokens: { total: 1, text: 1, reasoning: undefined },
};
const reply = (content, reason = 'stop') => ({
content, finishReason: { unified: reason, raw: undefined }, usage, warnings: [],
});
const call = (requestId, toolName = 'lookupBrief', toolCallId = 'call-1') => reply([
{ type: 'tool-call', toolName, toolCallId, input: JSON.stringify({ requestId }) },
], 'tool-calls');
const done = reply([{ type: 'text', text: 'Brief is ready for team review.' }]);
function harness(responses) {
const executed = [];
const model = new MockLanguageModelV4({ doGenerate: responses });
const agent = new ToolLoopAgent({
model,
stopWhen: isStepCount(2),
tools: {
lookupBrief: tool({
description: 'Read a synthetic brief from the demo fixture.',
inputSchema: z.object({ requestId: z.string().min(1) }),
execute: async ({ requestId }) => {
executed.push(requestId);
return requestId === 'demo-101'
? { status: 'needs-scope-review', pages: 6 }
: { status: 'not-found' };
},
}),
},
});
return { model, executed, run: () => agent.generate({ prompt: 'Review demo-101.' }) };
}3. Assert behavior at each boundary
Append these five tests. The first checks both the actual tool output and its presence in the second model request. That catches a broken handoff even if a canned final sentence looks correct.
In the tested 7.0.107 runtime, numeric input and an unregistered sendQuote name appear as invalid tool calls in the returned first step. Both tests assert that the lookup executor was untouched. Do not assume every invalid call will reject the entire generate promise; check the behavior of your installed version.
test('a valid call reaches the tool and its result reaches the next step', async () => {
const h = harness([call('demo-101'), done]);
const result = await h.run();
assert.deepEqual(h.executed, ['demo-101']);
assert.deepEqual(result.steps[0].toolResults[0].output,
{ status: 'needs-scope-review', pages: 6 });
assert.match(JSON.stringify(h.model.doGenerateCalls[1].prompt), /needs-scope-review/);
assert.equal(result.text, 'Brief is ready for team review.');
assert.equal(h.model.doGenerateCalls.length, 2);
});
test('a numeric request ID never reaches execute', async () => {
const h = harness([call(101), done]);
const result = await h.run();
assert.deepEqual(h.executed, []);
assert.equal(result.steps[0].toolCalls[0].invalid, true);
});
test('an unregistered sendQuote tool never executes', async () => {
const h = harness([call('demo-101', 'sendQuote'), done]);
const result = await h.run();
assert.deepEqual(h.executed, []);
assert.equal(result.steps[0].toolCalls[0].invalid, true);
});
test('a missing fixture returns no other brief', async () => {
const h = harness([call('demo-999'), done]);
const result = await h.run();
assert.deepEqual(result.steps[0].toolResults[0].output, { status: 'not-found' });
});
test('repeated calls stop after two generation steps', async () => {
const h = harness([call('demo-101'), call('demo-101', 'lookupBrief', 'call-2'), done]);
const result = await h.run();
assert.equal(h.model.doGenerateCalls.length, 2);
assert.equal(h.executed.length, 2);
assert.equal(result.steps.length, 2);
assert.equal(result.text, '');
});4. Read the results without overstating them
The run produced five passes and zero failures, with no network attempts. The missing-ID case returned only not-found. It does not establish tenant authorization: a production lookup must derive the customer identity from the authenticated session and enforce access in the data layer.
The repeated-call case reached two generation steps and executed the lookup twice, then stopped with an empty final text. Treat that as an incomplete run requiring an explicit application status, not a successful customer response.
isStepCount(2) bounds generation steps in this loop. A model can request multiple tools within one step, so it is not a two-tool-call allowance or a dollar ceiling. Use separate controls for tool execution, time and spending. [3]
5. Add model evaluation as a separate launch check
Keep these tests as a repeatable check when changing schemas, tool names or SDK versions. Extend the fixture set with executor failures and application-specific access rules before attaching real integrations.
Then evaluate your chosen live model separately in staging with synthetic briefs: incomplete requirements, conflicting deadlines and requests for unapproved discounts. Check whether it selects the right tool and avoids inventing commitments. A scripted model cannot establish any of those behaviors.
For quote automation, preserve the original request, keep approval decisions in the application and record whether a draft is ready, blocked or incomplete. This harness supplies one small, testable layer before that workflow goes live.
Sources & further reading
Make your quote worker testable before launch
Sociologix can help map your intake requirements, define tool boundaries and build repeatable checks for an AI-assisted quote workflow. Bring a sample brief and the decisions your team needs to approve.
Talk to Sociologix