Google ADKgoogle-adk 2.8 · Python 3.10+
1
Curious builder0 XP earned · 300 to level 2
0 daysFinish a lesson to begin
Badge collection0 of 6 unlocked
28 small wins to finish your pathNext lesson

Steps in a fixed order

Sometimes you do not want the model choosing the order. A SequentialAgent runs its sub agents one after another, every time.

This is the first of three workflow agents, and none of them use a model themselves. They decide who runs and when. The thinking still happens in the agents underneath.

Two steps

python
draft = LlmAgent(
    name="draft",
    model=PretendModel(replies=[say("dear customer, sorry")]),
    instruction="Write a first reply to the customer.",
    output_key="draft",
)

output_key from lesson 13 saves this agent's final reply into state under the name draft.

python
polish = LlmAgent(
    name="polish",
    model=PretendModel(replies=[say("Dear customer, we are sorry.")]),
    instruction="Improve this reply, fixing tone and capitals: {draft}",
    output_key="final",
)

And the template from lesson 12 reads it back out. That is how one step passes work to the next: through state, with no message passing to write.

python
writer = SequentialAgent(name="writer", sub_agents=[draft, polish])
Example
session = await run(writer, "The order was late")
print("state:", dict(session.state))

They ran in the order you listed them, and both results are in state. Nothing chose that order at runtime, which is the point of a sequence.

Running this prints a deprecation warning: as of ADK 2.x the three template workflow agents are deprecated in favour of a newer Workflow API. They still work, they are still what most existing code uses, and there is one thing only they can do. Lesson 20 covers the newer way and when each is right.

How a sequence passes work along
draft runs. Its final reply is saved under the key draft.Step 1 of 4
  • The order is not a judgement call. Clean, then summarise, then format.
  • Each step has one job, so each can have a short instruction and its own tools.
  • You can test one step without running the others.
Tools and a schema, separately
A sequence is also the standard way round the limitation from lesson 13: one agent does the work with tools, the next turns the result into a fixed shape.
Try it yourself
  • Add a third agent that shortens the reply, with its own key.
  • Remove output_key from draft and watch the second agent fail on the template.

You understood something today that you didn't yesterday.