Skip to content

Commit 845ec2f

Browse files
committed
feat: add context handling to sampling prompts in executors
1 parent a03b8df commit 845ec2f

File tree

3 files changed

+26
-4
lines changed

3 files changed

+26
-4
lines changed

packages/core/src/executors/sampling/agentic-sampling-executor.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,9 @@ export class SamplingExecutor extends BaseSamplingExecutor {
9999
const systemPrompt = this.buildSystemPrompt(
100100
args.userRequest as string,
101101
agenticSchema,
102+
(args.context && typeof args.context === "object")
103+
? args.context as Record<string, unknown>
104+
: undefined,
102105
);
103106
return this.runSamplingLoop(() => systemPrompt, agenticSchema);
104107
}
@@ -151,6 +154,7 @@ export class SamplingExecutor extends BaseSamplingExecutor {
151154
private buildSystemPrompt(
152155
userRequest: string,
153156
agenticSchema: Record<string, unknown>,
157+
context?: Record<string, unknown>,
154158
): string {
155159
const toolList = this.allToolNames
156160
.map((name) => {
@@ -168,7 +172,12 @@ export class SamplingExecutor extends BaseSamplingExecutor {
168172
})
169173
.join("\n");
170174

171-
// Build the complete schema using forAgentic
175+
let contextInfo = "";
176+
if (
177+
context && typeof context === "object" && Object.keys(context).length > 0
178+
) {
179+
contextInfo = `\n\nContext:\n${JSON.stringify(context, null, 2)}`;
180+
}
172181

173182
// Use compiled sampling prompt
174183
const basePrompt = CompiledPrompts.samplingExecution({
@@ -180,7 +189,7 @@ export class SamplingExecutor extends BaseSamplingExecutor {
180189
const taskPrompt = `
181190
182191
## Current Task
183-
I will now use agentic sampling to complete the following task: "${userRequest}"
192+
I will now use agentic sampling to complete the following task: "${userRequest}"${contextInfo}
184193
185194
When I need to use a tool, I should specify the tool name in 'action' and provide tool-specific parameters as additional properties.
186195
When the task is complete, I should use "action": "complete".`;

packages/core/src/executors/sampling/workflow-sampling-executor.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,15 @@ export class WorkflowSamplingExecutor extends BaseSamplingExecutor {
132132
});
133133

134134
// Create workflow-specific sampling prompt using existing patterns
135+
let contextInfo = "";
136+
if (
137+
args.context && typeof args.context === "object" &&
138+
Object.keys(args.context).length > 0
139+
) {
140+
contextInfo = `\n\nContext:\n${JSON.stringify(args.context, null, 2)}`;
141+
}
135142
const workflowPrompt =
136-
`\n\nCurrent Task: <user_request>${args.userRequest}</user_request>`;
143+
`\n\nCurrent Task: <user_request>${args.userRequest}</user_request>${contextInfo}`;
137144

138145
// Use JSON instruction injection pattern
139146
return this.injectJsonInstruction({

packages/core/src/factories/args-def-factory.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,8 +154,14 @@ Workflow step definitions - provide ONLY on initial call.
154154
description:
155155
"The task or request that should be completed autonomously by the agentic system using available tools",
156156
},
157+
context: {
158+
type: "object",
159+
description:
160+
"Necessary context for the request, e.g., the absolute path of the current working directory. This is just an example; any relevant context fields are allowed.",
161+
additionalProperties: true,
162+
},
157163
},
158-
required: ["userRequest"],
164+
required: ["userRequest", "context"],
159165
};
160166
},
161167

0 commit comments

Comments
 (0)