harden retrieval logic

bugfixes
This commit is contained in:
team2
2026-04-18 21:49:30 +02:00
parent a2425b68a6
commit 5984091282
7 changed files with 426 additions and 108 deletions

View File

@@ -51,6 +51,9 @@ final readonly class AgentRunner
$shopResults = [];
$sources = [];
$optimizedShopQuery = '';
$shopSearchQuery = '';
$commerceIntent = CommerceIntentLite::NONE;
$commerceHistoryContext = '';
$this->agentLogger->info('Agent run started', [
'userId' => $userId,
@@ -97,7 +100,7 @@ final readonly class AgentRunner
$commerceHistoryContext = $this->buildCommerceHistoryContext($userId);
if($commerceHistoryContext){
if ($commerceHistoryContext !== '') {
$this->addSource($sources, 'Chatverlauf');
}
@@ -109,6 +112,16 @@ final readonly class AgentRunner
$shopSearchQuery = $optimizedShopQuery !== '' ? $optimizedShopQuery : $prompt;
$this->agentLogger->info('Commerce search prepared', [
'userId' => $userId,
'commerceIntent' => $commerceIntent,
'usedOptimizedShopQuery' => $optimizedShopQuery !== '',
'optimizedShopQuery' => $optimizedShopQuery,
'shopSearchQuery' => $shopSearchQuery,
'hasCommerceHistoryContext' => $commerceHistoryContext !== '',
'commerceHistoryContextLength' => mb_strlen($commerceHistoryContext),
]);
yield $this->systemMsg(
'Ich rufe Recherchedaten ab (type: ' . $commerceIntent . ')',
'think'
@@ -126,7 +139,9 @@ final readonly class AgentRunner
}
}
$knowledgeChunks = $this->limitKnowledgeChunks($knowledgeChunks, $commerceIntent);
if ($shopResults !== []) {
$knowledgeChunks = $this->limitKnowledgeChunks($knowledgeChunks, $commerceIntent);
}
yield $this->systemMsg('Ich analysiere alle Informationen...', 'think');
@@ -148,6 +163,7 @@ final readonly class AgentRunner
'userId' => $userId,
'finalPrompt' => $finalPrompt,
'optimizedShopQuery' => $optimizedShopQuery,
'shopSearchQuery' => $shopSearchQuery,
]);
}
@@ -198,6 +214,10 @@ final readonly class AgentRunner
'knowledgeChunkCount' => count($knowledgeChunks),
'hasUrlContent' => $urlContent !== '',
'usedOptimizedShopQuery' => $optimizedShopQuery !== '',
'optimizedShopQuery' => $optimizedShopQuery,
'shopSearchQuery' => $shopSearchQuery,
'hasCommerceHistoryContext' => $commerceHistoryContext !== '',
'commerceHistoryContextLength' => mb_strlen($commerceHistoryContext),
]);
} catch (Throwable $e) {
$this->agentLogger->error('Agent run failed', [
@@ -282,6 +302,8 @@ final readonly class AgentRunner
'userId' => $userId,
'commerceIntent' => $commerceIntent,
'query' => $query,
'hasCommerceHistoryContext' => $commerceHistoryContext !== '',
'commerceHistoryContextLength' => mb_strlen($commerceHistoryContext),
'exception' => $e,
]);