fix(agents): improve subagent output extraction for edge cases
Fixes #43755 When subagent results are not delivered to parent session, the issue may be that the message format doesn't match the extraction logic. This fix adds more fallback handling: - Try user role as fallback (results might be in user messages) - Check for raw 'result' field at message root - Check for 'output' field at message root - Handle more edge cases in extractSubagentOutputText()
This commit is contained in:
parent
4f620bebe5
commit
ee96c3e0ef
@ -248,6 +248,8 @@ function extractSubagentOutputText(message: unknown): string {
|
||||
}
|
||||
const role = (message as { role?: unknown }).role;
|
||||
const content = (message as { content?: unknown }).content;
|
||||
|
||||
// Try assistant role first
|
||||
if (role === "assistant") {
|
||||
const assistantText = extractAssistantText(message);
|
||||
if (assistantText) {
|
||||
@ -261,10 +263,14 @@ function extractSubagentOutputText(message: unknown): string {
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
// Try toolResult or tool role
|
||||
if (role === "toolResult" || role === "tool") {
|
||||
return extractToolResultText((message as ToolResultMessage).content);
|
||||
}
|
||||
if (role == null) {
|
||||
|
||||
// Try user role as fallback - subagent results might be in user messages
|
||||
if (role === "user") {
|
||||
if (typeof content === "string") {
|
||||
return sanitizeTextContent(content);
|
||||
}
|
||||
@ -272,6 +278,30 @@ function extractSubagentOutputText(message: unknown): string {
|
||||
return extractInlineTextContent(content);
|
||||
}
|
||||
}
|
||||
|
||||
// Handle null/undefined role - check all possible content fields
|
||||
if (role == null) {
|
||||
// Try all possible content fields
|
||||
if (typeof content === "string") {
|
||||
return sanitizeTextContent(content);
|
||||
}
|
||||
if (Array.isArray(content)) {
|
||||
return extractInlineTextContent(content);
|
||||
}
|
||||
|
||||
// Check for raw result field at message root
|
||||
const rawResult = (message as { result?: unknown }).result;
|
||||
if (typeof rawResult === "string") {
|
||||
return sanitizeTextContent(rawResult);
|
||||
}
|
||||
|
||||
// Check for output field at message root
|
||||
const output = (message as { output?: unknown }).output;
|
||||
if (typeof output === "string") {
|
||||
return sanitizeTextContent(output);
|
||||
}
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user