Goal Stack Planning
What you'll learn: How AI agents use a stack data structure to manage subgoals, pushing new goals on top and popping them as they're completed.
The Core Idea
Goal Stack Planning organizes an agent's objectives like a stack of plates. The agent starts with a high-level goal at the bottom, then breaks it into subgoals that get stacked on top. The agent always works on the topmost goal first—once achieved, it pops that goal off the stack and moves to the next one below.
This approach naturally handles nested dependencies: if completing Goal A requires achieving Goal B first, you push B onto the stack. B gets solved before returning to A.
How It Works
Imagine an agent needs to "write a research report":
- Push main goal: "Write research report"
- Agent realizes it needs sources first
- Push subgoal: "Find 3 academic sources"
- Agent works on top goal, finds sources
- Pop "Find sources" (achieved)
- Push new subgoal: "Summarize findings"
- Complete and pop "Summarize findings"
- Now tackle original goal with prerequisites met
- Pop "Write research report" (done!)
The stack ensures proper ordering—you never attempt a goal until all prerequisites above it are cleared.
Why It Matters
Goal Stack Planning provides structure to complex multi-step tasks. Unlike reactive agents that choose actions ad-hoc, the stack maintains an explicit queue of what needs doing and in what order. When an agent gets stuck, you can inspect the stack to see exactly which subgoal failed.
It works best when tasks have clear hierarchical structure and dependencies.
Key Takeaway: Goal Stack Planning uses a last-in-first-out stack to manage agent subgoals, ensuring prerequisites are completed before parent goals by always working on the topmost item.