Skip to content

Plan, then execute

Read · 1 of 2

Plans are graphs

For bigger goals ("write a report on our competitors"), good agents first make a plan: a list of tasks, where some depend on others. You can't summarise before you search.

That plan is a directed graph, and running it in a valid order is a topological sort: the same algorithm you'd meet in a DSA course, doing real work.

A plan with a cycle (A needs B, B needs A) can never finish. Detect it and send it back to the model instead of looping forever.

Read this lesson as text

A plan is a graph of tasks. Run each one after the tasks it depends on.

Plans are graphs

For bigger goals ("write a report on our competitors"), good agents first make a plan: a list of tasks, where some depend on others. You can't summarise before you search.

That plan is a directed graph, and running it in a valid order is a topological sort: the same algorithm you'd meet in a DSA course, doing real work.

A plan with a cycle (A needs B, B needs A) can never finish. Detect it and send it back to the model instead of looping forever.

Exercise: Run the plan

Input: n, then n lines task: dep dep … (nothing after the colon means no dependencies).

Print the tasks in an order where every task comes after its dependencies. When several are ready, take the one listed first in the input. If that's impossible, print cycle.