Hi everyone,
I want to create a custom node that integrates the existing AI Agent node together with HTTP Request calls to an external moderation layer. The goal is to run moderation checks before the agent execution while still reusing the existing AI Agent functionality.
Is there a recommended way to reuse or wrap the AI Agent node inside a custom node without reimplementing the full AI Agent logic?
1 Like
welcome to the n8n community @AlexiaBiancaR
I would not try to wrap or invoke the existing AI Agent node from inside a custom node.
From what I understand, custom nodes are meant to implement their own execute logic, while the AI Agent node is a workflow node with its own connected model/tool structure. I don’t think there is a supported public API for reusing the full AI Agent internals inside another custom node.
A safer workaround would be to keep the AI Agent as a normal node in the workflow and put the moderation layer before it. If you need this to be reusable, you could wrap that pattern in a sub-workflow and call it with Execute Workflow, instead of building a custom node that tries to contain the AI Agent. So I would use the custom node only for the external moderation call if needed, and keep the AI Agent orchestration in the workflow itself.
1 Like
Welcome to the community, @AlexiaBiancaR! Really nice use case you’re building here.
Tamy’s advice is spot-on: n8n’s AI Agent node isn’t designed to be wrapped or invoked programmatically from inside a custom node. Its internal structure depends on connected sub-nodes (model, tools, memory) that are wired up at the workflow level, not via a callable API.
The cleanest architecture for what you’re describing is:
- Pre-moderation node (your custom node or an HTTP Request node) - calls your external moderation API with the incoming user message
- IF node - checks the moderation result, blocks or allows
- AI Agent node - runs only if the input passed moderation
- Post-moderation (optional) - can also check the agent’s output before returning it to the user
If you need this whole pipeline to be reusable across multiple workflows, wrapping it in a sub-workflow and calling it via the Execute Workflow node is the way to go. That gives you the modularity you’d get from a custom node wrapper, without fighting n8n’s architecture.
The custom node is still very useful here - just for the moderation call itself rather than trying to contain the agent.
Hope that helps clarify the pattern! If this direction works for you, feel free to mark one of the replies as a Solution.