Skip to content

2.12.0

Choose a tag to compare

@ilvalerione ilvalerione released this 08 Feb 11:27
· 44 commits to 2.x since this release

Introducing Testing Components

When you test an agent, you don't want every test run to make real API calls to OpenAI, Anthropic, or any other provider. Real calls are slow, cost money, and return different results every time, making your tests flaky and expensive. The same applies to RAG agents: you don't want to spin up a vector database or call an embeddings API just to verify your agent's logic.

This release introduces a set of "fake" components you can use to test the logic of your agentic system without the need to access real providers. FakeAIProvider replaces the AI provider, FakeEmbeddingsProvider replaces the embeddings provider, and FakeVectorStore replaces the vector store. They return predetermined responses, never hit the network, and record every interaction so you can assert exactly what your agent did.

Here is an example of a test you can create to prove the consistency of your implementation:

use NeuronAI\Chat\Messages\ToolCallMessage;

public function test_agent_uses_tools(): void
{
    $searchTool = Tool::make('search', 'Search the web')
        ->addProperty(new ToolProperty('query', PropertyType::STRING, 'Search query', true))
        ->setCallable(fn (string $query): string => "Results for: {$query}");

    $provider = new FakeAIProvider(
        // First call: the model asks to use the search tool
        new ToolCallMessage(null, [
            (clone $searchTool)->setCallId('call_1')->setInputs(['query' => 'PHP frameworks']),
        ]),
        // Second call: the model responds using the tool result
        new AssistantMessage('Here are the top PHP frameworks...')
    );

    $agent = MyAgent::make()
        ->setAiProvider($provider)
        ->addTool($searchTool);

    $message = $agent->chat(new UserMessage('Best PHP frameworks?'))->getMessage();

    $this->assertSame('Here are the top PHP frameworks...', $message->getContent());
    $provider->assertCallCount(2);
}

Check out the full documentation.