patch 20n
This commit is contained in:
@@ -214,7 +214,7 @@ final readonly class AgentRunner
|
||||
|
||||
$commerceHistoryContext = $this->buildCommerceHistoryContext($userId, $requestContextHint);
|
||||
$shopQueryHistoryContext = $this->resolveShopQueryHistoryContext(
|
||||
prompt: $routingPrompt,
|
||||
prompt: $originalPrompt,
|
||||
commerceHistoryContext: $commerceHistoryContext
|
||||
);
|
||||
|
||||
@@ -227,6 +227,7 @@ final readonly class AgentRunner
|
||||
'userId' => $userId,
|
||||
'prompt' => $prompt,
|
||||
'routingPrompt' => $routingPrompt,
|
||||
'originalPrompt' => $originalPrompt,
|
||||
'commerceHistoryContextLength' => mb_strlen($commerceHistoryContext),
|
||||
]);
|
||||
}
|
||||
@@ -238,12 +239,32 @@ final readonly class AgentRunner
|
||||
);
|
||||
|
||||
$shopSearchQuery = $this->resolveShopSearchQuery(
|
||||
prompt: $routingPrompt,
|
||||
prompt: $originalPrompt,
|
||||
optimizedShopQuery: $optimizedShopQuery,
|
||||
commerceHistoryContext: $shopQueryHistoryContext,
|
||||
userId: $userId
|
||||
userId: $userId,
|
||||
currentPromptFallback: $routingPrompt
|
||||
);
|
||||
|
||||
$guardedShopSearchQuery = $this->guardFinalStandaloneShopSearchQuery(
|
||||
prompt: $originalPrompt,
|
||||
shopSearchQuery: $shopSearchQuery
|
||||
);
|
||||
|
||||
if ($guardedShopSearchQuery !== $shopSearchQuery) {
|
||||
$this->agentLogger->info('Replaced standalone shop search query after final guard', [
|
||||
'userId' => $userId,
|
||||
'prompt' => $prompt,
|
||||
'routingPrompt' => $routingPrompt,
|
||||
'optimizedShopQuery' => $optimizedShopQuery,
|
||||
'unsafeShopSearchQuery' => $shopSearchQuery,
|
||||
'guardedShopSearchQuery' => $guardedShopSearchQuery,
|
||||
]);
|
||||
|
||||
$shopSearchQuery = $guardedShopSearchQuery;
|
||||
$optimizedShopQuery = '';
|
||||
}
|
||||
|
||||
if ($shopSearchQuery === '') {
|
||||
$this->agentLogger->info('Commerce search skipped because no concrete shop query could be resolved', [
|
||||
'userId' => $userId,
|
||||
@@ -1498,6 +1519,23 @@ final readonly class AgentRunner
|
||||
return $prompt;
|
||||
}
|
||||
|
||||
private function guardFinalStandaloneShopSearchQuery(string $prompt, string $shopSearchQuery): string
|
||||
{
|
||||
$shopSearchQuery = trim($shopSearchQuery);
|
||||
|
||||
if ($shopSearchQuery === '') {
|
||||
return '';
|
||||
}
|
||||
|
||||
$guardedQuery = $this->guardStandaloneOptimizedShopQuery($prompt, $shopSearchQuery);
|
||||
|
||||
if ($guardedQuery !== $shopSearchQuery) {
|
||||
return $guardedQuery;
|
||||
}
|
||||
|
||||
return $shopSearchQuery;
|
||||
}
|
||||
|
||||
private function standaloneOptimizedShopQueryIntroducesUnsupportedContext(
|
||||
string $prompt,
|
||||
string $optimizedShopQuery
|
||||
@@ -1535,7 +1573,8 @@ final readonly class AgentRunner
|
||||
string $prompt,
|
||||
string $optimizedShopQuery,
|
||||
string $commerceHistoryContext,
|
||||
string $userId
|
||||
string $userId,
|
||||
string $currentPromptFallback = ''
|
||||
): string {
|
||||
if ($this->isCommercialTableFollowUpPrompt($prompt)) {
|
||||
foreach ($this->buildCommercialTableFollowUpContextCandidates($commerceHistoryContext, $userId) as $contextCandidate) {
|
||||
@@ -1551,6 +1590,11 @@ final readonly class AgentRunner
|
||||
return $this->guardStandaloneOptimizedShopQuery($prompt, $optimizedShopQuery);
|
||||
}
|
||||
|
||||
$currentPromptFallback = trim($currentPromptFallback);
|
||||
if ($currentPromptFallback !== '' && !$this->isMetaOnlyShopQuery($currentPromptFallback)) {
|
||||
return $currentPromptFallback;
|
||||
}
|
||||
|
||||
if (!$this->isMetaOnlyShopQuery($prompt)) {
|
||||
return $prompt;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user