@@ -1016,20 +1016,31 @@ export class LangGraphAgent extends AbstractAgent {
10161016 }
10171017
10181018 async getAssistant ( ) : Promise < Assistant > {
1019- const assistants = await this . client . assistants . search ( ) ;
1020- const retrievedAssistant = assistants . find (
1021- ( searchResult ) => searchResult . graph_id === this . graphId ,
1022- ) ;
1023- if ( ! retrievedAssistant ) {
1024- console . error ( `
1019+ try {
1020+ const assistants = await this . client . assistants . search ( ) ;
1021+ const retrievedAssistant = assistants . find (
1022+ ( searchResult ) => searchResult . graph_id === this . graphId ,
1023+ ) ;
1024+ if ( ! retrievedAssistant ) {
1025+ const notFoundMessage = `
10251026 No agent found with graph ID ${ this . graphId } found..\n
10261027
10271028 These are the available agents: [${ assistants . map ( ( a ) => `${ a . graph_id } (ID: ${ a . assistant_id } )` ) . join ( ", " ) } ]
1028- ` ) ;
1029- throw new Error ( "No agent id found" ) ;
1030- }
1029+ `
1030+ console . error ( notFoundMessage ) ;
1031+ throw new Error ( notFoundMessage ) ;
1032+ }
10311033
1032- return retrievedAssistant ;
1034+ return retrievedAssistant ;
1035+ } catch ( error ) {
1036+ const redefinedError = new Error ( `Failed to retrieve assistant: ${ ( error as Error ) . message } ` )
1037+ this . dispatchEvent ( {
1038+ type : EventType . RUN_ERROR ,
1039+ message : redefinedError . message ,
1040+ } ) ;
1041+ this . subscriber . error ( )
1042+ throw redefinedError ;
1043+ }
10331044 }
10341045
10351046 async getSchemaKeys ( ) : Promise < SchemaKeys > {
0 commit comments