mirror of
https://github.com/n8n-io/n8n.git
synced 2026-05-12 16:10:30 +02:00
feat: Pass focused nodes context to planner agent (#25617)
This commit is contained in:
parent
c706e962ec
commit
20934363db
|
|
@ -94,6 +94,7 @@ export interface PlannerNodeInput {
|
|||
workflowJSON: SimpleWorkflow;
|
||||
planPrevious?: PlanOutput | null;
|
||||
planFeedback?: string | null;
|
||||
selectedNodesContext?: string;
|
||||
}
|
||||
|
||||
export interface PlannerNodeResult {
|
||||
|
|
@ -143,6 +144,7 @@ export async function invokePlannerNode(
|
|||
workflowJSON: input.workflowJSON,
|
||||
planPrevious: input.planPrevious,
|
||||
planFeedback: input.planFeedback,
|
||||
selectedNodesContext: input.selectedNodesContext,
|
||||
});
|
||||
const contextMessage = createContextMessage([contextContent]);
|
||||
|
||||
|
|
|
|||
|
|
@ -77,6 +77,7 @@ export interface PlannerContextOptions {
|
|||
workflowJSON: SimpleWorkflow;
|
||||
planPrevious?: PlanOutput | null;
|
||||
planFeedback?: string | null;
|
||||
selectedNodesContext?: string;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -85,7 +86,14 @@ export interface PlannerContextOptions {
|
|||
* feedback from a previous modify cycle.
|
||||
*/
|
||||
export function buildPlannerContext(options: PlannerContextOptions): string {
|
||||
const { userRequest, discoveryContext, workflowJSON, planPrevious, planFeedback } = options;
|
||||
const {
|
||||
userRequest,
|
||||
discoveryContext,
|
||||
workflowJSON,
|
||||
planPrevious,
|
||||
planFeedback,
|
||||
selectedNodesContext,
|
||||
} = options;
|
||||
|
||||
const discoveredNodesList = discoveryContext.nodesFound
|
||||
.map((node) => `- ${node.nodeName} v${node.version}: ${node.reasoning}`)
|
||||
|
|
@ -101,6 +109,7 @@ export function buildPlannerContext(options: PlannerContextOptions): string {
|
|||
|
||||
return prompt()
|
||||
.section('user_request', userRequest)
|
||||
.sectionIf(selectedNodesContext, 'selected_nodes', () => selectedNodesContext!)
|
||||
.sectionIf(
|
||||
discoveryContext.nodesFound.length > 0,
|
||||
'discovery_context_suggested_nodes',
|
||||
|
|
|
|||
|
|
@ -186,6 +186,12 @@ export const DiscoverySubgraphState = Annotation.Root({
|
|||
default: () => ({}),
|
||||
}),
|
||||
|
||||
// Selected nodes context for planner (built from workflowContext.selectedNodes)
|
||||
selectedNodesContext: Annotation<string>({
|
||||
reducer: (x, y) => y ?? x,
|
||||
default: () => '',
|
||||
}),
|
||||
|
||||
// Retry count for when LLM fails to use tool calls properly
|
||||
toolCallRetryCount: Annotation<number>({
|
||||
reducer: (x, y) => y ?? x,
|
||||
|
|
@ -353,6 +359,7 @@ export class DiscoverySubgraph extends BaseSubgraph<
|
|||
workflowJSON: state.workflowJSON,
|
||||
planPrevious: state.planPrevious,
|
||||
planFeedback: state.planFeedback,
|
||||
selectedNodesContext: state.selectedNodesContext,
|
||||
},
|
||||
runnableConfig,
|
||||
);
|
||||
|
|
@ -685,6 +692,7 @@ export class DiscoverySubgraph extends BaseSubgraph<
|
|||
planDecision: null,
|
||||
planFeedback: parentState.planFeedback ?? null,
|
||||
planPrevious: parentState.planPrevious ?? null,
|
||||
selectedNodesContext: selectedNodesSummary ?? '',
|
||||
messages: [contextMessage], // Context already in messages
|
||||
cachedTemplates: parentState.cachedTemplates,
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user