01. Why Agents Plan
In building agents, there are two styles. One reacts to each situation without a plan. The other creates a plan first. The plan gives a view of what to do over time. This design combines memory with planning and reflection. The plan tries to balance what works now versus what works later. But planning has limits. The source shows that long term planning and task decomposition remain challenging. When unexpected errors happen, large language models, or LLMs, struggle to adjust their plans. So planning can reduce the chance of going down a wrong path. It bounds the work by setting a course. You can inspect the intent behind an agent's actions. However, planning costs flexibility. A reactive approach adapts more easily to sudden changes. Yet it may lack a big picture view. The choice between them is a trade off. One offers a clear structure and foresight. The other offers quick adjustment. Neither is perfect. The best choice depends on the task at hand.
Prompt template for generative agent daily planning balancing immediate and long-term believability.
planning_prompt = (
"{Intro of an agent X}. Here is X's plan today in broad strokes: "
"1) Relationships between agents and observations of one agent by another "
"are all taken into consideration for planning and reacting. "
"Environment information is present in a tree structure."
)
Imagine planning a road trip: one way is to just drive and ask for directions at every turn, while the other is to study a map and write down the route before leaving. This chapter explains the second style—building an AI agent that creates a plan first. It is meant to help the agent avoid wandering down wrong paths by giving it a clear sequence of steps to follow.
The plan-first agent works in two phases. First, a “planner” generates a list of subgoals, like “search for flights, then book hotel.” Then, separate “executors” carry out each step one at a time—for instance, calling a search tool or a booking API. After each step, the agent checks the result and, if needed, re-plans the remaining steps. This design appears in the Plan-and-Execute architecture from the source, where the planner uses a large language model (LLM) and the executors can use smaller, faster models. Another example is ReWOO, which lets the agent reason about the whole task before making any observations, cutting down on repeated LLM calls.
The trickiest point is that even a careful plan can break when something unexpected happens, because LLMs struggle to adjust their plans on the fly. To guard against this, KnowAgent introduces an “action knowledge base” and a “knowledgeable self-learning strategy” that constrain which actions the agent can take next, preventing it from hallucinating a wrong move. If the planner makes a mistake, the agent might execute a step that leads nowhere—like driving to a closed hotel. Without planning, the agent would react to each new piece of information without a map, often getting stuck in dead ends or ignoring long‑term goals entirely.
In the Plan-and-Execute agent architecture, the ordered mechanism begins with a planner component that uses an LLM to generate a multi-step plan covering the entire task. This plan is then handed to one or more executor components, each responsible for taking a single step from the plan and invoking the appropriate tool (such as a database query or API call). After all steps are completed, the system invokes a re-planning prompt, which lets the agent decide whether to finish with a response or generate a follow-up plan if the first plan did not have the desired effect. On failure—for instance, if an executor’s tool call returns an error—the re-planning loop is re-entered, potentially producing a new plan that accounts for the failure.
The invariant the design preserves is that cost savings and better overall performance are maintained by not calling the large planner LLM on every single tool invocation. Instead, the planner’s LLM is invoked only at planning and re-planning points, while the executors may use lighter-weight LLMs or no LLM at all. This directly addresses the downside of traditional ReAct agents (thought-act-observation loops), which require an LLM call for each action and only plan one sub-problem at a time. The planning guarantees that the agent’s reasoning is forced to cover the whole task, reducing sub‑optimal trajectories.
The key trade‑off is choosing the planning architecture over the obvious alternative: a pure ReAct-style agent that interleaves thought, act, and observation at every step. ReAct is simpler to implement but suffers from high latency and cost because each tool invocation demands a fresh LLM call, and the model never “sees” the entire task at once. Plan-and-Execute rejects that per‑step LLM call pattern, accepting instead the risk that the initial plan may be flawed or that a tool failure may not be fully corrected during re‑planning. The cost it avoids is the multiplicative expense of many LLM calls per task and the compounding of local decisions that ignore the global objective.
A concrete failure mode occurs when an executor’s tool call returns an unexpected result—for example, a database query that was assumed to return data returns an empty set. The executor completes the step with that incorrect output, and the re‑planning prompt may not detect the discrepancy because it relies on the same original plan context. An operator would see the agent enter a loop: the re‑planning prompt repeatedly generates similar follow-up plans that do not alter the flawed step, or the agent produces a final response that logically contradicts the missing data. The signal is a log of multiple identical re‑planning cycles followed by an obviously wrong answer, with no intermediate check that the executor’s output matched the plan’s expectation.
Failure 1: Planning Hallucination
- Trigger — The agent lacks built-in action knowledge, leading it to generate an invalid or unrealistic plan.
- Guard — The
action knowledge baseandknowledgeable self-learning strategyfrom KnowAgent constrain the action path during planning, mitigating hallucination. - Posture — Fail-soft: the guard filters or corrects the plan, allowing the agent to continue with a valid trajectory rather than aborting.
- Operator signal — The agent invokes the
action knowledge baseand applies theknowledgeable self-learning strategy; no explicit error log is emitted, but the operator sees a constrained plan instead of a hallucinated one. - Recovery — The guard prevents the hallucinated plan from being executed; no retry is needed because the constraint operates during plan generation.
Failure 2: Inability to Adjust Plan on Unexpected Errors
- Trigger — An unexpected error occurs during execution, and the LLM struggles to adjust its plan (as stated in the chapter).
- Guard — No guard is identified in the source: the chapter only notes this as a limitation, with no exception handling, retry, fallback, or validation component presented.
- Posture — Fail-hard: the agent cannot adapt, so the run aborts or produces an incorrect result.
- Operator signal — Silent absence of any correction or re‑planning; the agent may output a confusing response or remain stuck.
- Recovery — Manual intervention required: the operator must restart the task or provide an explicit corrective prompt.
Failure 3: Long-Term Planning Breakdown
- Trigger — The task is complex and requires planning over many steps; long‑term planning and task decomposition remain challenging.
- Guard — The
re‑planning promptfrom the Plan‑and‑Execute architecture: after execution of one step, the agent is called again with a re‑planning prompt to decide whether to finish or generate a follow‑up plan. - Posture — Fail-soft: the agent attempts to re‑plan rather than aborting, degrading performance but continuing.
- Operator signal — The
re‑planning promptis invoked; the operator sees that the agent is generating a new plan mid‑execution. - Recovery — The agent generates a follow‑up plan based on the re‑planning prompt; no fixed retry count is specified, but the loop repeats until success or manual stop.
Failure 4: Agent Stuck in Loop
- Trigger — The trajectory contains a sequence of consecutive identical actions that lead to the same observation (hallucination in the trajectory).
- Guard — The
heuristic functionfrom the self‑reflection mechanism: it determines when the trajectory is inefficient or contains hallucination and should be stopped. - Posture — Fail-hard: the heuristic function stops the current trajectory to prevent endless looping.
- Operator signal — The
heuristic functiontriggers; the operator sees that the trajectory is terminated andself‑reflectionis about to begin. - Recovery —
Self-reflectionis performed using two‑shot examples (failed trajectory, ideal reflection), and up to three reflections are added to the agent’s working memory as context for future queries.
Failure 5: Task Decomposition Failure
- Trigger — The planner fails to decompose the task into valid, achievable sub‑tasks due to task complexity (the source notes that task decomposition remains challenging).
- Guard — No guard is explicitly provided in the source: the planner is mentioned as part of Plan‑and‑Execute, but no fallback or validation for decomposition failure is described.
- Posture — Fail-hard: without a valid decomposition, the agent cannot proceed and the run effectively halts.
- Operator signal — The agent either outputs an incomplete or incorrect multi‑step plan, or fails to generate any plan; the operator observes a missing or broken execution sequence.
- Recovery — Manual step required: the operator must replan the decomposition manually or restart with a simpler prompt.