Skip to content

Commit b7da591

Browse files
committed
Rework MultiAgent log messages for better readability
- Remove redundant inline context formatting from messages - Simplify messages to be more concise and professional - Structure context arrays properly for custom logger display - Improve agent details formatting with clean array structure - Standardize fallback reason terminology - Messages now rely on context arrays for detailed information
1 parent 95ee4c2 commit b7da591

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

src/agent/src/MultiAgent/MultiAgent.php

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -69,50 +69,54 @@ public function call(MessageBag $messages, array $options = []): ResultInterface
6969

7070
// Ask orchestrator which agent to target using JSON response format
7171
$userText = self::extractUserMessage($userMessages);
72-
$this->logger->debug('MultiAgent: Processing user message: '.$userText.' [user_text='.$userText.']', ['user_text' => $userText]);
72+
$this->logger->debug('MultiAgent: Processing user message', ['user_text' => $userText]);
7373

7474
// Log available rules and agents
75-
$agentInfo = [];
76-
foreach ($this->rules as $rule) {
77-
$triggers = empty($rule->getTriggers()) ? '[no triggers]' : implode(', ', $rule->getTriggers());
78-
$agentInfo[] = $rule->getAgentName().' ('.$triggers.')';
79-
}
80-
$agentDetails = json_encode(array_map(fn ($rule) => ['name' => $rule->getAgentName(), 'triggers' => $rule->getTriggers()], $this->rules));
81-
$this->logger->debug('MultiAgent: Available agents: '.implode(' | ', $agentInfo).' [agents='.$agentDetails.']', ['agents' => $this->rules]);
75+
$agentDetails = array_map(fn ($rule) => [
76+
'name' => $rule->getAgentName(),
77+
'triggers' => $rule->getTriggers(),
78+
], $this->rules);
79+
$this->logger->debug('MultiAgent: Available agents for routing', ['agents' => $agentDetails]);
8280

8381
$agentSelectionPrompt = $this->buildAgentSelectionPrompt($userText);
8482
$agentSelectionMessages = new MessageBag(Message::ofUser($agentSelectionPrompt));
8583

8684
$selectionResult = $this->orchestrator->call($agentSelectionMessages, $options);
8785
$responseContent = $selectionResult->getContent();
88-
$this->logger->debug('MultiAgent: Orchestrator response: '.$responseContent.' [response='.substr($responseContent, 0, 100).'...]', ['response' => $responseContent]);
86+
$this->logger->debug('MultiAgent: Received orchestrator response', ['response' => $responseContent]);
8987

9088
// Parse JSON response
9189
$selectionData = json_decode($responseContent, true);
9290
if (\JSON_ERROR_NONE !== json_last_error()) {
93-
$errorMsg = json_last_error_msg();
94-
$this->logger->debug('MultiAgent: JSON parsing failed ('.$errorMsg.'), falling back to orchestrator [json_error='.$errorMsg.']', ['json_error' => $errorMsg]);
91+
$this->logger->debug('MultiAgent: JSON parsing failed, falling back to orchestrator', ['json_error' => json_last_error_msg()]);
9592

9693
return $this->orchestrator->call($messages, $options);
9794
}
9895

9996
$agentName = $selectionData['agentName'] ?? null;
10097
$reasoning = $selectionData['reasoning'] ?? 'No reasoning provided';
101-
$this->logger->debug('MultiAgent: Selected agent "'.($agentName ?: 'null').'" - '.$reasoning.' [selected_agent='.($agentName ?: 'null').', reasoning='.$reasoning.']', ['selected_agent' => $agentName, 'reasoning' => $reasoning]);
98+
$this->logger->debug('MultiAgent: Agent selection completed', [
99+
'selected_agent' => $agentName,
100+
'reasoning' => $reasoning,
101+
]);
102102

103103
// If no specific agent is selected, fall back to orchestrator
104104
if (!$agentName || 'null' === $agentName) {
105-
$this->logger->debug('MultiAgent: No specific agent selected, using orchestrator [fallback_reason=no_agent_selected]', ['fallback_reason' => 'no_agent_selected']);
105+
$this->logger->debug('MultiAgent: Falling back to orchestrator', ['reason' => 'no_agent_selected']);
106106

107107
return $this->orchestrator->call($messages, $options);
108108
}
109109

110110
// Find the target agent by name
111111
try {
112112
$targetAgent = $this->getAgent($agentName);
113-
$this->logger->debug('MultiAgent: Found and calling agent "'.$agentName.'" [target_agent='.$agentName.']', ['target_agent' => $agentName]);
113+
$this->logger->debug('MultiAgent: Delegating to target agent', ['agent_name' => $agentName]);
114114
} catch (RuntimeException $e) {
115-
$this->logger->debug('MultiAgent: Agent "'.$agentName.'" not found ('.$e->getMessage().'), falling back to orchestrator [requested_agent='.$agentName.', error='.$e->getMessage().', fallback_reason=agent_not_found]', ['requested_agent' => $agentName, 'error' => $e->getMessage(), 'fallback_reason' => 'agent_not_found']);
115+
$this->logger->debug('MultiAgent: Target agent not found, falling back to orchestrator', [
116+
'requested_agent' => $agentName,
117+
'error' => $e->getMessage(),
118+
'reason' => 'agent_not_found',
119+
]);
116120

117121
return $this->orchestrator->call($messages, $options);
118122
}

0 commit comments

Comments
 (0)