Skip to content

Commit 4a93f26

Browse files
Copilotyaonyan
andcommitted
Replace proceed boolean parameter with decision enum in workflow tools
Co-authored-by: yaonyan <[email protected]>
1 parent aedce55 commit 4a93f26

File tree

4 files changed

+68
-26
lines changed

4 files changed

+68
-26
lines changed

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

Lines changed: 43 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,9 @@ export class WorkflowExecutor {
9696
};
9797
}
9898

99-
if (args.proceed === true) {
99+
const decision = args.decision as string;
100+
101+
if (decision === "proceed") {
100102
// Allow proceeding to completion even when at the last step
101103
if (
102104
!state.hasNextStep() &&
@@ -144,13 +146,50 @@ export class WorkflowExecutor {
144146
} else {
145147
state.start();
146148
}
149+
} else if (decision === "complete") {
150+
// Only allow completion at final step or when at last step and started
151+
if (
152+
(state.isAtLastStep() && state.isWorkflowStarted()) ||
153+
(!state.hasNextStep() && state.isWorkflowStarted())
154+
) {
155+
state.markCompleted();
156+
return {
157+
content: [
158+
{
159+
type: "text",
160+
text: `## Workflow Completed!\n\n${
161+
this.formatProgress(state)
162+
}\n\n${
163+
CompiledPrompts.workflowCompleted({
164+
totalSteps: state.getSteps().length,
165+
toolName: this.name,
166+
newWorkflowInstructions: this.predefinedSteps
167+
? ""
168+
: " and new `steps` array",
169+
})
170+
}`,
171+
},
172+
],
173+
isError: false,
174+
};
175+
} else {
176+
return {
177+
content: [
178+
{
179+
type: "text",
180+
text: WorkflowPrompts.ERRORS.ALREADY_AT_FINAL,
181+
},
182+
],
183+
isError: true,
184+
};
185+
}
147186
}
148-
// When proceed: false, stay at current step (retry)
187+
// When decision is "retry" or undefined, stay at current step (retry)
149188
}
150189

151190
// Validate arguments based on current state
152-
// - If proceed: true, validate against the new step after moving
153-
// - If proceed: false, validate against current step
191+
// - If decision: "proceed", validate against the new step after moving
192+
// - If decision: "retry" or undefined, validate against current step
154193
const validationSchema = this.createArgsDef.forCurrentState(state);
155194

156195
const validationResult = this.validate(args, validationSchema);

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,11 @@ Workflow step definitions - provide ONLY on initial call.
8383
enum: [true],
8484
}),
8585

86-
proceed: (): JSONSchema => ({
87-
type: "boolean",
86+
decision: (): JSONSchema => ({
87+
type: "string",
88+
enum: ["retry", "proceed", "complete"],
8889
description:
89-
"**Step execution control. Set \`true\` to advance, \`false\`/omit to retry. For failed steps, MUST use \`false\`**",
90+
"**Step execution control. Use \`proceed\` to advance to next step, \`retry\` to re-execute current step, or \`complete\` to finish workflow (only allowed at final step). For failed steps, MUST use \`retry\`**",
9091
}),
9192

9293
action: (sampling?: boolean): JSONSchema => ({
@@ -115,10 +116,10 @@ Workflow step definitions - provide ONLY on initial call.
115116
...pick(depGroups, currentStep.actions),
116117
} as Record<string, JSONSchema>;
117118

118-
stepDependencies["proceed"] = this.proceed();
119+
stepDependencies["decision"] = this.decision();
119120
stepDependencies["action"] = this.action();
120121

121-
// Make proceed required when workflow is in progress and needs user decision
122+
// Make decision required when workflow is in progress and needs user decision
122123
return this.common(stepDependencies);
123124
},
124125

@@ -218,10 +219,10 @@ Workflow step definitions - provide ONLY on initial call.
218219
...pick(depGroups, nextStep.actions),
219220
} as Record<string, JSONSchema>;
220221

221-
stepDependencies["proceed"] = this.proceed();
222+
stepDependencies["decision"] = this.decision();
222223
stepDependencies["action"] = this.action();
223224

224-
// Make proceed required for next state transitions
225+
// Make decision required for next state transitions
225226
return this.common(stepDependencies);
226227
},
227228

packages/core/src/prompts/index.ts

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,14 @@ export const SystemPrompts = {
6060
6161
**⚡ SUBSEQUENT CALLS (Execution):**
6262
- Provide ONLY current step parameters
63-
- **ADVANCE STEP**: Set \`proceed: true\` to move to next step
64-
- **RETRY STEP**: Set \`proceed: false\`
63+
- **ADVANCE STEP**: Set \`decision: "proceed"\` to move to next step
64+
- **RETRY STEP**: Set \`decision: "retry"\`
65+
- **COMPLETE WORKFLOW**: Set \`decision: "complete"\` (only at final step)
6566
- Use \`reasoning\` action for thinking/analysis
6667
6768
**🚫 Do NOT include \`steps\` parameter during normal execution**
6869
**✅ Include \`steps\` parameter ONLY when restarting workflow with \`init: true\`**
69-
**⚠️ CRITICAL: When retrying failed steps, NEVER use \`proceed: true\`**`,
70+
**⚠️ CRITICAL: When retrying failed steps, MUST use \`decision: "retry"\`**`,
7071

7172
/**
7273
* Sampling execution system prompt with JSON output constraints
@@ -142,7 +143,7 @@ You MUST respond with a JSON object for workflow execution:
142143
**For Step Execution (Subsequent Calls):**
143144
- action: "{toolName}" OR "complete" when workflow is autonomously determined finished
144145
- reasoning: Your independent analysis of current step and next decision
145-
- proceed: true (advance to next step) OR false (retry/repeat current step)
146+
- decision: "proceed" (advance to next step), "retry" (retry/repeat current step), or "complete" (finish workflow)
146147
- [step parameters]: Tool-specific parameters you autonomously determine for current step
147148
148149
**🎯 AGENTIC WORKFLOW CONSTRAINTS:**
@@ -154,7 +155,7 @@ You MUST respond with a JSON object for workflow execution:
154155
155156
**🚫 Do NOT include \`steps\` parameter during normal execution**
156157
**✅ Include \`steps\` parameter ONLY when restarting workflow with \`init: true\`**
157-
**⚠️ CRITICAL: When retrying failed steps, NEVER use \`proceed: true\`**`,
158+
**⚠️ CRITICAL: When retrying failed steps, MUST use \`decision: "retry"\`**`,
158159
};
159160

160161
/**
@@ -175,9 +176,10 @@ export const WorkflowPrompts = {
175176
- **Include 'steps' parameter ONLY when restarting workflow (with 'init: true')**
176177
- **Do NOT include 'steps' parameter during normal step execution**
177178
- **MUST Use the provided JSON schema definition above for parameter generation and validation**
178-
- **ADVANCE STEP: Set 'proceed' to true to advance to next step**
179-
- **RETRY STEP: Set 'proceed' to false to re-execute current step**
180-
- **⚠️ CRITICAL: When retrying failed steps, MUST set 'proceed' to false**
179+
- **ADVANCE STEP: Set 'decision' to "proceed" to advance to next step**
180+
- **RETRY STEP: Set 'decision' to "retry" to re-execute current step**
181+
- **COMPLETE WORKFLOW: Set 'decision' to "complete" to finish workflow (only at final step)**
182+
- **⚠️ CRITICAL: When retrying failed steps, MUST set 'decision' to "retry"**
181183
182184
{workflowSteps}`,
183185

@@ -208,11 +210,11 @@ Previous step completed. Choose your action:
208210
209211
**🔄 RETRY Current Step:**
210212
- Call \`{toolName}\` with current parameters
211-
- ⚠️ CRITICAL: Set \`proceed: false\`
213+
- ⚠️ CRITICAL: Set \`decision: "retry"\`
212214
213215
**▶️ PROCEED to Next Step:**
214216
- Call \`{toolName}\` with parameters below
215-
- Set \`proceed: true\`
217+
- Set \`decision: "proceed"\`
216218
217219
Next step: \`{nextStepDescription}\`
218220
@@ -227,11 +229,11 @@ Next step: \`{nextStepDescription}\`
227229
228230
Current step executed {statusText}. Choose your next action:
229231
230-
**1. ▶️ Complete Workflow:** Call \`{toolName}\` with \`proceed: true\` to finish
231-
**2. 🔄 Retry Final Step:** Call \`{toolName}\` with final step parameters
232+
**1. ▶️ Complete Workflow:** Call \`{toolName}\` with \`decision: "complete"\` to finish
233+
**2. 🔄 Retry Final Step:** Call \`{toolName}\` with final step parameters and \`decision: "retry"\`
232234
**3. 🆕 New Workflow:** Call \`{toolName}\` with \`init: true\`{newWorkflowInstructions}
233235
234-
**Note:** Use \`proceed: true\` to officially complete the workflow.`,
236+
**Note:** Use \`decision: "complete"\` to officially complete the workflow.`,
235237

236238
/**
237239
* Workflow completion success message
@@ -306,7 +308,7 @@ Choose the next action that best advances toward completing the user's request.`
306308
*/
307309
ERROR_RESPONSE: `Action argument validation failed: {errorMessage}`,
308310
WORKFLOW_ERROR_RESPONSE: `Action argument validation failed: {errorMessage}
309-
Set \`proceed: false\` to retry the current step.`,
311+
Set \`decision: "retry"\` to retry the current step.`,
310312

311313
/**
312314
* Completion message

packages/core/src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ export interface ArgsDefCreator {
2525
) => JSONSchema;
2626
steps: () => JSONSchema;
2727
init: () => JSONSchema;
28-
proceed: () => JSONSchema;
28+
decision: () => JSONSchema;
2929
action: () => JSONSchema;
3030
forTool: () => JSONSchema;
3131
forCurrentState: (

0 commit comments

Comments
 (0)