feat: Pass focused nodes context to planner agent (#25617)

This commit is contained in:
Albert Alises 2026-02-11 14:24:37 +01:00 committed by GitHub
parent c706e962ec
commit 20934363db
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 20 additions and 1 deletions

View File

@ -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]);

View File

@ -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',

View File

@ -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,
};