Testing utilities and helpers for AgentForge framework
npm install @agentforge/testing> Testing utilities and helpers for the AgentForge framework



Complete testing toolkit | Full TypeScript support | Comprehensive documentation
``bash`
npm install --save-dev @agentforge/testingor
pnpm add -D @agentforge/testingor
yarn add -D @agentforge/testing
- ๐ญ Mock Factories - Create mock LLMs, tools, and states for testing
- ๐ง Test Helpers - Assertion helpers and state builders
- ๐ฆ Fixtures - Pre-built sample agents, tools, and conversations
- ๐ Test Runners - Agent test runner and conversation simulator
- ๐ธ Snapshot Testing - State and message snapshot utilities
- โ
Full TypeScript - Complete type safety and inference
- ๐งช Vitest Integration - Works seamlessly with Vitest
`typescript
import { describe, it, expect } from 'vitest';
import {
createMockLLM,
createMockTool,
createStateBuilder,
createAgentTestRunner,
assertMessageContains,
} from '@agentforge/testing';
describe('My Agent', () => {
it('should respond to greetings', async () => {
// Create mock LLM
const llm = createMockLLM({
responses: ['Hello! How can I help you?']
});
// Create test state
const state = createStateBuilder()
.addHumanMessage('Hi')
.build();
// Run agent
const runner = createAgentTestRunner(agent);
const result = await runner.run(state);
// Assert
expect(result.passed).toBe(true);
assertMessageContains(result.messages, 'Hello');
});
});
`
Create mock language models for testing:
`typescript
import { createMockLLM, createEchoLLM, createErrorLLM } from '@agentforge/testing';
// Basic mock with predefined responses
const llm = createMockLLM({
responses: ['Response 1', 'Response 2']
});
// Echo LLM (echoes input)
const echoLLM = createEchoLLM();
// Error LLM (always throws)
const errorLLM = createErrorLLM('Custom error message');
// Custom response generator
const customLLM = createMockLLM({
responseGenerator: (messages) => {
const lastMsg = messages[messages.length - 1];
return You said: ${lastMsg.content};`
}
});
Create mock tools for testing:
`typescript
import { createMockTool, createEchoTool, createCalculatorTool } from '@agentforge/testing';
import { z } from 'zod';
// Basic mock tool
const tool = createMockTool({
name: 'my_tool',
schema: z.object({ input: z.string() }),
implementation: async ({ input }) => Processed: ${input}
});
// Echo tool
const echoTool = createEchoTool();
// Calculator tool
const calcTool = createCalculatorTool();
`
Build test states easily:
`typescript
import { createStateBuilder } from '@agentforge/testing';
const state = createStateBuilder()
.addHumanMessage('Hello')
.addAIMessage('Hi there!')
.set('customField', 'value')
.build();
`
Helpful assertion functions:
`typescript
import {
assertMessageContains,
assertLastMessageContains,
assertToolCalled,
assertCompletesWithin,
} from '@agentforge/testing';
// Assert message contains text
assertMessageContains(messages, 'hello');
// Assert last message contains text
assertLastMessageContains(messages, 'goodbye');
// Assert tool was called
assertToolCalled(toolCalls, 'calculator', { operation: 'add' });
// Assert completes within time
await assertCompletesWithin(async () => {
await agent.invoke(input);
}, 1000);
`
Pre-built test data:
`typescript
import {
simpleGreeting,
multiTurnConversation,
sampleTools,
calculatorTool,
} from '@agentforge/testing';
// Use sample conversations
const messages = simpleGreeting;
// Use sample tools
const tools = sampleTools;
`
Run integration tests on agents:
`typescript
import { createAgentTestRunner } from '@agentforge/testing';
const runner = createAgentTestRunner(agent, {
timeout: 5000,
captureSteps: true,
validateState: true,
});
const result = await runner.run({ messages: [new HumanMessage('Test')] });
expect(result.passed).toBe(true);
expect(result.executionTime).toBeLessThan(5000);
`
Simulate multi-turn conversations:
`typescript
import { createConversationSimulator } from '@agentforge/testing';
const simulator = createConversationSimulator(agent, {
maxTurns: 5,
verbose: true,
stopCondition: (messages) => {
const lastMsg = messages[messages.length - 1];
return lastMsg.content.includes('goodbye');
}
});
const result = await simulator.simulate([
'Hello',
'What can you do?',
'Help me with a task'
]);
expect(result.completed).toBe(true);
expect(result.turns).toBe(3);
`
Create and compare state snapshots:
`typescript
import {
createSnapshot,
assertMatchesSnapshot,
compareStates,
createStateDiff,
} from '@agentforge/testing';
// Create snapshot
const snapshot = createSnapshot(state, {
normalizeTimestamps: true,
normalizeIds: true,
excludeFields: ['_internal']
});
// Assert matches snapshot
assertMatchesSnapshot(state);
// Compare states
const isEqual = compareStates(state1, state2);
// Create diff
const diff = createStateDiff(stateBefore, stateAfter);
console.log(diff.changed); // { field: { from: 'old', to: 'new' } }
`
`typescript
import { describe, it, expect } from 'vitest';
import {
createMockLLM,
createMockTool,
createStateBuilder,
createAgentTestRunner,
createConversationSimulator,
assertMessageContains,
assertToolCalled,
assertMatchesSnapshot,
} from '@agentforge/testing';
import { createReActAgent } from '@agentforge/patterns';
describe('ReAct Agent Integration Tests', () => {
const llm = createMockLLM({
responses: [
'I need to use the calculator tool.',
'The result is 4.'
]
});
const calculatorTool = createMockTool({
name: 'calculator',
implementation: async ({ operation, a, b }) => {
if (operation === 'add') return ${a + b};
return '0';
}
});
const agent = createReActAgent({
llm,
tools: [calculatorTool],
});
it('should use tools to solve problems', async () => {
const runner = createAgentTestRunner(agent, {
timeout: 5000,
captureSteps: true
});
const state = createStateBuilder()
.addHumanMessage('What is 2 + 2?')
.build();
const result = await runner.run(state);
expect(result.passed).toBe(true);
assertMessageContains(result.messages, 'calculator');
assertToolCalled(result.finalState.toolCalls, 'calculator');
});
it('should handle multi-turn conversations', async () => {
const simulator = createConversationSimulator(agent, {
maxTurns: 3,
verbose: false
});
const result = await simulator.simulate([
'Hello',
'Calculate 5 + 3',
'Thank you'
]);
expect(result.completed).toBe(true);
expect(result.turns).toBe(3);
assertMatchesSnapshot(result.messages);
});
});
`
- createMockLLM(config?) - Create a mock LLMcreateEchoLLM()
- - Create an echo LLMcreateErrorLLM(message?)
- - Create an error LLMcreateMockTool(config?)
- - Create a mock toolcreateEchoTool(name?)
- - Create an echo toolcreateCalculatorTool()
- - Create a calculator tool
- createStateBuilder() - Create a state buildercreateConversationState(messages)
- - Create conversation statecreateReActState(config?)
- - Create ReAct agent statecreatePlanningState(config?)
- - Create planning agent state
- assertMessageContains(messages, content) - Assert message contains textassertLastMessageContains(messages, content)
- - Assert last message contains textassertToolCalled(toolCalls, name, args?)
- - Assert tool was calledassertCompletesWithin(fn, maxMs)
- - Assert completes within timeassertStateHasFields(state, fields)
- - Assert state has fieldsassertMatchesSnapshot(state, config?)
- - Assert matches snapshot
- createAgentTestRunner(agent, config?) - Create agent test runnercreateConversationSimulator(agent, config?)
- - Create conversation simulator
- simpleGreeting - Simple greeting conversationmultiTurnConversation
- - Multi-turn conversationsampleTools
- - Array of sample toolscalculatorTool
- - Calculator toolsearchTool` - Search tool
-
- ๐ Full Documentation
- ๐ Quick Start
- ๐งช Testing API Reference
- ๐ก Testing Tutorial
- GitHub Repository
- npm Package
- Changelog - See what's new before upgrading
- Report Issues
- @agentforge/core - Core abstractions
- @agentforge/patterns - Agent patterns
- @agentforge/tools - Standard tools
- @agentforge/cli - CLI tool
MIT ยฉ 2026 Tom Van Schoor