Plan and reason before acting
Curated. Written from research and curation. Not run in our harness yet.
The job
Our agent should work out what it is going to do before it does it, keep doing that while it works, and not tell us it did something it did not do.
The approach
Keep the reasoning adjacent to the action, and keep the plan small, typed and written down.
Three parts. First, let the model decide how much to reason on each turn, and steer it with the effort parameter rather than with prose. Set one top-level effort per conversation and hold it, because the resolved effort value is rendered into the prompt and changing it between requests invalidates cache breakpoints. To vary thinking per turn without touching the cache, use the beta per-message effort change, or the two documented steering phrases on the user turn. Second, hold the plan as a validated object: an id, a state from a closed set, and an evidence field, per step. Write it to a store outside the conversation, keyed by task id. State changes by writing, never by saying. Third, re-plan only on three named triggers (a tool returned an error, an observation contradicts the plan, the instruction changed) and cap the count.
What this buys: reasoning where reasoning pays, and a plan that cannot silently go stale or be narrated into existence.
A large upfront plan document with a human approval gate before any action. This is what both major coding harnesses ship, so it is the default answer. It is not the default here for three reasons. The gate is leaky in practice, and a builder who assumes otherwise is wrong about their own safety property: Claude Code issue 101504 is plan mode executing commands without permission, and issue 100192 is plan mode ignoring the MCP tool allow list. The artifact goes stale while execution runs, which issue 101544 shows as a plan's exit table carrying across runs. And a mode is the wrong trigger, because it makes the user ask whether a task deserves planning and then remember a toggle, which Codex issue 53921 shows desyncing in a real client. Keep the gate for the subset of actions where a human must sign off before an effect is published, and treat it as one step in the plan rather than as the architecture. The two compose.
Planner and executor as separate models, with search over candidate plans. Tree of Thoughts (arXiv 2305.10601), Language Agent Tree Search (arXiv 2310.04406), LLM+P (arXiv 2304.11477) and the LLM-Modulo framing (arXiv 2402.01817) are the canonical statements, with Plan-and-Solve (arXiv 2305.04091) as the zero-shot ancestor. This dominates in domains with a simulator or a formal checker because a cheap verifier exists there. Without one, the scoring is another model opinion. arXiv 2609.38108 names the deeper problem: selecting a plan and executing it faithfully are separately failing capabilities, so end success cannot tell you which one failed. If you adopt this, score the two stages separately.
A framework that owns the loop. LangGraph, Pydantic AI and the OpenAI Agents SDK all give you persistence, interrupts and resume, and any of them is a reasonable host for these steps. They are not the approach because the plan object described here is a dozen fields and a store write, and the failure modes in the traps section belong to the harness, not to the framework. Adopt one when you also want checkpointing, human in the loop primitives and time travel, which are different recipes. Pydantic AI's own planning docs are worth reading either way.
What you need
Every URL below was fetched or queried on 2026-10-14. "Not applicable" means the item is a documentation page or a hosted provider feature with no package version and no software licence. "Unconfirmed" means the metadata did not carry the value and it was not guessed.
| Component | Version | Licence | Link |
|---|---|---|---|
| Claude adaptive thinking, effort, per-message steering | not applicable, provider feature | not applicable | https://platform.claude.com/docs/en/build-with-claude/thinking-steering-and-cost |
| Claude effort parameter | not applicable | not applicable | https://platform.claude.com/docs/en/build-with-claude/effort |
| Claude thinking overview, includes interleaved thinking | not applicable | not applicable | https://platform.claude.com/docs/en/build-with-claude/thinking |
| Claude thinking in tool and multi-turn workflows | not applicable | not applicable | https://platform.claude.com/docs/en/build-with-claude/thinking-tool-workflows |
| Claude thinking troubleshooting | not applicable | not applicable | https://platform.claude.com/docs/en/build-with-claude/thinking-troubleshooting |
| Build an orchestration mode, worked example | not applicable | not applicable | https://platform.claude.com/docs/en/build-with-claude/mid-conversation-effort-example |
| Claude mid-conversation system messages | not applicable | not applicable | https://platform.claude.com/docs/en/build-with-claude/mid-conversation-system-messages |
| Claude preserved thinking | not applicable | not applicable | https://platform.claude.com/docs/en/build-with-claude/preserved-thinking |
| Extended thinking (legacy, migrate off it) | not applicable | not applicable | https://platform.claude.com/docs/en/build-with-claude/extended-thinking |
| OpenAI reasoning guide, summaries and mid-turn steering | not applicable | not applicable | https://developers.openai.com/api/docs/guides/reasoning |
| Anthropic Python SDK | 1.14.0, uploaded 2026-10-14 (PyPI) | MIT | https://github.com/anthropics/anthropic-sdk-python |
| Anthropic TypeScript SDK | 0.134.0 (npm latest, 2026-10-14) | MIT | https://github.com/anthropics/anthropic-sdk-typescript |
| OpenAI Python SDK | 3.31.0, uploaded 2026-10-14 (PyPI) | Apache-2.0 | https://github.com/openai/openai-python |
| OpenAI Node SDK | 7.33.0 (npm latest, 2026-10-14) | Apache-2.0 | https://github.com/openai/openai-node |
| Pydantic | 2.14.1, uploaded 2026-10-11 (PyPI) | MIT | https://github.com/pydantic/pydantic |
| Zod | 4.6.7 (npm latest) | MIT | https://github.com/colinhacks/zod |
| jsonschema (Python) | 4.26.0, uploaded 2026-01-07 (PyPI) | MIT | https://github.com/python-jsonschema/jsonschema |
| Ajv | 8.20.0 (npm latest, published 2026-04-24) | MIT | https://github.com/ajv-validator/ajv |
| Instructor | 1.17.0, uploaded 2026-09-09 (PyPI) | MIT | https://github.com/567-labs/instructor |
| json-repair | 0.64.0, uploaded 2026-10-09 (PyPI) | MIT | https://github.com/mangiucugna/json_repair |
| SQLite, zero dependency local store | unconfirmed, the project publishes no pinned "latest" number | public domain | https://sqlite.org/ |
| PostgreSQL, if you already operate one | unconfirmed, no specific version is required | PostgreSQL License | https://www.postgresql.org/ |
| LangGraph, Python | 1.2.15, uploaded 2026-10-12 (PyPI) | MIT | https://github.com/langchain-ai/langgraph |
LangGraph, npm @langchain/langgraph (separate version line) | 1.5.0, published 2026-10-12 | MIT | https://www.npmjs.com/package/@langchain/langgraph |
| LangGraph persistence docs | not applicable | not applicable | https://docs.langchain.com/oss/python/langgraph/persistence |
| Pydantic AI | 2.56.0, uploaded 2026-10-13 (PyPI) | MIT | https://github.com/pydantic/pydantic-ai |
| Pydantic AI planning docs | not applicable | not applicable | https://pydantic.dev/docs/ai/harness/planning/ |
OpenAI Agents SDK (PyPI openai-agents) | 0.23.1, uploaded 2026-10-02 (PyPI) | MIT | https://github.com/openai/openai-agents-python |
| Outlines, only if you constrain decoding instead of validating after | 1.3.3, uploaded 2026-08-06 (PyPI) | Apache-2.0 | https://github.com/dottxt-ai/outlines |
The demo harness in the official orchestration example runs on claude-opus-5-5 at effort xhigh. That is the documented example's choice, not a requirement.
Three configuration facts, all confirmed in the docs on 2026-10-14:
- Effort is set at
output_config.effort, at the top level of the request, not inside thethinkingobject. The top-level parameter needs no beta header. The per-message effort change is in beta. - The default effort is
highon every model that supports effort except Claude Opus 5.5 and Claude Haiku 5.5, where it ismedium.xhighis the docs' recommended starting point for agentic and coding work, andmaxis available on the frontier models only. Availability is per model and the effort page's availability table is the authority. - Extended thinking (
thinking: {type: "enabled", budget_tokens: N}) is deprecated on the Claude 4.6 models, where requests still succeed, and is rejected with a 400 on Claude 4.7 and later. Claude Opus 4.6 has no interleaved thinking in manual mode at all, so it must use adaptive thinking to reason between tool calls.
Steps
- Define the trigger from task properties, not from a mode. Write the predicate down and put it in code: plan when the action is irreversible or publishes outside the agent's own workspace, when the task needs more tool calls than your stated floor, when it spans more than one system, or when a budget is attached. Below the floor, act directly. Do not ask the user to pick a mode or remember a toggle.
- Pick one top-level effort level per conversation and keep it there.
xhighis the documented starting point for agentic work;highis the default on most models. Changing the top-level effort between requests invalidates cache breakpoints, so it is a conversation-level decision, not a per-turn one. - Vary reasoning per turn with the two cache-safe levers. Append the documented phrases to the user turn:
Please think hard before responding.to encourage thinking on a planning or diagnosis turn, andAnswer directly without deliberating.on a routine confirmation. On Claude Haiku 5.5 the discouraging phrase does not reliably work, so use the beta per-message effort change there instead. Do not try to turn thinking down by editing the system prompt. - Do not force one long deliberation up front. Adaptive thinking interleaves with tool use automatically and needs no beta header and no extra configuration. Let the model reason between tool calls, which is where the plan correction happens in practice.
- Define the plan as a schema before writing any code. One array of steps, each with an
id, adescription, astatefrom the closed setpending,in_progress,done,blocked,abandoned, and anevidencefield that is required whenever the state isdone. Nothing else is required. A shape that works:
```json
{
"task_id": "string",
"version": 1,
"updated_at": "RFC3339",
"steps": [
{"id": "s1", "description": "string", "state": "pending", "evidence": null}
],
"replans": 0
}
```
- Validate every model-produced plan, and repair rather than trust. Pydantic in Python, Zod in TypeScript, or a JSON Schema with jsonschema or Ajv. Use Instructor or the provider's structured output to constrain generation where it is available. On malformed output, run json-repair once and re-validate, or reject and retry. Never accept an unvalidated plan into the loop.
- Persist the plan outside the conversation, keyed by task id. A row in SQLite or Postgres is enough. The conversation may be compacted or truncated; the plan must not be. This is the step that makes step 8 checkable.
- Change state only through a write, and check the store rather than the message. Before any side effect, read the plan object back. A step is
doneonly if itsevidencefield is non-empty. If the model says it recorded something and the store disagrees, the store wins. - Re-plan on a named trigger only, and bound it. Allowed triggers: a tool returned an error, an observation contradicts a plan assumption, or the instruction changed. Increment
replansand stop at a stated maximum, then surface the failure to the caller. - Fail closed at the step boundary. When a step fails, stop the chain. Decide the failure policy once and assert it is honoured with a deliberate tool failure in the test, because a parallel run has been observed swallowing an explicit raise policy and running the downstream agents anyway (CrewAI issue 8088, fix in pull request 8089).
- Gate the irreversible subset, and test the gate. The gate is one step in the plan object, not a mode. Before the first publishing action, require approval. Then put a command in the test that must not run and assert that it did not, because plan mode has been found executing commands without permission (Claude Code issue 101504) and ignoring a tool allow list (issue 100192).
- Measure declaration against execution, and watch the object's token cost. Record the declared plan and the trajectory, then compare them; arXiv 2610.12375 is the streaming form of that check. Score plan selection and plan execution as two numbers, per arXiv 2609.38108. Track what the plan costs per run, and keep any plan reminder at a stable prefix position so prompt caching survives.
Traps
- Raising the top-level effort mid-run to think harder at the planning step. The mistake is treating
output_config.effortas a per-turn knob. Why agents make it: it is a request parameter, so it looks per-request, and raising it for the hard turn feels free. The docs state the opposite, that the resolved effort value is rendered into the prompt, that consecutive requests must keep the same thinking configuration and effort level to preserve caching, and that the practical consequence is to pick a level per conversation and keep it. The fix is step 2 for the conversation level and step 3 for the per-turn variation. On a plan and execute loop this is the same failure as Codex issue 52942, where the plan execution context grew from 27k to 174k tokens in four minutes. - Narrating plan state that was never written. The agent says a decision was recorded or a table was updated and the artifact disagrees. Why agents make it: the text channel is what the model actually controls, and writing to a store is extra plumbing that the demo does not need. The failure is invisible to a test that only checks the final answer, which is why it survived into three separate Claude Code issues (101628, 101544, 102099). The fix is steps 7 and 8: the state is a row, the check reads the row.
- Marking a step done on the model's own say so. The mistake is accepting a self report as evidence. Why agents make it: a summary of work already done reads exactly like evidence that the work was done. The fix is the required
evidencefield with a closed rule, a step with empty evidence is not done, whatever the message says. - Writing the plan as prose. The mistake is letting the plan be paragraphs, because paragraphs are what a model produces by default and a long plan reads as thorough. The documented result is that a longer spec "contained more information without creating more clarity". The fix is the typed object at step 5, validated at step 6. Prose length is not evidence of thinking, and nothing downstream can check a paragraph.
- Assuming the approval gate is airtight. The mistake is shipping a gate that the harness will route around. Why agents make it: the gate is a product feature with a dialog, so it reads as a guarantee. It is not one. The fix is step 11, which turns the assumption into a test that fails when the gate leaks.
- A failed step that silently continues. The mistake is leaving the failure policy at the framework default. Why agents make it: the default is to continue, which makes the demo complete, and a parallel planning path can also swallow an explicit raise policy. The fix is step 10, and assert the policy rather than configuring it.
- Over-planning trivial work. The mistake is applying a newly learned planning discipline to every task, including the one step ones. Why agents make it: the instruction says to plan, and nothing in it says when not to. The cost is latency, tokens and a fresh chance to get the plan wrong. The fix is the floor in step 1, written as a predicate.
- Confusing plan quality with execution quality. The mistake is reading a green end to end run as proof that the plan was good. Why agents make it: end success is the only signal most harnesses record. arXiv 2609.38108 shows the two are separately failing capabilities. The fix is two scores at step 12, which is the only way to know which half to repair.
- Copying
thinking: {type: "enabled", budget_tokens: N}from an older example. The mistake is teaching the previous generation. Why agents make it: the pattern is everywhere in older notes, and the legacy page still serves and still works on older models, so the code looks correct until it runs on a current one, where it is a 400 whose message starts with"thinking.type.enabled" is not supported. The fix is adaptive thinking and a top level effort. If a model genuinely supports only manual mode, the extended thinking page describes the supported configuration, and no change is needed until you move models. - Sending the interleaved thinking beta header. The mistake is adding
interleaved-thinking-2025-05-14because a note said thinking with tools needs it. Why agents make it: older guidance said so, and the Claude API accepts the header on any model and ignores it where unsupported, so nothing errors. Acceptance is not effect. The fix is to send nothing: adaptive thinking interleaves automatically with no header and no additional configuration.
Scope
Covers: deciding from task properties when an agent must plan rather than act; choosing and holding an effort level and varying reasoning per turn without breaking the prompt cache; letting reasoning interleave with tool calls; representing a plan as a validated typed object; persisting it outside the conversation; changing step state only by writing and checking declared state against evidence before a side effect; naming re-plan triggers and bounding the count; failing closed at a step boundary; gating irreversible actions and testing the gate; and measuring the declared plan against the executed one.
Does not cover, and these are other recipes: tool schema authoring, tool selection and deferred tool loading; retrieval, memory and context compaction design; assigning work across multiple agents and roles; building an evaluation harness; provider pricing and any claim about which model reasons best; and checkpointing, interrupts, resume after failure and time travel, which are harness features you may adopt alongside this recipe. It also does not cover a plan document format intended for a human to read. The sources themselves say that problem is open, and this page does not imply otherwise. It does not cover self critique and refinement loops (Reflexion, Self-Refine) as a substitute for a checked plan, and it does not cover planning benchmarks or leaderboards.
This recipe is curated and nothing here has been run end to end. The claim most likely to break on first contact is the per-message steering phrase behaviour, because it is a wording sensitive mechanism and the docs already flag one model where it does not hold. The second is the cache claim in step 2, because the difference between the top level effort parameter and the beta per-message effort change is one sentence in the docs and it decides whether a long run keeps its cached prefix. Both are cheap to settle with one run record.
Sources
Provider and component documentation, SDKs and libraries are linked in full in the table above.
Paper titles and dates taken from the arXiv API on 2026-10-14.
- Tree of Thoughts, arXiv 2305.10601. https://arxiv.org/abs/2305.10601
- Language Agent Tree Search, arXiv 2310.04406. https://arxiv.org/abs/2310.04406
- LLM+P, arXiv 2304.11477. https://arxiv.org/abs/2304.11477
- LLM-Modulo framing, arXiv 2402.01817. https://arxiv.org/abs/2402.01817
- Plan-and-Solve, arXiv 2305.04091. https://arxiv.org/abs/2305.04091
- Plan selection and plan execution as separately failing capabilities, arXiv 2609.38108, published 2026-09-29. https://arxiv.org/abs/2609.38108
- Streaming check of declared plan against trajectory, arXiv 2610.12375, published 2026-10-08. https://arxiv.org/abs/2610.12375
- arXiv 2607.23670, published 2026-07-26. https://arxiv.org/abs/2607.23670
Issue and pull request evidence, reproduced from the source brief rather than independently re-pulled: Claude Code issues 101504, 100192, 101544, 101628, 102099; Codex issues 53921, 52942; CrewAI issue 8088 and pull request 8089; Pydantic AI pull request 9733, fix(planning): prevent unusable generated step IDs, open since 2026-10-03.
Could not confirm, and left unconfirmed rather than guessed: the SQLite and PostgreSQL versions, since neither is a dependency the recipe pins; the smolagents licence; the Outlines repository's activity; the Anthropic TypeScript SDK and OpenAI Node SDK repository star and push data; and the individual reranker style provider versions that the sibling memory recipe also leaves open.
Rules and labels: How we choose · machine form: /recipes/plan-and-reason.json · all recipes