Skip to content

Module 02 · Lesson 2.3

Task Decomposition and Planning Strategies

40 minUpdated 18 Nov 2026Part of Agent Design and Instruction Engineering · AI Agent Development
On this page
  1. What you will learn
  2. What is task decomposition? Splitting a big job into small steps
  3. Three planning strategies: fixed, adaptive and no explicit plan
  4. Why step limits, stop rules and approvals must live in code
  5. Run a fixed plan in Python and stop at the first failed step
  6. How to choose a planning strategy for your agent
  7. Conclusion and your next step
  8. Common errors and fixes
  9. Validation checklist
  10. Hands-on exercise
  11. Knowledge check
  12. Frequently asked questions
  13. References

Nobody cooks a big dinner by standing in the kitchen and saying "make dinner". You follow a recipe: wash, chop, boil, taste, serve. Each small step is easy. The recipe also tells you the order, and what to do if the oven is broken.

An AI agent needs the same thing for its job. In this lesson you learn to split a goal into small steps, which is called task decomposition. You also learn three ways to plan those steps, and why some limits must live in code. Most of the lesson needs no coding. One short Python example at the end runs a plan step by step.

What you will learn

  • Split a goal into small steps that can each be checked.
  • Compare a fixed plan, an adaptive plan and no explicit plan.
  • Choose a planning strategy for a task by looking at predictability, cost and risk.
  • Run a short Python script that follows a fixed plan and stops at the first failed step.

Before you start

What is task decomposition? Splitting a big job into small steps

Task decomposition means splitting one big job into small steps. Think of a recipe. "Make lasagne" is a big job. "Boil the pasta for ten minutes" is a small step that anyone can do and check.

Small steps help an AI agent for the same reasons they help a cook. Each step is easier to get right. Each step is easier to test. When something goes wrong, you can see which step broke.

Step
One small action with a clear result. Example: look up an order.
Plan
The list of steps, in order, that gets the agent from the start to the goal.
Planning strategy
The way the plan is made: written in advance by people, or written and changed by the agent while it works.

Our running example: a bike return

Quillfeather Cycles is the made-up online bike shop we use throughout this program. Besides answering order questions, the shop wants help with a second job: returns. This is a separate returns workflow, not the order-status helper from earlier lessons. A customer wants to return a bike that was delivered. Here are the small steps:

  1. Find the order.
  2. Check that the order was delivered.
  3. Check that the delivery was within the shop's 30-day return window.
  4. Request the return. Staff must approve it.
The return plan as a chain of small steps
  1. Find the order

    lookup_order

  2. Delivered?

    Status must be delivered

  3. Within 30 days?

    Made-up shop rule

  4. Request return

    request_return, staff approve

Each step must succeed before the next one starts. The last step only asks. A person decides.

Three planning strategies: fixed, adaptive and no explicit plan

Once you have the steps, you must decide who controls them. There are three common choices. They run from "people decide everything" to "the agent decides everything".

1. Fixed plan: a recipe

In a fixed plan, people write the steps in advance. They always run in the same order, like a recipe. The AI model may still help inside a step, for example by writing a polite message. It does not change the order.

In Module 1 you met this as an LLM workflow in Chatbots vs. LLM Workflows vs. Tool-Using Agents: code controls the path, and the model does small jobs along the way. The bike return fits well. The four steps never change.

2. Adaptive plan: a satnav that re-routes

In an adaptive plan, the agent writes a plan first. After each result it looks again and updates the plan. A satnav does this. If a road is closed, it does not give up. It finds a new route.

Use it when you cannot know the steps in advance. Example: "Find out why this customer's parcel is late." The next step depends on what the last one showed.

3. No explicit plan: one step at a time

Here the agent writes no plan at all. At each moment it asks, "What is the best next step?" and does it. This is fine for short tasks of one to three steps, such as answering "What does dispatched mean?" with one lookup.

It gets risky as tasks grow. The agent can forget a step, repeat a step or wander off.

How the three compare

Fixed planAdaptive planNo explicit plan
Who decides the stepsPeople, in advanceThe agent, updated after each resultThe agent, one step at a time
PredictabilityHigh. Same order every time.Medium. The plan can change.Low. Hard to say what it will do.
CostLow. Few model calls.Higher. Extra calls to plan and re-plan.Low for short tasks, grows fast for long ones.
RiskLow. Easy to test.Medium. Needs strong limits.Highest for long tasks.
Best forKnown steps, such as the return check.Unknown steps, such as finding why a parcel is late.Quick jobs of one to three steps.
Start with the most fixed option that still does the job.

Why step limits, stop rules and approvals must live in code

A plan says what the agent should do. Limits say what it must never do, however it is planning. An adaptive agent without limits can loop forever, and a loop costs money with every model call.

Three limits every agent needs

  • Step limit: a maximum number of steps. For example, stop after 10 steps, even if the goal is not reached.
  • Stop on failure: if a step fails, stop, or hand over to a person. Do not carry on as if nothing happened.
  • Approval before risky steps: a person must say yes before the agent changes anything that matters, such as a return or a refund.

In the bike return plan, the last step is request_return. It only asks. Staff approve or refuse. That keeps a person in charge of the risky decision. The Agent Launch Safety Checklist lists more limits like these.

Run a fixed plan in Python and stop at the first failed step

The script below is a fixed plan. The steps are small functions kept in a list. A loop runs them in order. If a step fails, the loop stops. No AI model is needed, and nothing goes online.

Pythonfixed_plan.py
from datetime import date

TODAY = date(2026, 11, 18)  # fixed, so the output never changes
ORDERS = {
    "QF-1042": {"status": "dispatched", "delivered": None},
    "QF-1044": {"status": "delivered", "delivered": date(2026, 11, 9)},
}

def find_order(job):
    job["order"] = ORDERS.get(job["order_id"])
    return job["order"] is not None, "order found"

def check_delivered(job):
    return job["order"]["status"] == "delivered", "status is " + job["order"]["status"]

def check_window(job):
    days = (TODAY - job["order"]["delivered"]).days
    return days <= 30, f"{days} days since delivery (limit 30)"

def request_return(job):
    return True, "return requested, waiting for staff approval"

PLAN = [find_order, check_delivered, check_window, request_return]

def run_plan(order_id):
    job = {"order_id": order_id}
    print("Order", order_id)
    for number, step in enumerate(PLAN, start=1):
        ok, message = step(job)
        print(f"  step {number} {step.__name__}: {'OK' if ok else 'FAILED'} - {message}")
        if not ok:
            print("  stopped. Nothing was requested.")
            return
    print("  plan finished.")

run_plan("QF-1044")
run_plan("QF-1042")

Runs offline with Python 3.10 or later. Dates are fixed in the code, so your output matches ours. Run it with python fixed_plan.py.

What each part does

  • from datetime import date loads Python's built-in tool for working with calendar dates.
  • TODAY is a fixed date, not the real clock. That keeps the result the same on every run.
  • ORDERS is a dictionary, a list of pairs, that stands in for the shop's order system. Only these two orders exist.
  • Each step is a function, a named recipe you can reuse. It returns two things: True or False for success, and a short message.
  • find_order stores the order in job, a small dictionary that carries facts from step to step.
  • check_window counts the days between delivery and TODAY. The 30-day limit is the made-up shop rule.
  • request_return only reports that a request was made. In a real system it would call the request_return tool, and staff would approve.
  • PLAN is a list of the functions in order. This list is the fixed plan.
  • enumerate(PLAN, start=1) hands the loop each step together with its number: 1, 2, 3, 4. step.__name__ is the function's own name, used in the printout.
  • The for loop runs each step. When ok is False, it prints a message and return ends the run.
OutputCaptured from a real run
Order QF-1044
  step 1 find_order: OK - order found
  step 2 check_delivered: OK - status is delivered
  step 3 check_window: OK - 9 days since delivery (limit 30)
  step 4 request_return: OK - return requested, waiting for staff approval
  plan finished.
Order QF-1042
  step 1 find_order: OK - order found
  step 2 check_delivered: FAILED - status is dispatched
  stopped. Nothing was requested.

QF-1044 was delivered on 9 November, which is 9 days before our fixed date of 18 November, so all four steps pass. QF-1042 is still dispatched. It fails at step 2, and steps 3 and 4 never run. The loop is the "stop on failure" limit in action.

How to choose a planning strategy for your agent

Ask three questions about your task, in this order.

  1. Can I write the steps down today? If yes, use a fixed plan.
  2. Do the steps depend on what the agent finds? If yes, consider an adaptive plan, with a step limit.
  3. Is the task only one to three steps? If yes, no explicit plan may be enough.

Then check the risk. Does any step change money, data or a customer's account? If so, add an approval step, whichever strategy you chose.

Many real agents mix strategies. The bike return uses a fixed plan for the checks. A "why is my parcel late?" question could use an adaptive plan with only read-only tools. You will plan the tools in the next module, Tools, APIs and Function Calling.

Conclusion and your next step

Task decomposition turns a big goal into small steps that you can run and test. You can plan those steps in advance (fixed), let the agent update them (adaptive) or let it decide one step at a time (no explicit plan). Whichever you pick, keep the step limit, the stop-on-failure rule and the approval step in code.

Your next step: pick one task from your Module 1 agent map and write its steps as a numbered list. Mark the risky step. Then continue to Context Design: What the Agent Needs at Each Step, where you decide which facts the agent should see at each step of a plan.

Want more background first? Read Chain-of-Thought Prompting: A Practical Guide for Developers for the idea of reasoning step by step, or look up any new word in the Glossary of AI Engineering and Agent Terms.

Common errors and how to fix them

The agent skips a step or does the steps in the wrong order.

Why it happens: The plan lives only in the instructions, and the agent has no plan to follow in code.

Fix: If the steps are known, write them as a fixed plan in code, so the order cannot change.

The agent keeps going after a step failed.

Why it happens: Nothing in the code stops the run when a result is bad.

Fix: Check each step's result in code. Stop, or hand over to a person, at the first failure.

An adaptive agent loops and the bill grows.

Why it happens: There is no step limit, so the agent can keep re-planning.

Fix: Add a counter in code and stop at a fixed number of steps. Report what was done so far.

A risky action happens without anyone checking it.

Why it happens: The agent was allowed to finish the action itself.

Fix: Make the risky step only request the action, like request_return, and let a person approve it.

Validation checklist

Tick each item once you have confirmed it.

Hands-on exercise

Plan a book renewal for a library helper

A town library agent helps members renew a borrowed book. Write the steps, choose a planning strategy, and say which limits go in code.

You will need

  • A member can renew a book at most two times.
  • A book that another member has reserved cannot be renewed.
  • The library system has two tools: one that looks up a loan, and one that renews a book.
  • Late fees can only be removed by staff.

Acceptance criteria

Your work is done when every one of these is true.

Hints (3)
  • Think about the order. Which check should come before the renewal?
  • Ask whether you can write all the steps today. If yes, a fixed plan fits.
  • Renewing a book changes data. Is that risky enough to need approval?
Show a model answer

A strong answer uses a fixed plan, because the steps are known. Steps: (1) find the loan, (2) check that the book is not reserved, (3) check that the book has been renewed fewer than two times, (4) renew the book and report the new due date. Reason: the order never changes, so a fixed plan is predictable, cheap and easy to test. Limits in code: stop at the first failed step, a step limit of ten as a safety net, and a check that the renewal tool is only called after steps 2 and 3 pass. Approval: renewing one book is low risk and easy to undo, so a person does not need to approve it. Removing late fees is a different matter. That is out of scope and goes to staff.

Knowledge check

Choose an answer, then check it. Nothing is recorded — this is for you.

  1. 1.You know all the steps of a task in advance, and they never change. Which strategy fits best?
    Show the answer and explanation

    Answer: A. When the steps are known, a fixed plan is predictable, cheap and easy to test. The adaptive plan is tempting because it sounds smarter, but it adds cost and risk that this task does not need.

  2. 2.Where should a rule such as "stop after 10 steps" be enforced?
    Show the answer and explanation

    Answer: B. Code does exactly what it is told every time. The instructions can help, which makes the first option tempting, but a model may not follow them every time, and a missed limit can mean a loop that costs money.

  3. 3.In our example, QF-1042 is dispatched but not delivered. What does the fixed plan do?
    Show the answer and explanation

    Answer: B. The step fails, so the loop stops and no return is requested. Carrying on would be tempting if you wanted to be helpful, but a return for an order that has not arrived makes no sense, and guessing a date is a mistake the agent must never make.

Frequently asked questions

What is task decomposition in AI?

It means splitting a big goal into small steps that are easy to do and easy to check. It works like a recipe. Each step is simple, and together the steps reach the goal.

What is the difference between a fixed plan and an adaptive plan?

A fixed plan is written by people in advance and always runs in the same order. An adaptive plan is written by the agent, which updates it after each result. Think of a printed map compared with a satnav that re-routes when a road is closed.

Does every AI agent need a plan?

No. For very short tasks of one to three steps, the agent can simply decide the next step each time. Longer or riskier tasks need a plan, because the agent can forget or repeat steps without one.

How do I stop an AI agent from running forever?

Add a step limit in your code. Count each step, and stop when the count reaches a maximum such as 10. Also stop at the first failed step. Do not rely on the instructions alone.

Written by
PromptFable Editorial
Last updated 18 Nov 2026
Review
Reviewed by Waseem Nadir, Technical Reviewer
Last reviewed 27 Nov 2026

References

Primary sources for the technical details in this lesson. Vendor platforms change — check the official page if anything here looks different from what you see.

PromptFable is independent and is not affiliated with, endorsed by or sponsored by Anthropic, Google, OpenAI or any other vendor. Claude, Gemini, Google AI Studio and other product names are trademarks of their respective owners.