Sequential workflows
As agents grow beyond single decisions, they often need to do several things in order. This lesson exists to establish a simple mental model for workflows made up of ordered steps. Sequential execution is the foundation for more complex agent behavior, including planning, branching, and recovery.
When we understand how to represent and run tasks step by step, we gain a clear way to reason about progress, outcomes, and completion in classical agents.
Representing a task as a sequence of steps
A sequential task is easiest to think about as a list of steps that must happen in a fixed order. Each step represents a unit of work, such as calling a tool or transforming some data.
In Python, this sequence is often represented using a list. Each element in the list corresponds to one step in the workflow.
steps = [
"load_data",
"generate_page",
"write_output"
]
At this stage, we are not executing anything. We are only describing the structure of the task.
Executing multiple tools in a defined order
Once steps are represented explicitly, execution becomes a matter of walking through them in order. A common approach is to map step names to tool functions and then invoke them one by one.
def load_data(state):
return {"planets": ["Mars", "Jupiter"]}
def generate_page(state):
planets = state["planets"]
return {"html": "<ul>" + "".join(f"<li>{p}</li>" for p in planets) + "</ul>"}
def write_output(state):
with open("planets.html", "w") as file:
file.write(state["html"])
return {}
tools = {
"load_data": load_data,
"generate_page": generate_page,
"write_output": write_output
}
Execution now follows the defined order rather than being hard-coded into a single function.
Passing results from one step to the next
Sequential workflows rely on passing results forward. Each step produces output that becomes input for the next step.
This is often handled with a shared state object that is updated after each step runs.
state = {}
for step in steps:
result = tools[step](state)
state.update(result)
The workflow remains simple and predictable because data only moves forward through the sequence.
Tracking progress through a sequence
When a task spans multiple steps, it is useful to know where we are in the sequence. Progress can be tracked using an index or by recording the current step name.
current_step = 0
while current_step < len(steps):
step_name = steps[current_step]
result = tools[step_name](state)
state.update(result)
current_step += 1
This makes it possible to pause, resume, or inspect execution without changing the overall structure.
Completing a workflow successfully
A sequential workflow is complete when all steps have executed in order. Completion is usually defined by reaching the end of the step list without interruption.
At that point, the final state represents the outcome of the entire task. For example, a generated HTML file now exists on disk, and the workflow has achieved its goal.
Conclusion
We now have a clear picture of how to represent and execute tasks as ordered sequences of steps. By defining steps explicitly, running them in order, passing results forward, and tracking progress, we gain a solid foundation for classical agent workflows.
This orientation is enough to recognize sequential execution patterns and build upon them confidently in larger agent systems.