fix(n8n): pass connected tools to models and use core 1.x memory API in CascadeFlow Agent - #201
Merged
Merged
Conversation
…in CascadeFlow Agent The agent node read the tools from its Tools port but only used them to execute tool calls. The drafter, verifier and domain models were invoked without the tool definitions, so no model could ever emit a tool call and tool-using prompts ended with the model asking for permission to run a tool. CascadeFlowAgentExecutor now merges the connected tools into the model call options (LangChain `tools` option) for invoke, invokeVerifierDirect and stream; caller-provided `tools` are kept. Persisting a turn to a connected memory node used chatHistory.addUserMessage/addAIChatMessage, which were removed in @langchain/core 1.x (shipped by n8n 2.x) and crashed the node with "addAIChatMessage is not a function". The node now writes through chatHistory.addMessage with HumanMessage/AIMessage, available in core 0.3 and 1.x, via a small exported persistTurnToMemory helper. Adds executor tests for tool forwarding (with and without connected tools, caller override) and for the memory helper. Verified against n8n 2.4.6 with OpenAI-compatible models and Calculator, Wikipedia and OpenWeatherMap tools. Claude-Session: https://claude.ai/code/session_018SnqMYYEDpG72ZGubKLtx6
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Two defects in the n8n CascadeFlow Agent node (
@cascadeflow/n8n-nodes-cascadeflow, present since #134), found while preparing a demo on n8n 2.4.6:execute()reads the nodes on the Tools port and hands them toCascadeFlowAgentExecutor, but the executor only uses them to run tool calls. The drafter, verifier and domain models are invoked without the tool definitions, so no model can ever request a tool. In practice a prompt like "what is the weather in X" ends with the model answering "shall I run the Weather tool?".chatHistory.addUserMessage/addAIChatMessage, which were removed in@langchain/core1.x (addAIChatMessage is not a function). Our peer range allows core 1.x.Neither was caught by tests: the executor test mocks a cascade model that already returns
tool_calls, so tool binding was never exercised.Fix
CascadeFlowAgentExecutor.withTools()merges the connected tools into the model call options (LangChaintoolscall option, the same thingbindToolssets) forinvoke,invokeVerifierDirectandstream. No tools connected: options are passed through untouched. Caller-providedoptions.toolswin.persistTurnToMemory()writes the turn viachatHistory.addMessage(new HumanMessage(...))/addMessage(new AIMessage(...)), available in core 0.3 and 1.x.ChatMemoryLikeupdated accordingly.Tests
invokeandinvokeVerifierDirect, notoolskey without connected tools, caller override kept.persistTurnToMemorytests (core 1.x style history, and null memory).vitest runinpackages/integrations/n8n: 55 passed.tsc --noEmitand eslint clean for the changed files.npm run buildbundles fine.Version is left at 1.3.0; bump separately when publishing.
https://claude.ai/code/session_018SnqMYYEDpG72ZGubKLtx6