This commit is contained in:
team 1
2026-05-09 12:04:06 +02:00
parent 7f25335c44
commit dabbc33f07
5 changed files with 171 additions and 18 deletions

View File

@@ -700,6 +700,17 @@ final readonly class AgentRunner
'meta'
);
$followUpActionsMessage = $this->buildFollowUpActionsMessage(
isCommerceIntent: $this->isCommerceIntent($commerceIntent),
hasShopResults: $shopResults !== [],
hasKnowledge: $this->isDirectKnowledgeEvidence($knowledgeEvidenceState),
shopSearchHadSystemFailure: $primaryShopSearchHadSystemFailure
);
if ($followUpActionsMessage !== '') {
yield $this->systemMsg($followUpActionsMessage, 'meta');
}
/* if ($sources !== []) {
yield $this->emitSources(
$sources,
@@ -4850,20 +4861,27 @@ final readonly class AgentRunner
return $this->agentRunnerConfig->getProductionUiTemplate('relevance_default');
}
private function buildFollowUpActionsMessage(bool $isCommerceIntent, bool $hasShopResults, bool $hasKnowledge): string
{
if (!$isCommerceIntent && !$hasShopResults && !$hasKnowledge) {
private function buildFollowUpActionsMessage(
bool $isCommerceIntent,
bool $hasShopResults,
bool $hasKnowledge,
bool $shopSearchHadSystemFailure
): string {
if (!$this->agentRunnerConfig->isProductionUiFollowUpActionsEnabled()) {
return '';
}
$actions = [];
$seenActionKeys = [];
if ($isCommerceIntent || $hasShopResults) {
$actions = array_merge($actions, $this->agentRunnerConfig->getProductionUiFollowUpActions('commerce'));
if ($hasShopResults) {
$this->appendFollowUpActions($actions, $seenActionKeys, $this->agentRunnerConfig->getProductionUiFollowUpActions('shop_results'));
} elseif ($isCommerceIntent && !$shopSearchHadSystemFailure) {
$this->appendFollowUpActions($actions, $seenActionKeys, $this->agentRunnerConfig->getProductionUiFollowUpActions('commerce'));
}
if ($hasKnowledge || $hasShopResults) {
$actions = array_merge($actions, $this->agentRunnerConfig->getProductionUiFollowUpActions('knowledge'));
if ($hasKnowledge) {
$this->appendFollowUpActions($actions, $seenActionKeys, $this->agentRunnerConfig->getProductionUiFollowUpActions('knowledge'));
}
if ($actions === []) {
@@ -4876,15 +4894,10 @@ final readonly class AgentRunner
. '<div class="retriex-action-chip-row">';
foreach ($actions as $action) {
$label = (string) ($action['label'] ?? '');
$actionPrompt = (string) ($action['prompt'] ?? '');
if ($label === '' || $actionPrompt === '') {
continue;
}
$html .= '<button type="button" class="retriex-action-chip" data-retriex-action-prompt="'
. htmlspecialchars($actionPrompt, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8')
. htmlspecialchars($action['prompt'], ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8')
. '">'
. htmlspecialchars($label, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8')
. htmlspecialchars($action['label'], ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8')
. '</button>';
}
@@ -4893,6 +4906,34 @@ final readonly class AgentRunner
return $html;
}
/**
* @param array<int, array{label:string, prompt:string}> $actions
* @param array<string, bool> $seenActionKeys
* @param array<int, array{label:string, prompt:string}> $items
*/
private function appendFollowUpActions(array &$actions, array &$seenActionKeys, array $items): void
{
foreach ($items as $item) {
$label = trim((string) ($item['label'] ?? ''));
$actionPrompt = trim((string) ($item['prompt'] ?? ''));
if ($label === '' || $actionPrompt === '') {
continue;
}
$key = mb_strtolower($label . "\n" . $actionPrompt, 'UTF-8');
if (isset($seenActionKeys[$key])) {
continue;
}
$seenActionKeys[$key] = true;
$actions[] = [
'label' => $label,
'prompt' => $actionPrompt,
];
}
}
private function buildShopSearchMetaMessage(
string $query,
string $commerceIntent,