@@ -73,9 +73,8 @@ export class MastraAgent extends AbstractAgent {
73
73
subscriber . next ( runStartedEvent ) ;
74
74
75
75
// Handle local agent memory management (from Mastra implementation)
76
- if ( "metrics" in this . agent ) {
77
- // @ts -ignore
78
- const memory = this . agent . getMemory ( ) ;
76
+ if ( this . isLocalMastraAgent ( this . agent ) ) {
77
+ const memory = await this . agent . getMemory ( ) ;
79
78
80
79
if ( memory && input . state && Object . keys ( input . state || { } ) . length > 0 ) {
81
80
let thread : StorageThreadType | null = await memory . getThreadById ( {
@@ -163,14 +162,12 @@ export class MastraAgent extends AbstractAgent {
163
162
subscriber . error ( error ) ;
164
163
} ,
165
164
onRunFinished : async ( ) => {
166
- if ( "metrics" in this . agent ) {
165
+ if ( this . isLocalMastraAgent ( this . agent ) ) {
167
166
try {
168
- // @ts -ignore
169
- const memory = this . agent . getMemory ( ) ;
167
+ const memory = await this . agent . getMemory ( ) ;
170
168
if ( memory ) {
171
169
const workingMemory = await memory . getWorkingMemory ( {
172
170
threadId : input . threadId ,
173
- // @ts -ignore
174
171
memoryConfig : {
175
172
workingMemory : {
176
173
enabled : true ,
@@ -219,6 +216,10 @@ export class MastraAgent extends AbstractAgent {
219
216
} ) ;
220
217
}
221
218
219
+ isLocalMastraAgent ( agent : LocalMastraAgent | RemoteMastraAgent ) : agent is LocalMastraAgent {
220
+ return "getMemory" in agent ;
221
+ }
222
+
222
223
/**
223
224
* Streams in process or remote mastra agent.
224
225
* @param input - The input for the mastra agent.
@@ -251,13 +252,7 @@ export class MastraAgent extends AbstractAgent {
251
252
const convertedMessages = convertAGUIMessagesToMastra ( messages ) ;
252
253
const runtimeContext = this . runtimeContext ;
253
254
254
- function isLocalMastraAgent (
255
- agent : LocalMastraAgent | RemoteMastraAgent ,
256
- ) : agent is LocalMastraAgent {
257
- return "metrics" in agent ;
258
- }
259
-
260
- if ( isLocalMastraAgent ( this . agent ) ) {
255
+ if ( this . isLocalMastraAgent ( this . agent ) ) {
261
256
// Local agent - use the agent's stream method directly
262
257
try {
263
258
const response = await this . agent . stream ( convertedMessages , {
0 commit comments