Skip to content

Commit 0c7c364

Browse files
committed
fix access of final response in streamEvents
1 parent 2aa6fdb commit 0c7c364

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

src/agents/mcp_agent.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -727,6 +727,7 @@ export class MCPAgent {
727727

728728
// Add user message to history if memory enabled
729729
if (this.memoryEnabled) {
730+
logger.info(`🔄 Adding user message to history: ${query}`)
730731
this.addToHistory(new HumanMessage(query))
731732
}
732733

@@ -767,11 +768,8 @@ export class MCPAgent {
767768
// Capture final response from chain end event
768769
if (event.event === 'on_chain_end' && event.data?.output) {
769770
const output = event.data.output
770-
if (typeof output === 'string') {
771-
finalResponse = output
772-
}
773-
else if (output?.output && typeof output.output === 'string') {
774-
finalResponse = output.output
771+
if (Array.isArray(output) && output.length > 0 && output[0]?.text) {
772+
finalResponse = output[0].text
775773
}
776774
}
777775
}

0 commit comments

Comments
 (0)