refactor(instance-ai): Harmonize prompting between builders (no-changelog)#28338
refactor(instance-ai): Harmonize prompting between builders (no-changelog)#28338OlegIvaniv merged 19 commits intomasterfrom
Conversation
… (no-changelog) Move EXPRESSION_REFERENCE, ADDITIONAL_FUNCTIONS, WORKFLOW_RULES, and WORKFLOW_SDK_PATTERNS to @n8n/workflow-sdk as the single source of truth. Both ai-workflow-builder.ee and instance-ai now import from the shared location instead of maintaining independent forks.
…orkflow-sdk/prompts (no-changelog) Move parameter-updater guides (IF, Switch, Set, HTTP, etc.), node tips (webhook, structured output parser), and node recommendations (text, image, video, audio) to the shared workflow-sdk/prompts package. Legacy ai-workflow-builder.ee now re-exports from the shared location.
… (no-changelog) Move BestPracticesDocument interface, WorkflowTechnique enum, TechniqueDescription, and all 16 guide classes to the shared workflow-sdk/prompts package. Wire up 5 previously disabled guides (data-analysis, enrichment, knowledge-base, human-in-the-loop, monitoring). Both consumer packages now import from the shared source.
…ter guides (no-changelog) Replace the 140-line inline SDK_RULES_AND_PATTERNS block in the instance-ai builder prompt with imports from the shared parameter guides (IF, Switch, Set, HTTP Request, Tool Nodes, Embedding Nodes, Resource Locator) in @n8n/workflow-sdk/prompts. Instance-ai-specific patterns (AI Agent, Code Node, Data Table, Google Sheets, Web App) remain local.
…sdk/prompts (no-changelog) Remove 46 files that were moved to the shared workflow-sdk/prompts package in previous commits. These files were no longer imported by any consumer — all barrel re-exports now point to the shared package.
…angelog) - Extract fuzzySearchNodes as reusable method for multi-word query handling - Fix searchByConnectionType using raw sublimeSearch which failed on multi-word queries like 'n8n data table tool' (returned 0 results) - Both searchByName and searchByConnectionType now share the same per-term fuzzy search with type-name/display-name fallback - Improve connectionType parameter description to guide agents toward using connectionType='ai_tool' when searching for AI Agent tools - Add guidance in tool description about auto-generated tool variants
! PR exceeds size limit (1,713 lines added)This PR adds 1,713 lines, exceeding the 1,000-line limit (test files excluded). Large PRs are harder to review and increase the risk of bugs going unnoticed. Please consider:
If the size is genuinely justified (e.g. generated code, large migrations, test fixtures), a maintainer can override by commenting |
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
There was a problem hiding this comment.
2 issues found across 83 files
Note: This PR contains a large number of files. cubic only reviews up to 75 files per PR, so some files may not have been reviewed. cubic prioritises the most important files to review.
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="packages/@n8n/ai-workflow-builder.ee/src/types/node-recommendations.ts">
<violation number="1" location="packages/@n8n/ai-workflow-builder.ee/src/types/node-recommendations.ts:11">
P1: Custom agent: **Quality & Performance Review**
Avoid re-exporting from the root `@n8n/workflow-sdk/prompts` barrel here; it eagerly loads unrelated prompt modules and increases baseline memory for consumers of this type file. Re-export from the narrower node-recommendations entrypoint instead.</violation>
</file>
<file name="packages/@n8n/workflow-sdk/src/prompts/sdk-reference/workflow-patterns.ts">
<violation number="1" location="packages/@n8n/workflow-sdk/src/prompts/sdk-reference/workflow-patterns.ts:218">
P2: The parallel execution pattern uses two separate trigger instances, so the Merge inputs won’t be produced in the same execution. Use a single trigger node feeding both branches.</violation>
</file>
Architecture diagram
sequenceDiagram
participant Agent as AI Agent / Orchestrator
participant InstanceAI as instance-ai (Package)
participant EEBuilder as ai-workflow-builder.ee (Package)
participant SDK as @n8n/workflow-sdk/prompts
participant Search as NodeSearchEngine
Note over InstanceAI, SDK: Prompt Construction Flow (Consolidated)
InstanceAI->>SDK: NEW: Import SDK Reference (Rules, Expressions)
EEBuilder->>SDK: NEW: Import Best Practices & Node Guidance
alt Request for Best Practices
Agent->>InstanceAI: get_best_practices(technique)
InstanceAI->>SDK: NEW: bestPracticesRegistry.getDocumentation()
SDK-->>InstanceAI: Return Markdown content
InstanceAI-->>Agent: Formatted Best Practices
end
alt Request to Build/Update Workflow
InstanceAI->>SDK: NEW: Fetch Parameter Guides (IF, Switch, Set, etc.)
InstanceAI->>InstanceAI: Compose System Prompt with SDK Rules
InstanceAI-->>Agent: Validated instructions for code generation
end
Note over Agent, Search: Node Discovery Flow (Improved Multi-word Search)
Agent->>InstanceAI: search_nodes(query="google calendar tool", connectionType="ai_tool")
InstanceAI->>Search: fuzzySearchNodes("google calendar tool")
Search->>Search: CHANGED: Split query into terms ["google", "calendar", "tool"]
loop For each term
Search->>Search: Perform sublimeSearch against node database
end
Search->>Search: CHANGED: Merge scores + fallback to display name matches
opt Filter by Connection Type
Search->>Search: CHANGED: Intersect fuzzy results with ai_tool connections
end
Search-->>InstanceAI: Ranked search results
InstanceAI-->>Agent: JSON Node Definitions (including auto-generated tools)
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review, or fix all with cubic.
Signed-off-by: Oleg Ivaniv <me@olegivaniv.com>
There was a problem hiding this comment.
1 issue found across 17 files (changes from recent commits).
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="packages/@n8n/workflow-sdk/package.json">
<violation number="1" location="packages/@n8n/workflow-sdk/package.json:21">
P2: This change introduces a breaking public API change by removing the `@n8n/workflow-sdk/prompts` subpath export. Keep a compatibility alias for `./prompts` (and its `typesVersions` entry) to avoid breaking existing consumers.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review, or fix all with cubic.
…-changelog) Importing from the @n8n/workflow-sdk/prompts barrel eagerly loaded all SDK reference strings, 11 parameter guides, 16 best-practices classes and the registry that instantiates them — even if the consumer only needed a single type or constant. Add per-module subpath exports (sdk-reference, parameter-guides, node-tips, node-recommendations, best-practices) and update all consumers to import from the narrowest entrypoint.
Signed-off-by: Oleg Ivaniv <me@olegivaniv.com>
405afb4 to
d0abccf
Compare
Performance ComparisonComparing current → latest master → 14-day baseline Idle baseline with Instance AI module loaded
Memory consumption baseline with starter plan resources
docker-stats
How to read this table
|
Signed-off-by: Oleg Ivaniv <me@olegivaniv.com>
a6b4e71 to
736b246
Compare
…-AI (no-changelog) - Create shared node-selection constants in workflow-sdk: AI node selection, use-case patterns, trigger selection, native node preference, connection parameters, baseline flow control, AI tool patterns - Port detailed workflow topology patterns (linear, parallel, fan-in, batch, AI agent variants) from legacy builder to workflow-sdk shared - Inject node selection heuristics into instance-ai planner prompt - Inject AI tool patterns, connection params, baseline flow control into instance-ai builder prompt - Add ./prompts/node-selection subpath export + typesVersions entry
…prompts (no-changelog) The user message was pre-saved to storage for HITL page-refresh resilience, then Mastra's MessageHistory processor loaded it back from storage as history while the same message was also passed as direct input to agent.stream(). Cross-format deduplication failed (MastraDBMessage vs CoreMessage), so the LLM received the user message twice. Mastra now flushes messages before HITL suspension via SaveQueueManager, making the pre-save redundant. Also removes the client-side user-message content dedup workaround in message-parser.ts.
Signed-off-by: Oleg Ivaniv <me@olegivaniv.com>
…hangelog) Re-disable data-analysis, enrichment, knowledge-base, human-in-the-loop, and monitoring best-practices guides in the shared registry. These were unintentionally enabled when consolidating into workflow-sdk. Reverts test expectations to match the original disabled state.
…changelog) Replace free-form string with z.enum(AI_CONNECTION_TYPES) so the LLM sees the exact valid values in the tool schema. Shortens the verbose description since the enum values are self-descriptive.
… + query combo (no-changelog) Covers the regression where multi-word queries like 'data table tool' returned 0 results from searchByConnectionType. Tests verify: - Multi-word queries find nodes via term splitting in searchByName - searchByConnectionType + multi-word name filter finds tool nodes - connectionType filtering excludes regular nodes (e.g. Google Calendar vs Google Calendar Tool) Signed-off-by: Oleg Ivaniv <me@olegivaniv.com>
There was a problem hiding this comment.
1 issue found across 5 files (changes from recent commits).
Prompt for AI agents (unresolved issues)
Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.
<file name="packages/@n8n/workflow-sdk/src/prompts/best-practices/index.ts">
<violation number="1" location="packages/@n8n/workflow-sdk/src/prompts/best-practices/index.ts:48">
P1: This change disables five best-practice guides in the registry, so lookups for those techniques now return `undefined` instead of a document.</violation>
</file>
Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review, or fix all with cubic.
Signed-off-by: Oleg Ivaniv <me@olegivaniv.com>
mutdmour
left a comment
There was a problem hiding this comment.
Looks good. thanks for addressing my feedback
|
Got released with |
…elog) (n8n-io#28338) Signed-off-by: Oleg Ivaniv <me@olegivaniv.com>
Summary
Both
instance-aiandai-workflow-builder.eehad their own forked copies of the same prompting content, expression references, workflow rules, parameter guides, best-practices docs, node recommendations. When one got updated the other drifted. This PR moves all of that shared content into@n8n/workflow-sdk/prompts(both packages already depend on workflow-sdk) so there's a single source of truth, then deletes the 46 dead files that got replaced.Also fixes a bug in the
search-nodestool where multi-word queries like"data table tool"returned 0 results when combined withconnectionType, which meant the builder couldn't find auto-generated tool nodes (dataTableTool, googleCalendarTool, etc).What changed
Moved SDK reference constants (expression reference, additional functions, workflow rules, SDK patterns) into
workflow-sdk/src/prompts/sdk-reference/. Both packages now import from there.Moved all 11 parameter guides (IF, Switch, Set, HTTP, Gmail, etc.), 2 node tips (Webhook, Structured Output Parser), and 4 node recommendations (text/image/video/audio generation) into
workflow-sdk/src/prompts/node-guidance/. Extracted types locally so there's no dependency on framework-specific packages.Moved the
WorkflowTechniqueenum,BestPracticesDocumentinterface, and all 16 guide classes intoworkflow-sdk/src/prompts/best-practices/. This also wired up 5 guides that were previously commented out (data-analysis, enrichment, knowledge-base, human-in-the-loop, monitoring).Replaced the ~300-line inline
SDK_RULES_AND_PATTERNSblock in instance-ai's builder prompt with composed imports from the shared parameter guides. The instance-ai-specific stuff (AI Agent subnodes, Code Node, Data Table, Google Sheets, web app pattern) stays local.Deleted 46 original source files across both packages (~5,900 lines).
Fixed
searchByConnectionTypein the node search engine, it was callingsublimeSearchdirectly with the raw query string, which breaks on multi-word input. Extracted afuzzySearchNodesmethod (with per-term splitting + display-name fallback) that bothsearchByNameandsearchByConnectionTypenow share. Also improved theconnectionTypeparam description so the agent actually knows to useconnectionType="ai_tool"when looking for tool nodes to attach to an AI Agent.Layout
Review / Merge checklist
Backport to Beta,Backport to Stable, orBackport to v1(if the PR is an urgent fix that needs to be backported)