From b61de4a515d0b4b92107d92648f428d6ffe9c89d Mon Sep 17 00:00:00 2001 From: ran Date: Tue, 18 Nov 2025 18:35:02 +0100 Subject: [PATCH] fix: throw redefined error on agent fetching failure --- .../langgraph/typescript/src/agent.ts | 31 +++++++++++++------ 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/integrations/langgraph/typescript/src/agent.ts b/integrations/langgraph/typescript/src/agent.ts index 00a156f5f..adbfd9e17 100644 --- a/integrations/langgraph/typescript/src/agent.ts +++ b/integrations/langgraph/typescript/src/agent.ts @@ -1016,20 +1016,31 @@ export class LangGraphAgent extends AbstractAgent { } async getAssistant(): Promise { - const assistants = await this.client.assistants.search(); - const retrievedAssistant = assistants.find( - (searchResult) => searchResult.graph_id === this.graphId, - ); - if (!retrievedAssistant) { - console.error(` + try { + const assistants = await this.client.assistants.search(); + const retrievedAssistant = assistants.find( + (searchResult) => searchResult.graph_id === this.graphId, + ); + if (!retrievedAssistant) { + const notFoundMessage = ` No agent found with graph ID ${this.graphId} found..\n These are the available agents: [${assistants.map((a) => `${a.graph_id} (ID: ${a.assistant_id})`).join(", ")}] - `); - throw new Error("No agent id found"); - } + ` + console.error(notFoundMessage); + throw new Error(notFoundMessage); + } - return retrievedAssistant; + return retrievedAssistant; + } catch (error) { + const redefinedError = new Error(`Failed to retrieve assistant: ${(error as Error).message}`) + this.dispatchEvent({ + type: EventType.RUN_ERROR, + message: redefinedError.message, + }); + this.subscriber.error() + throw redefinedError; + } } async getSchemaKeys(): Promise {