How Agents Reason and Decompose Tasks
Breaking a goal into steps that can be checked, ordered and, where safe, run at the same time.
An agent reasons by producing intermediate work before it acts. Decomposition turns a goal into smaller steps, each with a clear output and a way to check it. Write the plan as data with dependencies, so that code can validate it, run independent steps together and resume after a failure.
What you will learn: the main styles of model reasoning, what reasoning models change, how to split a task well, how to represent a plan, when to run or delegate steps in parallel, and how decomposition goes wrong.
Prerequisites: The Agent Loop: Observe, Reason, Plan, Act, Reflect and How LLMs Power Agents: Transformers, Tokens and Sampling.
What "reasoning" means here
When a person faces "prepare the monthly margin report", they do not write it in one stroke. They gather figures, check them, calculate, compare with last month and then write. An agent does something similar: it produces intermediate text, chooses actions, reads results and adjusts.
In this site, reasoning means that observable process of working toward a goal through intermediate steps. It is a useful engineering term, not a claim that a model thinks as people do. What matters in practice is whether the steps lead to correct, checkable results.
Styles of reasoning
| Style | How it works | Use when |
|---|---|---|
| Direct answer | The model replies at once | Simple lookups and classification |
| Chain of thought | The model writes steps before the answer | Problems with several linked steps |
| Self-consistency | Sample several reasoning paths; take the most common answer | Answers that can be compared, where accuracy justifies the cost |
| Least-to-most | List simpler sub-problems, then solve them in order | Problems harder than the examples you can show |
| Interleaved reasoning and action | Think, call a tool, observe, think again | The next step depends on new information; see ReAct Agents: Reasoning and Acting |
| Plan then execute | Make a plan, then carry it out | Long tasks with predictable structure; see Plan-and-Execute and Dynamic Planning |
Chain-of-thought prompting was shown to improve performance on multi-step problems by asking the model, through examples, to write intermediate steps. Self-consistency builds on it by sampling many paths and choosing the answer they agree on most. Least-to-most prompting first reduces a hard problem to a list of easier ones and then solves them in sequence, using earlier answers.
Reasoning models
Many current models perform extended reasoning internally before they reply, often with a setting for how much effort to spend. This changes how you work with them:
- Cost. Reasoning tokens are normally billed as output tokens and occupy context, even when the text is not shown to you. Both OpenAI's and Claude's documentation describe this.
- Visibility. You may receive a summary or nothing, depending on the model and settings.
- Prompting. A clear goal, constraints and success criteria usually help more than dictating every thinking step. Check your provider's guidance.
- Effort. More effort tends to help hard problems and wastes time on easy ones. Set it per task type and measure.
Run your test cases at two or three effort levels. If the lowest level passes the routine cases, use it for them and reserve higher effort for the types that fail. See Model Routing, Fallbacks and Gateways.
What makes a good subtask
- One purpose. It can be described in a sentence without "and then".
- A defined output. A figure, a file, a list, a decision with a reason.
- A check. Code, a test, a source to compare with, or a reviewer.
- Stated inputs. Which earlier results it needs.
- A bounded size. It fits comfortably within one working context.
- Known side effects. Whether it only reads or also changes something.
Compare "analyze the sales data" with "return total sales by region for October from the orders table, and report any missing days". The second can be verified. The first can be declared complete by almost any output.
Ways to split a goal
| Split by | Example | Watch for |
|---|---|---|
| Stage | Collect, clean, calculate, report | Errors passing silently to later stages |
| Data item | Summarize each of 40 contracts, then combine | Inconsistent formats between items |
| Question | Research three sub-questions separately | Gaps between questions; overlapping work |
| Expertise | Legal check and financial check | Conflicting advice with no one to decide |
| Hierarchy | Large goal into subgoals into actions | Excessive depth and bookkeeping |
| Risk | Read-only investigation, then approved changes | Changes slipping into the investigation stage |
Write the plan as data
A plan in prose is hard to check. A plan as a structure, with step names and dependencies, can be validated before anything runs. Python's standard library can order such a plan:
"""Turn a goal into steps with dependencies, then run what can run together."""
from graphlib import TopologicalSorter, CycleError
# step: the steps it needs first
PLAN = {
"get_sales": set(),
"get_costs": set(),
"get_last_month": set(),
"check_data": {"get_sales", "get_costs"},
"compute_margin": {"check_data"},
"compare": {"compute_margin", "get_last_month"},
"write_summary": {"compare"},
}
MINUTES = {"get_sales": 4, "get_costs": 6, "get_last_month": 3,
"check_data": 2, "compute_margin": 1, "compare": 1,
"write_summary": 3}
def waves(plan):
"""Group steps that have no unfinished dependency."""
sorter = TopologicalSorter(plan)
sorter.prepare()
while sorter.is_active():
ready = sorted(sorter.get_ready())
yield ready
sorter.done(*ready)
if __name__ == "__main__":
parallel = 0
for number, ready in enumerate(waves(PLAN), start=1):
parallel += max(MINUTES[s] for s in ready)
print(f"wave {number}: {', '.join(ready)}")
print(f"one at a time: {sum(MINUTES.values())} min; in waves: {parallel} min")
broken = dict(PLAN, get_sales={"write_summary"})
try:
list(waves(broken))
except CycleError as error:
print("rejected plan with a cycle of", len(error.args[1]) - 1, "steps")
Output:
wave 1: get_costs, get_last_month, get_sales
wave 2: check_data
wave 3: compute_margin
wave 4: compare
wave 5: write_summary
one at a time: 20 min; in waves: 13 min
rejected plan with a cycle of 5 steps
Three data fetches have no dependencies, so they form the first wave. The rest must wait. The script also rejects a plan in which a step indirectly depends on itself, an error a model can easily make in a long plan. The minute figures are invented and assume enough workers to run a wave at once.
Intermediate representations
Between steps, pass structured results instead of free-flowing text where you can. A table, a typed record or a short JSON object with named fields lets the next step, and your tests, rely on it. Useful fields include the result, the sources used, assumptions made, confidence or open questions, and the status: done, partial or failed. Message Roles, Structured Output and Function Calling explains how to require a schema.
Ask a model for a plan in a fixed shape, for example: step identifier, action, required inputs, expected output, check, and whether it changes anything. Then validate it in code: every tool named exists, every input is produced by an earlier step, no forbidden action appears and the number of steps is within limit.
A worked decomposition
Take the request "tell me why support tickets rose last week". A weak plan has one step: ask a model to analyze the tickets. A better plan names what each step produces and how it is checked:
| Step | Needs | Produces | Check |
|---|---|---|---|
| 1. Fix the question | The request | Dates to compare and ticket types included | Requester confirms if ambiguous |
| 2. Count tickets | Step 1 | Counts per day and category for both weeks | Totals match the ticket system |
| 3. Find the change | Step 2 | Categories that grew most | Computed in code |
| 4. Read samples | Step 3 | Themes with example ticket identifiers | Each theme cites real tickets |
| 5. Look for events | Step 1 | Releases, outages and price changes in the period | Taken from change records |
| 6. Explain | Steps 3, 4 and 5 | Likely causes, evidence and open questions | Reviewer; no claim without evidence |
Steps 4 and 5 can run at the same time. Only two steps, reading themes and writing the explanation, truly need a model's judgment. The rest are queries and arithmetic, which are cheaper and exact. Notice also that step 6 reports likely causes: a rise that follows a release is a clue, not proof, and the output should say which it is.
Give each step the right context
Decomposition lets each step work with a small, focused context. That helps quality, but only if the step receives what it needs. For every step, decide which of these it gets: the original goal, the constraints, the results it depends on, the tools it may use, and the output shape. Leave out the rest. A step that receives the entire history behaves like no decomposition at all, while a step that receives only a title is likely to guess. Context Isolation, Provenance and Governance treats this in detail.
Keep results in a shared record outside the model, keyed by step identifier. Later steps read from it, restarts resume from it, and reviewers can see exactly which result fed which conclusion. See Stateful and Long-Running Agent Architecture.
Delegation and parallel execution
Steps may run together when they are independent: neither needs the other's result, and they do not write to the same place. Reading five documents is a good candidate. Two workers editing one file is not.
A delegated task needs a complete brief: the goal, relevant facts, constraints, the exact output shape and what to do if blocked. The worker does not share the coordinator's memory. Decide in advance what happens if one worker fails: retry it, continue and report the gap, or stop everything. See Supervisor and Orchestrator-Worker Patterns and Handoffs, Routing, Shared State and Communication.
Replanning
Plans meet surprises: a file is missing, a figure contradicts another, a permission is refused. Keep completed results, mark the failed step, and ask for a revised plan for the remainder only. Limit how often this may happen. Repeated replanning usually means the goal is unclear or something is broken, and the right action is to report that.
A revised plan is checked against the same permissions as the first. If the obvious path is blocked, the agent should say so instead of finding another route around a control. See Action Guardrails and Policy Engines.
How decomposition fails
| Failure | Sign | Remedy |
|---|---|---|
| Too many tiny steps | High cost, slow, context lost between steps | Merge steps that share inputs and a check |
| Steps too large | Vague outputs that cannot be verified | Require a concrete output per step |
| Missing step | Final answer ignores a constraint | Check the plan against the success criteria |
| False independence | Parallel results conflict | Declare shared resources; run those in order |
| Lost intent | Workers solve an easier problem | Pass the original goal and constraints to each |
| Silent partial result | Report omits failed items | Require status per step and a count on joining |
When not to decompose
Splitting adds calls, cost and places to fail. If one well-written request solves the task reliably, keep it. If the steps are always the same, write them as a fixed workflow in code rather than asking a model to plan them each time. Planning by model earns its place when the route truly varies between requests. Agent Limits, Myths and When Not to Use One discusses this choice.
An invented purchasing agent is asked to "review our suppliers". It first asks which period and criteria. It then fetches delivery, quality and price records separately, checks that supplier identifiers match across the three, scores each supplier with a fixed formula in code, and asks a model only to write explanations of the scores. Two suppliers with missing records are listed as unscored instead of being guessed.
Whenever a step can be expressed exactly, such as a sum, a filter or a rule, let code do it. Reserve model reasoning for the parts that need interpretation. This reduces cost and shrinks the surface you have to evaluate.
How to tell whether a step is small enough
Try a simple test: could a new colleague carry out this step from its description alone, and would two colleagues produce results you could compare? If either answer is no, the step still hides decisions. Surface them: add the missing input, name the output format or split the step at the point where a judgment is made. If the answer is yes and the step is trivial, consider merging it with its neighbor to save a model call.
Measuring decomposition
Track the share of plans that pass validation, the share of steps that pass their check first time, steps per completed task, replans per task and the final success rate. Compare against a single-call baseline on the same cases. If decomposition does not beat the baseline, remove it. See Reasoning Traces and Planning Benchmarks.
Decomposition checklist
- The goal has a written definition of done.
- Every step has inputs, an output and a check.
- Dependencies are explicit and checked for cycles.
- Steps that change things are marked and gated.
- Parallel steps share no writable resource.
- Failures and gaps appear in the final report.
- Replans are limited and stay within the same permissions.
Frequently asked questions
Should I ask a reasoning model to think step by step?
Usually it is more useful to state the goal, constraints and checks clearly and let the model decide how to think. Follow the guidance for your model and verify with tests.
Who should make the plan, the model or the developer?
If the steps are known, the developer. If they vary with each request, let the model propose them and let code validate the proposal.
How deep should a task hierarchy be?
As shallow as possible. Two levels cover most business tasks. Add depth only when a subgoal is still too large to check.
References and further reading
- Wei et al., Chain-of-Thought Prompting Elicits Reasoning
- Wang et al., Self-Consistency Improves Chain of Thought Reasoning
- Zhou et al., Least-to-Most Prompting
- OpenAI: Reasoning models guide
- Claude documentation: thinking
- Python documentation: graphlib
Next steps
Planning and Search Algorithms
Find good routes when many are possible.
Plan-and-Execute and Dynamic Planning
Turn a plan into reliable execution.
Reflection, Self-Critique and Self-Refine
Check and improve the results.