From 4247825528f7d0e840c574cabb783933e72c74bb Mon Sep 17 00:00:00 2001 From: team 1 Date: Fri, 17 Apr 2026 08:26:21 +0200 Subject: [PATCH] add used sources --- src/Agent/AgentRunner.php | 23 +++++++++++++++++++++-- src/Agent/PromptBuilder.php | 3 +++ 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/Agent/AgentRunner.php b/src/Agent/AgentRunner.php index 3b84c2b..620cdc3 100644 --- a/src/Agent/AgentRunner.php +++ b/src/Agent/AgentRunner.php @@ -44,6 +44,7 @@ final readonly class AgentRunner $swagFullOutPut = ''; $firstThinkLoop = true; $shopResults = []; + $sources = []; if ($prompt === '') { yield '❌ Empty prompt.'; @@ -70,13 +71,18 @@ final readonly class AgentRunner // --------------------------------------------------------- yield $this->systemMsg("Ich prüfe auf Internet Quellen...", "think"); $urlContent = $this->urlAnalyzer->extractContentFromPrompt($prompt); + if($urlContent){ + $sources[]= 'Externe URL'; + } // --------------------------------------------------------- // 3) Retrieve RAG knowledge // --------------------------------------------------------- yield $this->systemMsg("Ich hole relevante Daten aus meinem RAG Wissen...", "think"); $knowledgeChunks = $this->retriever->retrieve($prompt); - + if($knowledgeChunks){ + $sources[]= 'RAG Wissen'; + } // --------------------------------------------------------- // 4) commerce/shop search // --------------------------------------------------------- @@ -126,6 +132,10 @@ final readonly class AgentRunner } } + if($shopResults){ + $sources[]= 'Shopsystem'; + } + if ($commerceIntent === CommerceIntentLite::PRODUCT_SEARCH) { $knowledgeChunks = array_slice($knowledgeChunks, 0, 2); } elseif ($commerceIntent === CommerceIntentLite::ADVISORY_PRODUCT_SEARCH) { @@ -168,6 +178,10 @@ final readonly class AgentRunner $chunker->flush(); $this->thinkSuppressor->reset(); + if($sources){ + yield $this->systemMsg("Genutze Quellen: ".implode(', ',$sources), 'info'); + } + foreach ($this->ollamaClient->stream($finalPrompt) as $token) { if (!is_string($token)) { @@ -202,6 +216,10 @@ final readonly class AgentRunner yield $this->systemMsg('❌ Es wurden keine Daten vom LLM empfangen.', 'err'); } + if($sources){ + yield $this->systemMsg("Quellen: ".implode(', ',$sources), 'info'); + } + // --------------------------------------------------------- // 7) Persist conversation history // --------------------------------------------------------- @@ -237,7 +255,8 @@ final readonly class AgentRunner return match ($type) { 'answer' => '' . $msg, 'err' => '' . $msg . "\n
\n", - 'think' => '' . $msg . "\n" + 'think' => '' . $msg . "\n", + 'info' => "\n\n" . $msg . "\n" }; } } \ No newline at end of file diff --git a/src/Agent/PromptBuilder.php b/src/Agent/PromptBuilder.php index d6606e4..cf7a149 100644 --- a/src/Agent/PromptBuilder.php +++ b/src/Agent/PromptBuilder.php @@ -81,6 +81,7 @@ final readonly class PromptBuilder if($swagFullOutPut){ $shopBlock = "SHOP SEARCH QUERY: " . trim($swagFullOutPut)."\n"; + $shopBlock .= "Source: Shop Search\n"; } if ($shopResults !== []) { @@ -158,12 +159,14 @@ final readonly class PromptBuilder $knowledgeParts[] = "RETRIEVED KNOWLEDGE (supporting):\n" . + "Source: Documents \n". implode("\n\n", $lines); } if ($urlContent !== '') { $knowledgeParts[] = "CONTENT FROM URL (supporting):\n" . + "Source: URL \n". $urlContent; }