Planning multi-step tasks
As agents move beyond single decisions, they need a way to pursue goals that unfold over time. In practice, many useful tasks are not one action but a sequence of related steps that must be carried out in order. This lesson introduces how an LLM can be used to help plan those steps, while the surrounding Python program remains responsible for execution and control.
Framing a goal-oriented task for an LLM
Planning starts by expressing a task as a clear goal rather than a list of instructions. Instead of telling the model what to do step by step, we describe the outcome we want to achieve and any constraints that matter. This gives the LLM room to reason about how the task might be broken down.
In code, this usually means constructing a prompt that explains the goal and the current situation, without embedding execution logic into the prompt itself.
Asking an LLM to propose a sequence of steps
Once a goal is framed, we can ask the LLM to propose the steps needed to reach it. The model’s role is to suggest an ordered sequence of actions, not to perform them. Each step should be describable in a way the program can later interpret.
The LLM’s response is treated as a plan proposal, not as something that runs automatically.
Representing plans as structured data
For a plan to be useful in a program, it must be represented as data rather than free-form text. Common choices include lists of dictionaries or other simple structures that name each step and capture any required inputs.
This structure makes it possible to inspect, validate, and store the plan before execution begins.
plan = [
{"step": "load_data"},
{"step": "generate_page", "planet": "Mars"},
{"step": "write_output"}
]
Executing planned steps one at a time
Execution happens outside the model. The program takes the structured plan and executes each step in order, typically by mapping step names to Python functions or tools. Only one step is executed at a time, and the program remains in control between steps.
This separation makes it clear where reasoning ends and deterministic execution begins.
for item in plan:
run_step(item)
Monitoring progress through a plan
As steps are executed, the program tracks progress explicitly. This might mean recording which step is currently running, which steps have completed, and what outputs have been produced so far. That progress information can be used for logging, recovery, or to provide context if the plan needs to be revisited.
The key idea is that progress lives in program state, not inside the LLM.
Conclusion
By framing tasks as goals, asking an LLM to propose steps, and then executing those steps under program control, we gain a simple but powerful way to handle multi-step work. At this point, we are oriented to how planning fits into an LLM-guided workflow, and how responsibility is divided between model reasoning and Python execution.