patch 20o
This commit is contained in:
@@ -213,10 +213,13 @@ final readonly class AgentRunner
|
||||
yield $this->systemMsg($this->agentRunnerConfig->getOptimizeSearchMessage(), 'think');
|
||||
|
||||
$commerceHistoryContext = $this->buildCommerceHistoryContext($userId, $requestContextHint);
|
||||
$shopQueryHistoryContext = $this->resolveShopQueryHistoryContext(
|
||||
prompt: $originalPrompt,
|
||||
commerceHistoryContext: $commerceHistoryContext
|
||||
);
|
||||
$isStandaloneShopQuery = $this->shouldIsolateStandaloneShopQueryFromHistory($originalPrompt);
|
||||
$shopQueryHistoryContext = $isStandaloneShopQuery
|
||||
? ''
|
||||
: $this->resolveShopQueryHistoryContext(
|
||||
prompt: $originalPrompt,
|
||||
commerceHistoryContext: $commerceHistoryContext
|
||||
);
|
||||
|
||||
if ($shopQueryHistoryContext !== '') {
|
||||
$this->addSource($sources, $this->agentRunnerConfig->getConversationHistorySourceLabel());
|
||||
@@ -229,22 +232,43 @@ final readonly class AgentRunner
|
||||
'routingPrompt' => $routingPrompt,
|
||||
'originalPrompt' => $originalPrompt,
|
||||
'commerceHistoryContextLength' => mb_strlen($commerceHistoryContext),
|
||||
'standaloneShopQueryIsolated' => $isStandaloneShopQuery,
|
||||
]);
|
||||
}
|
||||
|
||||
$optimizedShopQuery = yield from $this->buildOptimizedShopQuery(
|
||||
$routingPrompt,
|
||||
$userId,
|
||||
$shopQueryHistoryContext
|
||||
);
|
||||
if ($isStandaloneShopQuery) {
|
||||
$optimizedShopQuery = '';
|
||||
$shopSearchQuery = $this->guardFinalStandaloneShopSearchQuery(
|
||||
prompt: $originalPrompt,
|
||||
shopSearchQuery: $routingPrompt
|
||||
);
|
||||
|
||||
$shopSearchQuery = $this->resolveShopSearchQuery(
|
||||
prompt: $originalPrompt,
|
||||
optimizedShopQuery: $optimizedShopQuery,
|
||||
commerceHistoryContext: $shopQueryHistoryContext,
|
||||
userId: $userId,
|
||||
currentPromptFallback: $routingPrompt
|
||||
);
|
||||
if ($shopSearchQuery === '') {
|
||||
$shopSearchQuery = $originalPrompt;
|
||||
}
|
||||
|
||||
$this->agentLogger->info('Using deterministic standalone shop query without LLM optimizer history', [
|
||||
'userId' => $userId,
|
||||
'prompt' => $prompt,
|
||||
'routingPrompt' => $routingPrompt,
|
||||
'originalPrompt' => $originalPrompt,
|
||||
'shopSearchQuery' => $shopSearchQuery,
|
||||
]);
|
||||
} else {
|
||||
$optimizedShopQuery = yield from $this->buildOptimizedShopQuery(
|
||||
$routingPrompt,
|
||||
$userId,
|
||||
$shopQueryHistoryContext
|
||||
);
|
||||
|
||||
$shopSearchQuery = $this->resolveShopSearchQuery(
|
||||
prompt: $originalPrompt,
|
||||
optimizedShopQuery: $optimizedShopQuery,
|
||||
commerceHistoryContext: $shopQueryHistoryContext,
|
||||
userId: $userId,
|
||||
currentPromptFallback: $routingPrompt
|
||||
);
|
||||
}
|
||||
|
||||
$guardedShopSearchQuery = $this->guardFinalStandaloneShopSearchQuery(
|
||||
prompt: $originalPrompt,
|
||||
@@ -756,6 +780,10 @@ final readonly class AgentRunner
|
||||
return $originalPrompt;
|
||||
}
|
||||
|
||||
if ($this->isInputNormalizationPlaceholderOutput($candidate)) {
|
||||
return $originalPrompt;
|
||||
}
|
||||
|
||||
if (mb_strlen($candidate, 'UTF-8') > $this->agentRunnerConfig->getInputNormalizationMaxOutputChars()) {
|
||||
return $originalPrompt;
|
||||
}
|
||||
@@ -994,6 +1022,19 @@ final readonly class AgentRunner
|
||||
return true;
|
||||
}
|
||||
|
||||
private function isInputNormalizationPlaceholderOutput(string $candidate): bool
|
||||
{
|
||||
$normalized = $this->normalizeRoutingComparisonText($candidate);
|
||||
|
||||
return in_array($normalized, [
|
||||
'normalized user input',
|
||||
'corrected user input',
|
||||
'user input',
|
||||
'normalisierte nutzereingabe',
|
||||
'korrigierte nutzereingabe',
|
||||
], true);
|
||||
}
|
||||
|
||||
private function normalizeRoutingComparisonText(string $value): string
|
||||
{
|
||||
$value = mb_strtolower(trim($value), 'UTF-8');
|
||||
@@ -1484,6 +1525,74 @@ final readonly class AgentRunner
|
||||
return false;
|
||||
}
|
||||
|
||||
private function shouldIsolateStandaloneShopQueryFromHistory(string $prompt): bool
|
||||
{
|
||||
$prompt = trim($prompt);
|
||||
|
||||
if ($prompt === '') {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($this->isCommercialTableFollowUpPrompt($prompt) || $this->isMetaOnlyShopQuery($prompt)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$normalizedPrompt = $this->normalizeFollowUpText($prompt);
|
||||
$usesReferenceLanguage = $this->containsReferentialShopQueryMarker($normalizedPrompt)
|
||||
|| $this->containsConfiguredShopQueryAnchorTrigger($normalizedPrompt);
|
||||
|
||||
if (!$usesReferenceLanguage) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $this->hasStandaloneConcreteShopSubject($prompt);
|
||||
}
|
||||
|
||||
private function hasStandaloneConcreteShopSubject(string $prompt): bool
|
||||
{
|
||||
if ($this->extractFirstTestomatModelAnchor($prompt) !== '') {
|
||||
return true;
|
||||
}
|
||||
|
||||
$contextFallbackQuery = $this->buildContextFallbackShopQuery($prompt);
|
||||
$tokens = $this->tokenizeShopQueryCandidate($contextFallbackQuery);
|
||||
|
||||
if (count($tokens) >= 2) {
|
||||
return true;
|
||||
}
|
||||
|
||||
foreach ($tokens as $token) {
|
||||
if (preg_match('/\d/u', $token) === 1) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private function shouldUseDeterministicStandaloneShopQuery(string $prompt, string $shopQueryHistoryContext): bool
|
||||
{
|
||||
$prompt = trim($prompt);
|
||||
|
||||
if ($prompt === '') {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (trim($shopQueryHistoryContext) !== '') {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($this->isCommercialTableFollowUpPrompt($prompt)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($this->isMetaOnlyShopQuery($prompt)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private function guardStandaloneOptimizedShopQuery(string $prompt, string $optimizedShopQuery): string
|
||||
{
|
||||
if ($this->shouldUseCommerceHistoryForShopQuery($prompt)) {
|
||||
|
||||
Reference in New Issue
Block a user