@@ -69,50 +69,54 @@ public function call(MessageBag $messages, array $options = []): ResultInterface
69
69
70
70
// Ask orchestrator which agent to target using JSON response format
71
71
$ 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 ]);
73
73
74
74
// 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 ]);
82
80
83
81
$ agentSelectionPrompt = $ this ->buildAgentSelectionPrompt ($ userText );
84
82
$ agentSelectionMessages = new MessageBag (Message::ofUser ($ agentSelectionPrompt ));
85
83
86
84
$ selectionResult = $ this ->orchestrator ->call ($ agentSelectionMessages , $ options );
87
85
$ 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 ]);
89
87
90
88
// Parse JSON response
91
89
$ selectionData = json_decode ($ responseContent , true );
92
90
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 ()]);
95
92
96
93
return $ this ->orchestrator ->call ($ messages , $ options );
97
94
}
98
95
99
96
$ agentName = $ selectionData ['agentName ' ] ?? null ;
100
97
$ 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
+ ]);
102
102
103
103
// If no specific agent is selected, fall back to orchestrator
104
104
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 ' ]);
106
106
107
107
return $ this ->orchestrator ->call ($ messages , $ options );
108
108
}
109
109
110
110
// Find the target agent by name
111
111
try {
112
112
$ 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 ]);
114
114
} 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
+ ]);
116
120
117
121
return $ this ->orchestrator ->call ($ messages , $ options );
118
122
}
0 commit comments