diff --git a/src/Agent/AgentRunner.php b/src/Agent/AgentRunner.php index 3a3f742..c115bb9 100644 --- a/src/Agent/AgentRunner.php +++ b/src/Agent/AgentRunner.php @@ -26,7 +26,9 @@ final readonly class AgentRunner private bool $debug, private bool $logPrompt, private bool $logContext, - ) {} + ) + { + } public function run(string $prompt, string $userId): Generator { @@ -88,7 +90,12 @@ final readonly class AgentRunner $chunker = new StreamChunker(); foreach ($this->ollamaClient->stream($finalPrompt) as $token) { - $cleanToken = $this->thinkSuppressor->filter($token); + + if (!is_string($token)) { + continue; + } + + $cleanToken = $this->thinkSuppressor->filter((string)$token); if ($cleanToken === '') { continue; @@ -108,6 +115,8 @@ final readonly class AgentRunner $finalChunk = $chunker->flush(); if ($finalChunk !== null) { yield $finalChunk; + } else { + yield '... no data received from llm'; } // --------------------------------------------------------- @@ -120,17 +129,17 @@ final readonly class AgentRunner ); $this->agentLogger->info('Agent run finished', [ - 'userId' => $userId, + 'userId' => $userId, 'outputLength' => mb_strlen($fullOutput), - 'contextMode' => 'recent', + 'contextMode' => 'recent', ]); } catch (Throwable $e) { $this->agentLogger->error('Agent run failed', [ - 'userId' => $userId, + 'userId' => $userId, 'exception' => $e, ]); - yield "\n❌ An internal error occurred while processing the request."; + yield "\n❌ An internal error occurred while processing the request. \nError: " . $e->getMessage(); } } }