How Agents Reason and Decompose Tasks

Breaking a goal into steps that can be checked, ordered and, where safe, run at the same time.

BeginnerIntermediateExpert · 12 min read · Last updated:

In short

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.

Beginner Thinking in steps

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.

Goalwhat done looks like
Decomposesteps and dependencies
Executetools and model calls
Checkeach output
Combinefinal result
↺ A failed check revises the remaining plan
Reasoning is useful when its steps can be inspected and corrected.

Styles of reasoning

StyleHow it worksUse when
Direct answerThe model replies at onceSimple lookups and classification
Chain of thoughtThe model writes steps before the answerProblems with several linked steps
Self-consistencySample several reasoning paths; take the most common answerAnswers that can be compared, where accuracy justifies the cost
Least-to-mostList simpler sub-problems, then solve them in orderProblems harder than the examples you can show
Interleaved reasoning and actionThink, call a tool, observe, think againThe next step depends on new information; see ReAct Agents: Reasoning and Acting
Plan then executeMake a plan, then carry it outLong 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.
Match effort to difficulty

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.

Intermediate Decomposing a task

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 byExampleWatch for
StageCollect, clean, calculate, reportErrors passing silently to later stages
Data itemSummarize each of 40 contracts, then combineInconsistent formats between items
QuestionResearch three sub-questions separatelyGaps between questions; overlapping work
ExpertiseLegal check and financial checkConflicting advice with no one to decide
HierarchyLarge goal into subgoals into actionsExcessive depth and bookkeeping
RiskRead-only investigation, then approved changesChanges 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:

StepNeedsProducesCheck
1. Fix the questionThe requestDates to compare and ticket types includedRequester confirms if ambiguous
2. Count ticketsStep 1Counts per day and category for both weeksTotals match the ticket system
3. Find the changeStep 2Categories that grew mostComputed in code
4. Read samplesStep 3Themes with example ticket identifiersEach theme cites real tickets
5. Look for eventsStep 1Releases, outages and price changes in the periodTaken from change records
6. ExplainSteps 3, 4 and 5Likely causes, evidence and open questionsReviewer; 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.

Coordinatorassigns bounded tasks with all needed context
Worker Aregion north
Worker Bregion south
Worker Cregion west
Combine and checksame format, totals reconcile, gaps reported
Fan out for independent work, then verify when joining.

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.

Expert Control, replanning and failure

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.

Replanning must not widen authority

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

FailureSignRemedy
Too many tiny stepsHigh cost, slow, context lost between stepsMerge steps that share inputs and a check
Steps too largeVague outputs that cannot be verifiedRequire a concrete output per step
Missing stepFinal answer ignores a constraintCheck the plan against the success criteria
False independenceParallel results conflictDeclare shared resources; run those in order
Lost intentWorkers solve an easier problemPass the original goal and constraints to each
Silent partial resultReport omits failed itemsRequire 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.

Illustrative example: supplier review

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.

Move certainty into code

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

Next steps