patch 20c

This commit is contained in:
team 1
2026-05-02 20:08:25 +02:00
parent 0fc34f4bc0
commit 446df191c0
6 changed files with 284 additions and 2 deletions

View File

@@ -107,7 +107,11 @@ final readonly class AgentRunner
$this->addSource($sources, $this->agentRunnerConfig->getExternalUrlSourceLabel());
}
$commerceIntent = $this->detectCommerceIntent($routingPrompt);
$commerceIntent = $this->detectCommerceIntentForRouting(
$routingPrompt,
$userId,
$requestContextHint
);
yield $this->systemMsg($this->agentRunnerConfig->getRetrieveKnowledgeMessage(), 'think');
@@ -933,6 +937,36 @@ final readonly class AgentRunner
return (string) ($commerceMeta['intent'] ?? CommerceIntentLite::NONE);
}
private function detectCommerceIntentForRouting(
string $prompt,
string $userId,
string $requestContextHint
): string {
$commerceIntent = $this->detectCommerceIntent($prompt);
if ($this->isCommerceIntent($commerceIntent)) {
return $commerceIntent;
}
if (!$this->isCommercialTableFollowUpPrompt($prompt)) {
return $commerceIntent;
}
$commerceHistoryContext = $this->buildCommerceHistoryContext($userId, $requestContextHint);
if (!$this->commercialTableFollowUpHistoryHasAnchor($commerceHistoryContext)) {
return $commerceIntent;
}
$this->agentLogger->info('Promoted commercial table follow-up to shop intent', [
'userId' => $userId,
'prompt' => $prompt,
'hasRequestContextHint' => trim($requestContextHint) !== '',
]);
return CommerceIntentLite::PRODUCT_SEARCH;
}
private function isCommerceIntent(string $commerceIntent): bool
{
return $commerceIntent === CommerceIntentLite::PRODUCT_SEARCH
@@ -1265,6 +1299,14 @@ final readonly class AgentRunner
string $commerceHistoryContext,
string $userId
): string {
if ($this->isCommercialTableFollowUpPrompt($prompt)) {
$commercialTableContextQuery = $this->extractCommercialTableFollowUpShopQuery($commerceHistoryContext);
if ($commercialTableContextQuery !== '' && !$this->isMetaOnlyShopQuery($commercialTableContextQuery)) {
return $commercialTableContextQuery;
}
}
if ($optimizedShopQuery !== '' && !$this->isMetaOnlyShopQuery($optimizedShopQuery)) {
return $optimizedShopQuery;
}
@@ -1302,6 +1344,78 @@ final readonly class AgentRunner
return '';
}
private function extractCommercialTableFollowUpShopQuery(string $commerceHistoryContext): string
{
if (!$this->agentRunnerConfig->isCommercialTableFollowUpEnabled()) {
return '';
}
$turn = $this->extractLatestHistoryTurn($commerceHistoryContext);
if ($turn === '') {
return '';
}
if (!$this->matchesAnyConfiguredPattern(
$turn,
$this->agentRunnerConfig->getCommercialTableFollowUpIndicatorMarkerPatterns()
)) {
return '';
}
$model = $this->extractFirstTestomatModelAnchor($turn);
if ($model !== '') {
$query = str_replace(
'{model}',
$model,
$this->agentRunnerConfig->getCommercialTableFollowUpQueryTemplateWithModel()
);
return trim((string) preg_replace('/\s+/u', ' ', $query));
}
return trim($this->agentRunnerConfig->getCommercialTableFollowUpQueryTemplateWithoutModel());
}
private function isCommercialTableFollowUpPrompt(string $prompt): bool
{
if (!$this->agentRunnerConfig->isCommercialTableFollowUpEnabled()) {
return false;
}
return $this->matchesAnyConfiguredPattern(
$this->normalizeFollowUpText($prompt),
$this->agentRunnerConfig->getCommercialTableFollowUpPromptPatterns()
);
}
private function commercialTableFollowUpHistoryHasAnchor(string $commerceHistoryContext): bool
{
if (trim($commerceHistoryContext) === '') {
return false;
}
return $this->matchesAnyConfiguredPattern(
$commerceHistoryContext,
$this->agentRunnerConfig->getCommercialTableFollowUpHistoryAnchorPatterns()
);
}
/**
* @param string[] $patterns
*/
private function matchesAnyConfiguredPattern(string $text, array $patterns): bool
{
foreach ($patterns as $pattern) {
if (preg_match($pattern, $text) === 1) {
return true;
}
}
return false;
}
private function extractContextualShopSearchQuery(string $commerceHistoryContext): string
{
if (!$this->agentRunnerConfig->isShopQueryContextFallbackEnabled()) {