Testing
Testing your workflows and agents ensures they are configured correctly before you deploy them. The Culvii Kit makes it easy to write unit tests for your workflow definitions and mock the engine for local testing.
Testing step configurations
You can test a Step by verifying its generated JSON configuration. This ensures your steps are wired up with the correct parameters and connections.
import { Step } from '@culvii/kit';
import { expect, test } from 'vitest';
const formatNameStep = new Step({
name: 'Format Name',
type: 'core.set',
params: {
values: {
formattedName: 'ALICE'
}
}
});
test('generates correct step configuration', () => {
const config = formatNameStep.toJSON();
expect(config.name).toBe('Format Name');
expect(config.type).toBe('core.set');
expect(config.nodeParams.values.formattedName).toBe('ALICE');
});
Mocking the Multi-Agent Engine
When testing agents that rely on the MultiAgentEngine, you don't want to make real API calls to LLM providers. You can mock the engine locally to return predictable responses.
import { MultiAgentEngine } from '@culvii/kit';
import { test, expect, vi } from 'vitest';
test('agent returns expected response', async () => {
const engine = new MultiAgentEngine({
id: 'test-agent',
name: 'Test Agent',
role: 'primary',
model: 'openai/gpt-4o',
systemPrompt: 'You are a helpful assistant.'
});
// Mock the run method
vi.spyOn(engine, 'run').mockResolvedValue({
runId: 'test-run',
output: 'This is a mocked response.',
primaryAgentId: 'test-agent',
process: [],
toolsUsed: [],
delegations: [],
agents: {}
});
const response = await engine.run('Hello');
expect(response.output).toBe('This is a mocked response.');
});
Mocking allows you to test your agent logic, error handling, and tool execution without incurring API costs or dealing with network latency.