File tree Expand file tree Collapse file tree
packages/scorpio.ai/src/Agents/ReAct Expand file tree Collapse file tree Original file line number Diff line number Diff 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 ) {
You can’t perform that action at this time.
0 commit comments