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()) {

View File

@@ -55,6 +55,45 @@ final class AgentRunnerConfig
return $this->getRequiredStringList('follow_up_context.explicit_commercial_signal_terms');
}
public function isCommercialTableFollowUpEnabled(): bool
{
return $this->getRequiredBool('follow_up_context.commercial_table_follow_up.enabled');
}
/**
* @return string[]
*/
public function getCommercialTableFollowUpPromptPatterns(): array
{
return $this->getRequiredStringList('follow_up_context.commercial_table_follow_up.prompt_patterns');
}
/**
* @return string[]
*/
public function getCommercialTableFollowUpHistoryAnchorPatterns(): array
{
return $this->getRequiredStringList('follow_up_context.commercial_table_follow_up.history_anchor_patterns');
}
/**
* @return string[]
*/
public function getCommercialTableFollowUpIndicatorMarkerPatterns(): array
{
return $this->getRequiredStringList('follow_up_context.commercial_table_follow_up.indicator_marker_patterns');
}
public function getCommercialTableFollowUpQueryTemplateWithModel(): string
{
return $this->getRequiredString('follow_up_context.commercial_table_follow_up.query_template_with_model');
}
public function getCommercialTableFollowUpQueryTemplateWithoutModel(): string
{
return $this->getRequiredString('follow_up_context.commercial_table_follow_up.query_template_without_model');
}
public function getFollowUpHistoryQuestionPattern(): string
{
return $this->getRequiredString('follow_up_context.history_question_pattern');

View File

@@ -441,6 +441,16 @@ final readonly class RetriexEffectiveConfigProvider
'product_search_knowledge_chunk_limit' => $this->agentRunnerConfig->getProductSearchKnowledgeChunkLimit(),
'advisory_product_search_knowledge_chunk_limit' => $this->agentRunnerConfig->getAdvisoryProductSearchKnowledgeChunkLimit(),
'optimized_shop_query_prefix_pattern' => $this->agentRunnerConfig->getOptimizedShopQueryPrefixPattern(),
'follow_up_context' => [
'commercial_table_follow_up' => [
'enabled' => $this->agentRunnerConfig->isCommercialTableFollowUpEnabled(),
'prompt_patterns' => $this->agentRunnerConfig->getCommercialTableFollowUpPromptPatterns(),
'history_anchor_patterns' => $this->agentRunnerConfig->getCommercialTableFollowUpHistoryAnchorPatterns(),
'indicator_marker_patterns' => $this->agentRunnerConfig->getCommercialTableFollowUpIndicatorMarkerPatterns(),
'query_template_with_model' => $this->agentRunnerConfig->getCommercialTableFollowUpQueryTemplateWithModel(),
'query_template_without_model' => $this->agentRunnerConfig->getCommercialTableFollowUpQueryTemplateWithoutModel(),
],
],
'input_normalization' => [
'enabled' => $this->agentRunnerConfig->isInputNormalizationEnabled(),
'max_input_chars' => $this->agentRunnerConfig->getInputNormalizationMaxInputChars(),
@@ -1044,6 +1054,18 @@ final readonly class RetriexEffectiveConfigProvider
$this->validateStringListMap($agent['source_labels'] ?? [], 'agent.source_labels', $errors, $warnings);
$this->validateStringListMap($agent['html_templates'] ?? [], 'agent.html_templates', $errors, $warnings);
$followUpContext = is_array($agent['follow_up_context'] ?? null) ? $agent['follow_up_context'] : [];
$commercialTableFollowUp = is_array($followUpContext['commercial_table_follow_up'] ?? null) ? $followUpContext['commercial_table_follow_up'] : [];
$this->validateRegexPatternList($commercialTableFollowUp['prompt_patterns'] ?? [], 'agent.follow_up_context.commercial_table_follow_up.prompt_patterns', $errors);
$this->validateRegexPatternList($commercialTableFollowUp['history_anchor_patterns'] ?? [], 'agent.follow_up_context.commercial_table_follow_up.history_anchor_patterns', $errors);
$this->validateRegexPatternList($commercialTableFollowUp['indicator_marker_patterns'] ?? [], 'agent.follow_up_context.commercial_table_follow_up.indicator_marker_patterns', $errors);
if (trim((string) ($commercialTableFollowUp['query_template_with_model'] ?? '')) === '') {
$errors[] = 'agent.follow_up_context.commercial_table_follow_up.query_template_with_model must not be empty.';
}
if (trim((string) ($commercialTableFollowUp['query_template_without_model'] ?? '')) === '') {
$errors[] = 'agent.follow_up_context.commercial_table_follow_up.query_template_without_model must not be empty.';
}
$ragEvidence = is_array($agent['rag_evidence_guard'] ?? null) ? $agent['rag_evidence_guard'] : [];
$this->validateStringList($this->toList($ragEvidence['stop_terms'] ?? []), 'agent.rag_evidence_guard.stop_terms', $errors, $warnings);
$this->validateStringListMap($ragEvidence['synonyms'] ?? [], 'agent.rag_evidence_guard.synonyms', $errors, $warnings);