feat(core): improve A2A content extraction (#20487)

Co-authored-by: Gal Zahavi <38544478+galz10@users.noreply.github.com>
This commit is contained in:
Adam Weidman
2026-02-26 17:38:30 -05:00
committed by GitHub
parent 9de8349cf0
commit 10c5bd8ce9
2 changed files with 84 additions and 2 deletions

View File

@@ -74,6 +74,26 @@ export class A2AResultReassembler {
]);
}
}
// History Fallback: Some agent implementations do not populate the
// status.message in their final terminal response, instead archiving
// the final answer in the task's history array. To ensure we don't
// present an empty result, we fallback to the most recent agent message
// in the history only when the task is terminal and no other content
// (message log or artifacts) has been reassembled.
if (
isTerminalState(chunk.status?.state) &&
this.messageLog.length === 0 &&
this.artifacts.size === 0 &&
chunk.history &&
chunk.history.length > 0
) {
const lastAgentMsg = [...chunk.history]
.reverse()
.find((m) => m.role?.toLowerCase().includes('agent'));
if (lastAgentMsg) {
this.pushMessage(lastAgentMsg);
}
}
break;
case 'message': {
@@ -126,7 +146,7 @@ export class A2AResultReassembler {
* Handles Text, Data (JSON), and File parts.
*/
export function extractMessageText(message: Message | undefined): string {
if (!message) {
if (!message || !message.parts || !Array.isArray(message.parts)) {
return '';
}
@@ -158,7 +178,6 @@ function extractPartText(part: Part): string {
}
if (isDataPart(part)) {
// Attempt to format known data types if metadata exists, otherwise JSON stringify
return `Data: ${JSON.stringify(part.data)}`;
}