Skip to content
This repository was archived by the owner on Jul 16, 2025. It is now read-only.
Merged
Changes from all commits
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
5 changes: 5 additions & 0 deletions src/Chain/ToolBox/ToolBox.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@

use PhpLlm\LlmChain\Exception\ToolBoxException;
use PhpLlm\LlmChain\Model\Response\ToolCall;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;

final class ToolBox implements ToolBoxInterface
{
Expand All @@ -25,6 +27,7 @@ final class ToolBox implements ToolBoxInterface
public function __construct(
private readonly ToolAnalyzer $toolAnalyzer,
iterable $tools,
private readonly LoggerInterface $logger = new NullLogger(),
) {
$this->tools = $tools instanceof \Traversable ? iterator_to_array($tools) : $tools;
}
Expand Down Expand Up @@ -54,8 +57,10 @@ public function execute(ToolCall $toolCall): string
}

try {
$this->logger->debug(sprintf('Executing tool "%s".', $metadata->name), $toolCall->arguments);
$result = $tool->{$metadata->method}(...$toolCall->arguments);
} catch (\Throwable $e) {
$this->logger->warning(sprintf('Failed to execute tool "%s".', $metadata->name), ['exception' => $e]);
throw ToolBoxException::executionFailed($toolCall, $e);
}

Expand Down
Loading