Skip to content

Commit c2172f5

Browse files
author
linyuan.yang
committed
up
1 parent 429a090 commit c2172f5

1 file changed

Lines changed: 9 additions & 6 deletions

File tree

packages/scorpio.ai/src/Agents/ReAct/ReActAgentService.ts

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,13 +122,16 @@ export class ReActAgentService extends SingleAgentService {
122122
}
123123

124124
const messages = await agentService.stream(task, subCallback, signal);
125+
let lastAI: ChatMessage | undefined;
126+
for (let i = messages.length - 1; i >= 0; i--) {
127+
if (messages[i].role === MessageRole.AI && messages[i].content) { lastAI = messages[i]; break; }
128+
}
125129
const content: MCPContent[] = [];
126-
for (const msg of messages) {
127-
if (msg.role !== MessageRole.AI || !msg.content) continue;
128-
if (typeof msg.content === 'string') {
129-
if (msg.content.trim()) content.push(createTextContent(msg.content));
130-
} else if (Array.isArray(msg.content)) {
131-
for (const part of msg.content) {
130+
if (lastAI) {
131+
if (typeof lastAI.content === 'string') {
132+
if (lastAI.content.trim()) content.push(createTextContent(lastAI.content));
133+
} else if (Array.isArray(lastAI.content)) {
134+
for (const part of lastAI.content) {
132135
if (part.type === MCPContentType.Text && part.text?.trim()) {
133136
content.push(createTextContent(part.text));
134137
} else if (part.type === MCPContentType.Image && part.data) {

0 commit comments

Comments
 (0)