From a38fe7e72da849d443d37f37f4524ca72793325f Mon Sep 17 00:00:00 2001 From: Simon Kuehn Date: Mon, 18 May 2026 07:28:21 +0000 Subject: [PATCH] fix: use web search in SpecsResearchAgent to prevent spec hallucination MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The agent was calling generate() — pure model memory — which caused Mistral to hallucinate specs for older devices (e.g. i5-1135G7 instead of i3-3120M). generateWithWebSearch() is now used so Mistral queries live sources. OllamaClientInterface gains generateWithWebSearch(); OllamaClient falls back to generate() since Ollama has no built-in search tool. Co-Authored-By: Claude Sonnet 4.6 --- src/Infrastructure/AI/Agent/SpecsResearchAgent.php | 2 +- src/Infrastructure/AI/OllamaClient.php | 5 +++++ src/Infrastructure/AI/OllamaClientInterface.php | 3 +++ 3 files changed, 9 insertions(+), 1 deletion(-) diff --git a/src/Infrastructure/AI/Agent/SpecsResearchAgent.php b/src/Infrastructure/AI/Agent/SpecsResearchAgent.php index 2e4c635..9337669 100644 --- a/src/Infrastructure/AI/Agent/SpecsResearchAgent.php +++ b/src/Infrastructure/AI/Agent/SpecsResearchAgent.php @@ -25,7 +25,7 @@ final class SpecsResearchAgent 'subject' => $subject, ]); - $result = $this->client->generate($this->model, $prompt); + $result = $this->client->generateWithWebSearch($this->model, $prompt); if ('' === trim($result)) { throw new \RuntimeException("No specifications found for model: {$modelName}"); diff --git a/src/Infrastructure/AI/OllamaClient.php b/src/Infrastructure/AI/OllamaClient.php index af97ad8..038ca12 100644 --- a/src/Infrastructure/AI/OllamaClient.php +++ b/src/Infrastructure/AI/OllamaClient.php @@ -50,4 +50,9 @@ final class OllamaClient implements OllamaClientInterface return $data['response']; } + + public function generateWithWebSearch(string $model, string $prompt): string + { + return $this->generate($model, $prompt); + } } diff --git a/src/Infrastructure/AI/OllamaClientInterface.php b/src/Infrastructure/AI/OllamaClientInterface.php index 4ff78c2..ebfb56f 100644 --- a/src/Infrastructure/AI/OllamaClientInterface.php +++ b/src/Infrastructure/AI/OllamaClientInterface.php @@ -9,4 +9,7 @@ interface OllamaClientInterface public function generate(string $model, string $prompt): string; public function generateWithImage(string $model, string $prompt, string $imagePath): string; + + /** Generates with web search if the backend supports it, falls back to generate(). */ + public function generateWithWebSearch(string $model, string $prompt): string; }