From 5e5d082cf4c5fe0a6ca7d8a9775ca68b57f8e95f Mon Sep 17 00:00:00 2001 From: Christopher Hertel Date: Sat, 4 Jan 2025 19:20:39 +0100 Subject: [PATCH] chore: add logging to tool executor --- src/Chain/ToolBox/ToolBox.php | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/Chain/ToolBox/ToolBox.php b/src/Chain/ToolBox/ToolBox.php index 2c09a4b7..2a6a2c65 100644 --- a/src/Chain/ToolBox/ToolBox.php +++ b/src/Chain/ToolBox/ToolBox.php @@ -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 { @@ -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; } @@ -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); }