@@ -18,6 +18,7 @@ import { Agent as LocalMastraAgent } from "@mastra/core/agent";
18
18
import { RuntimeContext } from "@mastra/core/runtime-context" ;
19
19
import { randomUUID } from "crypto" ;
20
20
import { Observable } from "rxjs" ;
21
+ import util from "util" ;
21
22
import { MastraClient } from "@mastra/client-js" ;
22
23
type RemoteMastraAgent = ReturnType < MastraClient [ "getAgent" ] > ;
23
24
import {
@@ -70,6 +71,8 @@ export class MastraAgent extends AbstractAgent {
70
71
runId : input . runId ,
71
72
} ;
72
73
74
+ console . log ( "runStartedEvent" , runStartedEvent ) ;
75
+
73
76
subscriber . next ( runStartedEvent ) ;
74
77
75
78
// Handle local agent memory management (from Mastra implementation)
@@ -118,6 +121,7 @@ export class MastraAgent extends AbstractAgent {
118
121
messageId,
119
122
delta : text ,
120
123
} ;
124
+ console . log ( "textMessageChunkEvent" , util . inspect ( event , { depth : null } ) ) ;
121
125
subscriber . next ( event ) ;
122
126
} ,
123
127
onToolCallPart : ( streamPart ) => {
@@ -127,19 +131,22 @@ export class MastraAgent extends AbstractAgent {
127
131
toolCallId : streamPart . toolCallId ,
128
132
toolCallName : streamPart . toolName ,
129
133
} ;
134
+ console . log ( "toolCallStartEvent" , util . inspect ( startEvent , { depth : null } ) ) ;
130
135
subscriber . next ( startEvent ) ;
131
136
132
137
const argsEvent : ToolCallArgsEvent = {
133
138
type : EventType . TOOL_CALL_ARGS ,
134
139
toolCallId : streamPart . toolCallId ,
135
140
delta : JSON . stringify ( streamPart . args ) ,
136
141
} ;
142
+ console . log ( "toolCallArgsEvent" , util . inspect ( argsEvent , { depth : null } ) ) ;
137
143
subscriber . next ( argsEvent ) ;
138
144
139
145
const endEvent : ToolCallEndEvent = {
140
146
type : EventType . TOOL_CALL_END ,
141
147
toolCallId : streamPart . toolCallId ,
142
148
} ;
149
+ console . log ( "toolCallEndEvent" , util . inspect ( endEvent , { depth : null } ) ) ;
143
150
subscriber . next ( endEvent ) ;
144
151
} ,
145
152
onToolResultPart ( streamPart ) {
@@ -151,6 +158,11 @@ export class MastraAgent extends AbstractAgent {
151
158
role : "tool" ,
152
159
} ;
153
160
161
+ console . log (
162
+ "toolCallResultEvent" ,
163
+ util . inspect ( toolCallResultEvent , { depth : null } ) ,
164
+ ) ;
165
+
154
166
subscriber . next ( toolCallResultEvent ) ;
155
167
} ,
156
168
onFinishMessagePart : async ( ) => {
@@ -162,6 +174,7 @@ export class MastraAgent extends AbstractAgent {
162
174
subscriber . error ( error ) ;
163
175
} ,
164
176
onRunFinished : async ( ) => {
177
+ console . log ( "onRunFinished" ) ;
165
178
if ( this . isLocalMastraAgent ( this . agent ) ) {
166
179
try {
167
180
const memory = await this . agent . getMemory ( ) ;
@@ -248,9 +261,11 @@ export class MastraAgent extends AbstractAgent {
248
261
} ,
249
262
{ } as Record < string , any > ,
250
263
) ;
264
+ console . log ( "clientTools" , util . inspect ( clientTools , { depth : null } ) ) ;
251
265
const resourceId = this . resourceId ?? threadId ;
252
266
const convertedMessages = convertAGUIMessagesToMastra ( messages ) ;
253
267
const runtimeContext = this . runtimeContext ;
268
+ console . log ( "runtimeContext" , runtimeContext ) ;
254
269
255
270
if ( this . isLocalMastraAgent ( this . agent ) ) {
256
271
// Local agent - use the agent's stream method directly
@@ -286,13 +301,15 @@ export class MastraAgent extends AbstractAgent {
286
301
}
287
302
} else {
288
303
// If it's already a readable stream, process it directly
289
- await processDataStream ( {
304
+ const postProcessedResponse = await processDataStream ( {
290
305
stream : response as any ,
291
306
onTextPart,
292
307
onToolCallPart,
293
308
onToolResultPart,
294
309
onFinishMessagePart,
295
310
} ) ;
311
+ console . log ( "data stream processed" ) ;
312
+ console . log ( "postProcessedResponse" , util . inspect ( postProcessedResponse , { depth : null } ) ) ;
296
313
await onRunFinished ?.( ) ;
297
314
}
298
315
} else {
@@ -312,14 +329,22 @@ export class MastraAgent extends AbstractAgent {
312
329
clientTools,
313
330
} ) ;
314
331
332
+ console . log ( "response" , util . inspect ( response , { depth : null } ) ) ;
333
+
315
334
// Remote agents should have a processDataStream method
316
335
if ( response && typeof response . processDataStream === "function" ) {
317
- await response . processDataStream ( {
336
+ console . log ( "processing data stream" ) ;
337
+ const postProcessedResponse = await response . processDataStream ( {
318
338
onTextPart,
319
339
onToolCallPart,
320
340
onToolResultPart,
321
341
onFinishMessagePart,
322
342
} ) ;
343
+
344
+ console . log ( "data stream processed" ) ;
345
+
346
+ console . log ( "postProcessedResponse" , util . inspect ( postProcessedResponse , { depth : null } ) ) ;
347
+
323
348
await onRunFinished ?.( ) ;
324
349
} else {
325
350
throw new Error ( "Invalid response from remote agent" ) ;
0 commit comments