fix stream error handling
This commit is contained in:
@@ -60,6 +60,7 @@ final readonly class AgentRunner
|
||||
$attemptedShopRepair = false;
|
||||
$usedShopRepair = false;
|
||||
$shopRepairQueries = [];
|
||||
$primaryShopSearchHadSystemFailure = false;
|
||||
|
||||
$this->agentLogger->info('Agent run started', [
|
||||
'userId' => $userId,
|
||||
@@ -113,7 +114,7 @@ final readonly class AgentRunner
|
||||
$this->addSource($sources, $this->agentRunnerConfig->getConversationHistorySourceLabel());
|
||||
}
|
||||
|
||||
$optimizedShopQuery = $this->buildOptimizedShopQuery(
|
||||
$optimizedShopQuery = yield from $this->buildOptimizedShopQuery(
|
||||
$prompt,
|
||||
$userId,
|
||||
$commerceHistoryContext
|
||||
@@ -142,16 +143,35 @@ final readonly class AgentRunner
|
||||
$userId,
|
||||
$commerceHistoryContext
|
||||
);
|
||||
$primaryShopSearchHadSystemFailure = $this->shopSearchService->hadLastSearchSystemFailure();
|
||||
|
||||
$repairPayload = $this->repairShopResults(
|
||||
prompt: $prompt,
|
||||
userId: $userId,
|
||||
commerceIntent: $commerceIntent,
|
||||
commerceHistoryContext: $commerceHistoryContext,
|
||||
primaryQuery: $shopSearchQuery,
|
||||
primaryShopResults: $primaryShopResults,
|
||||
knowledgeChunks: $knowledgeChunks
|
||||
);
|
||||
if ($primaryShopSearchHadSystemFailure) {
|
||||
$this->agentLogger->warning('Shop repair skipped after Store API system failure', [
|
||||
'userId' => $userId,
|
||||
'commerceIntent' => $commerceIntent,
|
||||
'shopSearchQuery' => $shopSearchQuery,
|
||||
'failureReason' => $this->shopSearchService->getLastSearchFailureReason(),
|
||||
]);
|
||||
|
||||
$repairPayload = [
|
||||
'results' => $primaryShopResults,
|
||||
'attemptedRepair' => false,
|
||||
'usedRepair' => false,
|
||||
'repairQueries' => [],
|
||||
];
|
||||
} else {
|
||||
yield $this->systemMsg('Erweiterte Shopsuche wird geprüft…', 'think');
|
||||
|
||||
$repairPayload = $this->repairShopResults(
|
||||
prompt: $prompt,
|
||||
userId: $userId,
|
||||
commerceIntent: $commerceIntent,
|
||||
commerceHistoryContext: $commerceHistoryContext,
|
||||
primaryQuery: $shopSearchQuery,
|
||||
primaryShopResults: $primaryShopResults,
|
||||
knowledgeChunks: $knowledgeChunks
|
||||
);
|
||||
}
|
||||
|
||||
$shopResults = $repairPayload['results'];
|
||||
$attemptedShopRepair = $repairPayload['attemptedRepair'];
|
||||
@@ -247,6 +267,7 @@ final readonly class AgentRunner
|
||||
'attemptedShopRepair' => $attemptedShopRepair,
|
||||
'usedShopRepair' => $usedShopRepair,
|
||||
'shopRepairQueries' => $shopRepairQueries,
|
||||
'primaryShopSearchHadSystemFailure' => $primaryShopSearchHadSystemFailure,
|
||||
'knowledgeChunkCount' => count($knowledgeChunks),
|
||||
'knowledgeRetrievalPrompt' => $knowledgeRetrievalPrompt,
|
||||
'usedFollowUpRetrievalContext' => $usedFollowUpRetrievalContext,
|
||||
@@ -534,11 +555,14 @@ final readonly class AgentRunner
|
||||
return trim($value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Generator<int, string, mixed, string>
|
||||
*/
|
||||
private function buildOptimizedShopQuery(
|
||||
string $prompt,
|
||||
string $userId,
|
||||
string $commerceHistoryContext = ''
|
||||
): string {
|
||||
): Generator {
|
||||
$shopPrompt = trim($this->agentRunnerConfig->getShopPrompt(
|
||||
$prompt,
|
||||
$commerceHistoryContext
|
||||
@@ -549,6 +573,7 @@ final readonly class AgentRunner
|
||||
}
|
||||
|
||||
$optimizedQuery = '';
|
||||
$lastHeartbeatAt = time();
|
||||
$this->thinkSuppressor->reset();
|
||||
|
||||
try {
|
||||
@@ -557,6 +582,11 @@ final readonly class AgentRunner
|
||||
continue;
|
||||
}
|
||||
|
||||
if (time() - $lastHeartbeatAt >= 2) {
|
||||
yield $this->systemMsg('Shop-Suchanfrage wird optimiert…', 'think');
|
||||
$lastHeartbeatAt = time();
|
||||
}
|
||||
|
||||
$cleanToken = $this->thinkSuppressor->filter($token);
|
||||
|
||||
if ($cleanToken === '') {
|
||||
|
||||
Reference in New Issue
Block a user