Question about multi agent supervisor graph #35

Closed
opened 2026-02-15 17:05:58 -05:00 by yindo · 2 comments
Owner

Originally created by @laurencejennings on GitHub (Jun 6, 2024).

I'm following the example of the multi agent with supervisor. The graph works correctly in the sense that the supervisor does indeed call all the other agents who perform their actions with their tools. However in some cases, probably when the agent doesn't have any action to perform but they are called regardless, I get this error:

A promise rejection was handled asynchronously. This warning occurs when attaching a catch handler to a promise after it rejected. (rejection #1) Error: No tools_call in message [{"message":{"lc":1,"type":"constructor","id":["langchain_core","messages","AIMessage"],"kwargs":{"content":"__end__","tool_calls":[],"invalid_tool_calls":[],"additional_kwargs":{},"response_metadata":{"tokenUsage":{"completionTokens":4,"promptTokens":601,"totalTokens":605},"finish_reason":"stop"}}},"text":"__end__"}] at JsonOutputToolsParser.parseResult (index.js:23796:13) at JsonOutputToolsParser._callWithConfig (index.js:17097:72) at JsonOutputToolsParser._callWithConfig (index.js:13019:31) at async RunnableSequence.invoke (index.js:13650:29) at async RunnableSequence.invoke (index.js:13650:29) at async Promise.allSettled (index 0) at async executeTasks (index.js:39461:19) at async CompiledStateGraph._transform (index.js:39389:9) at async CompiledStateGraph._transformStreamWithConfig (index.js:13080:28) at async CompiledStateGraph.transform (index.js:39446:22) { stack: Error: No tools_call in message [{"message":{"lc":… CompiledStateGraph.transform (index.js:39446:22), message: No tools_call in message [{"message":{"lc":1,"type…605},"finish_reason":"stop"}}},"text":"__end__"}]

I suppose it's one of the agents responding with end when they aren't supposed to - only the supervisor can do this?

I'm not sure if this is an issue or not but I've tried to add in the prompts to the agents to never reply with end but this happens in a sort of unpredictable way.

Thanks for your help

Originally created by @laurencejennings on GitHub (Jun 6, 2024). I'm following the example of the multi agent with supervisor. The graph works correctly in the sense that the supervisor does indeed call all the other agents who perform their actions with their tools. However in some cases, probably when the agent doesn't have any action to perform but they are called regardless, I get this error: `A promise rejection was handled asynchronously. This warning occurs when attaching a catch handler to a promise after it rejected. (rejection #1) Error: No tools_call in message [{"message":{"lc":1,"type":"constructor","id":["langchain_core","messages","AIMessage"],"kwargs":{"content":"__end__","tool_calls":[],"invalid_tool_calls":[],"additional_kwargs":{},"response_metadata":{"tokenUsage":{"completionTokens":4,"promptTokens":601,"totalTokens":605},"finish_reason":"stop"}}},"text":"__end__"}] at JsonOutputToolsParser.parseResult (index.js:23796:13) at JsonOutputToolsParser._callWithConfig (index.js:17097:72) at JsonOutputToolsParser._callWithConfig (index.js:13019:31) at async RunnableSequence.invoke (index.js:13650:29) at async RunnableSequence.invoke (index.js:13650:29) at async Promise.allSettled (index 0) at async executeTasks (index.js:39461:19) at async CompiledStateGraph._transform (index.js:39389:9) at async CompiledStateGraph._transformStreamWithConfig (index.js:13080:28) at async CompiledStateGraph.transform (index.js:39446:22) { stack: Error: No tools_call in message [{"message":{"lc":… CompiledStateGraph.transform (index.js:39446:22), message: No tools_call in message [{"message":{"lc":1,"type…605},"finish_reason":"stop"}}},"text":"__end__"}]` I suppose it's one of the agents responding with __end__ when they aren't supposed to - only the supervisor can do this? I'm not sure if this is an issue or not but I've tried to add in the prompts to the agents to never reply with __end__ but this happens in a sort of unpredictable way. Thanks for your help
yindo closed this issue 2026-02-15 17:05:58 -05:00
Author
Owner

@scenaristeur commented on GitHub (Nov 27, 2024):

I have same issue using Anthropic Chat

in node_modules/langchain/dist/outputparsers/openai_tools.js

tool_calls can be accessed with
const toolCalls = generations[0].message.tool_calls
instead of

 const toolCalls = generations[0].message.additional_kwargs.tool_calls;

changing parseResult() with

   async parseResult(generations) {
        console.log(generations[0].message)
        const toolCalls = generations[0].message.tool_calls 
        if (!toolCalls) {
            throw new Error(`No tools_call in message ${JSON.stringify(generations)}`);
            // return []
        }
        const clonedToolCalls = JSON.parse(JSON.stringify(toolCalls));
        console.log("cloned",clonedToolCalls)
        const parsedToolCalls = [];
        for (const toolCall of clonedToolCalls) {
            let parsedToolCall  = null
            if (toolCall.function !== undefined) {
                // @ts-expect-error name and arguemnts are defined by Object.defineProperty
                 parsedToolCall = {
                    type: toolCall.function.name,
                    args: JSON.parse(toolCall.function.arguments),
                };
                if (this.returnId) {
                    parsedToolCall.id = toolCall.id;
                }

            }else  {
                 parsedToolCall = {
                    type: toolCall.name,
                    args: toolCall.args,
                    id: toolCall.id
                };
            }
                // backward-compatibility with previous
                // versions of Langchain JS, which uses `name` and `arguments`
                Object.defineProperty(parsedToolCall, "name", {
                    get() {
                        return this.type;
                    },
                });
                Object.defineProperty(parsedToolCall, "arguments", {
                    get() {
                        return this.args;
                    },
                });
                parsedToolCalls.push(parsedToolCall);
        }


console.log("parsed",parsedToolCalls)

        return parsedToolCalls;
    }

allow to go further

@scenaristeur commented on GitHub (Nov 27, 2024): I have same issue using Anthropic Chat in node_modules/langchain/dist/outputparsers/openai_tools.js tool_calls can be accessed with ``` const toolCalls = generations[0].message.tool_calls ``` instead of ``` const toolCalls = generations[0].message.additional_kwargs.tool_calls; ``` changing parseResult() with ``` async parseResult(generations) { console.log(generations[0].message) const toolCalls = generations[0].message.tool_calls if (!toolCalls) { throw new Error(`No tools_call in message ${JSON.stringify(generations)}`); // return [] } const clonedToolCalls = JSON.parse(JSON.stringify(toolCalls)); console.log("cloned",clonedToolCalls) const parsedToolCalls = []; for (const toolCall of clonedToolCalls) { let parsedToolCall = null if (toolCall.function !== undefined) { // @ts-expect-error name and arguemnts are defined by Object.defineProperty parsedToolCall = { type: toolCall.function.name, args: JSON.parse(toolCall.function.arguments), }; if (this.returnId) { parsedToolCall.id = toolCall.id; } }else { parsedToolCall = { type: toolCall.name, args: toolCall.args, id: toolCall.id }; } // backward-compatibility with previous // versions of Langchain JS, which uses `name` and `arguments` Object.defineProperty(parsedToolCall, "name", { get() { return this.type; }, }); Object.defineProperty(parsedToolCall, "arguments", { get() { return this.args; }, }); parsedToolCalls.push(parsedToolCall); } console.log("parsed",parsedToolCalls) return parsedToolCalls; } ``` allow to go further
Author
Owner

@bracesproul commented on GitHub (Dec 9, 2024):

hey @scenaristeur @laurencejennings this error is being thrown because the notebook uses the old JsonOutputToolParser output parser. If you update the chain to not use that (it's deprecated) then it works without issues. See my PR here: https://github.com/langchain-ai/langgraphjs/pull/722

@bracesproul commented on GitHub (Dec 9, 2024): hey @scenaristeur @laurencejennings this error is being thrown because the notebook uses the old `JsonOutputToolParser` output parser. If you update the chain to not use that (it's deprecated) then it works without issues. See my PR here: https://github.com/langchain-ai/langgraphjs/pull/722
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/langgraphjs#35