harden runner errors

This commit is contained in:
team2
2026-02-16 22:39:07 +01:00
parent 825a63c530
commit 34e3d8139e

View File

@@ -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';
}
// ---------------------------------------------------------
@@ -130,7 +139,7 @@ final readonly class AgentRunner
'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();
}
}
}