Instruction file imported from seiggy/apim-demo-infrastructure (
.github/instructions/sequential-thinking-workflow.instructions.md). Copyright stays with the author.
Purpose
Drive the MCP tool sequentialthinking with a deterministic, no-deviation state machine to maximize branching/revision features and produce a single correct answer.
Tool Contract (authoritative)
- name:
sequentialthinking - required args (every call):
thought: string,thoughtNumber: integer>=1,totalThoughts: integer>=1,nextThoughtNeeded: boolean - optional args:
isRevision?: boolean,revisesThought?: integer>=1,branchFromThought?: integer>=1,branchId?: string,needsMoreThoughts?: boolean
Guardrails (must obey)
- Monotonic counter: start
t=1; increment by exactly 1 on every call (linear, branch, or revision). - Estimate discipline: ensure
T >= t; if not, setT = t. - Branching: if branching, always pass both
branchFromThought=<origin>and a stablebranchIdreused for that branch. - Revision: if revising, set
isRevision=trueandrevisesThought=<n>; still incrementt. - Stop switch: set
nextThoughtNeeded=falseonly on the final synthesis step. - No hidden thought steps: every reasoning hop triggers exactly one tool call.
Minimal State
t(current thoughtNumber), init1T(totalThoughts estimate), init a small, honest estimate (e.g.,5)branches(set/map of known branchIds), init emptydone(bool), initfalse
Loop (deterministic)
While done == false:
- Plan the next step text for
thought:- Linear progress, or
- Start/continue a branch (choose/retain
branchId), or - Do a revision (
isRevision,revisesThought).
- Assemble arguments (always include required fields):
thought,thoughtNumber=t,totalThoughts=T,nextThoughtNeeded=true- Add either branch fields or revision fields if applicable (never both in the same call).
- Call tool
sequentialthinkingwith the JSON arguments. - Parse response JSON and update local state:
- If
nextThoughtNeededin the response isfalse, setdone=true. - Sync known
branchesfrombranches[]. - If response shows
t > T, setT = t.
- If
- Advance:
t = t + 1. - Heuristic adjust: If more analysis is clearly needed, optionally increase
T(do not rely onneedsMoreThoughtsfor control flow).
Finalization
When ready to answer, issue one last call with nextThoughtNeeded=false, then emit the final answer to the user (no further tool calls).
Pre-Call Checklist (every step)
-
thoughtis a single, clear action (derive, test, compare, decide, etc.). -
tincrements by 1 since last call. -
T >= t(if not, setT=t). - If branching: include both
branchFromThoughtand persistentbranchId. - If revising: include
isRevision=trueandrevisesThought. - Not mixing branch + revision flags in the same step.
-
nextThoughtNeeded=trueunless this is the final synthesis step.
Canonical Call Templates
Kick-off (Thought 1)
{
"tool": "sequentialthinking",
"arguments": {
"thought": "Define the problem, constraints, success criteria, and initial plan.",
"thoughtNumber": 1,
"totalThoughts": 5,
"nextThoughtNeeded": true
}
}
Linear Progress
{
"tool": "sequentialthinking",
"arguments": {
"thought": "Decompose subproblems and outline solution paths.",
"thoughtNumber": <t>,
"totalThoughts": <T>,
"nextThoughtNeeded": true
}
}
Start/Continue Branch
{
"tool": "sequentialthinking",
"arguments": {
"thought": "Branch A: explore alternative, collect pros/cons, constraints, costs.",
"thoughtNumber": <t>,
"totalThoughts": <T>,
"branchFromThought": <originThoughtNumber>,
"branchId": "A1",
"nextThoughtNeeded": true
}
}
Revision
{
"tool": "sequentialthinking",
"arguments": {
"thought": "Revision: correct/upgrade earlier assumption and update plan.",
"thoughtNumber": <t>,
"totalThoughts": <T>,
"isRevision": true,
"revisesThought": <n>,
"nextThoughtNeeded": true
}
}
Synthesis & Finalize (last call)
{
"tool": "sequentialthinking",
"arguments": {
"thought": "Synthesize evidence, select best option, justify trade-offs, and state final answer.",
"thoughtNumber": <t>,
"totalThoughts": <T>,
"nextThoughtNeeded": false
}
}
Prohibited
- Skipping a tool call for any reasoning step.
- Setting
nextThoughtNeeded=falsebefore synthesizing. - Branching without both
branchFromThoughtandbranchId. - Rewriting history without
isRevision/revisesThought.