Skip to content
This repository was archived by the owner on Jul 16, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Chain/ToolBox/ToolBox.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace PhpLlm\LlmChain\Chain\ToolBox;

use PhpLlm\LlmChain\Exception\RuntimeException;
use PhpLlm\LlmChain\Exception\ToolNotFoundException;
use PhpLlm\LlmChain\Model\Response\ToolCall;

final class ToolBox implements ToolBoxInterface
Expand Down Expand Up @@ -55,6 +55,6 @@ public function execute(ToolCall $toolCall): string
}
}

throw new RuntimeException('Tool not found');
throw ToolNotFoundException::forToolCall($toolCall);
}
}
15 changes: 15 additions & 0 deletions src/Exception/ToolNotFoundException.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

declare(strict_types=1);

namespace PhpLlm\LlmChain\Exception;

use PhpLlm\LlmChain\Model\Response\ToolCall;

final class ToolNotFoundException extends RuntimeException
{
public static function forToolCall(ToolCall $toolCall)
{
return new self(sprintf('Tool not found for call: %s', $toolCall->name));
}
}
10 changes: 10 additions & 0 deletions tests/Chain/ToolBox/ToolBoxTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace PhpLlm\LlmChain\Tests\Chain\ToolBox;

use PhpLlm\LlmChain\Exception\ToolNotFoundException;
use PhpLlm\LlmChain\Chain\ToolBox\Attribute\AsTool;
use PhpLlm\LlmChain\Chain\ToolBox\Metadata;
use PhpLlm\LlmChain\Chain\ToolBox\ParameterAnalyzer;
Expand Down Expand Up @@ -101,6 +102,15 @@ public function toolsMap(): void
self::assertSame(json_encode($expected), json_encode($actual));
}

#[Test]
public function executeWithUnknownTool(): void
{
self::expectException(ToolNotFoundException::class);
self::expectExceptionMessage('Tool not found for call: foo_bar_baz');

$this->toolBox->execute(new ToolCall('call_1234', 'foo_bar_baz'));
}

#[Test]
public function execute(): void
{
Expand Down
Loading