Skip to content

fix(n8n): pass connected tools to models and use core 1.x memory API in CascadeFlow Agent - #201

Merged
saschabuehrle merged 1 commit into
mainfrom
fix/n8n-agent-tools-and-memory
Sep 8, 2026
Merged

saschabuehrle merged 1 commit into
mainfrom
fix/n8n-agent-tools-and-memory

Conversation

@saschabuehrle

Copy link
Copy Markdown
Collaborator

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:

  1. Tools are never offered to the models. execute() reads the nodes on the Tools port and hands them to CascadeFlowAgentExecutor, 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?".
  2. A connected memory node crashes the agent on n8n 2.x. Persisting the turn calls chatHistory.addUserMessage / addAIChatMessage, which were removed in @langchain/core 1.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 (LangChain tools call option, the same thing bindTools sets) for invoke, invokeVerifierDirect and stream. No tools connected: options are passed through untouched. Caller-provided options.tools win.
  • New exported persistTurnToMemory() writes the turn via chatHistory.addMessage(new HumanMessage(...)) / addMessage(new AIMessage(...)), available in core 0.3 and 1.x. ChatMemoryLike updated accordingly.
  • CHANGELOG: Unreleased / Fixed entries.

Tests

  • New executor tests: tools forwarded to invoke and invokeVerifierDirect, no tools key without connected tools, caller override kept.
  • New persistTurnToMemory tests (core 1.x style history, and null memory).
  • vitest run in packages/integrations/n8n: 55 passed. tsc --noEmit and eslint clean for the changed files. npm run build bundles fine.
  • Verified end to end on n8n 2.4.6 with the equivalent change applied to the installed node: Calculator, Wikipedia and OpenWeatherMap tools are called by the drafter and verifier, and Window Buffer Memory works across turns.

Version is left at 1.3.0; bump separately when publishing.

https://claude.ai/code/session_018SnqMYYEDpG72ZGubKLtx6

…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
@saschabuehrle saschabuehrle added the bug Something isn't working label Sep 8, 2026
@saschabuehrle
saschabuehrle merged commit d825100 into main Sep 8, 2026
28 checks passed
@saschabuehrle
saschabuehrle deleted the fix/n8n-agent-tools-and-memory branch September 8, 2026 21:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working documentation Improvements or additions to documentation integration: n8n lang: typescript size/m tests

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant