> ## Documentation Index
> Fetch the complete documentation index at: https://notes.kodekloud.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Planning and Reasoning

> Explains how explicit planning improves LLM agent performance, contrasts reactive and planned agents, and details guardrails and orchestration to prevent planning failures.

Zippy is a capable assistant for quick, reactive tasks, but he can struggle on deep research or multi-step workflows. He follows the ReAct pattern (Reason then Act) without explicitly planning.

Savvy is a research specialist who also uses ReAct, but she inserts an explicit planning phase before taking actions. In this lesson we examine how planning improves agent performance and how Savvy performs it.

An agent shouldn't simply react — it should plan.

When faced with a complex request like "book me a flight to NYC next Friday under \$300," an effective agent first reasons about the required steps and produces a plan, rather than invoking tools at random. For that flight example, a concise high-level plan might be:

1. Search for flights to NYC for next Friday.
2. Filter options under \$300.
3. Check the user's calendar for conflicts.
4. Book the best matching option.

This planning happens inside the LLM's text generation: the model thinks through the task while composing its output. You can encourage explicit planning by instructing the agent to think step-by-step before acting — a practical application of chain-of-thought prompting for agents.

<Callout icon="lightbulb" color="#1CB2FE">
  A useful system-level rule is to require the agent to produce its plan before any tool calls. This makes the plan inspectable by orchestrators and helps avoid random tool usage.
</Callout>

For example, a system instruction can require visible reasoning before each action:

```text theme={null}
System instruction:
"Before taking any action, think through your plan step by step.
Explain your reasoning before each tool call."
```

Given that instruction, the agent interleaves visible reasoning and tool calls. Example output might look like:

```text theme={null}
User request:
"The user wants a flight to NYC under $300."

Agent thought:
"I'll search for flights first. If nothing is under budget, I'll check nearby dates or airports."

Action:
→ search_flights(NYC, $300)
```

When the agent runs the search and receives results, it continues the ReAct loop: think, act, observe, think again. This alternating pattern of reasoning and action is the hallmark of ReAct (Reasoning and Acting).

Let's trace the flight-booking example with a realistic sequence of thoughts, actions, and observations:

```text theme={null}
Agent action:
search_flights(NYC, Fri, $300)

Observation:
4 results: $245@6:00, $280@14:30, $295@8:45, $299@17:20

Agent thought:
"The $245 option is very early; user may prefer afternoons. I'll check user travel preferences."

Action:
get_user_preferences('travel')

Observation:
User prefers afternoon flights, window seats

Agent thought:
"There's a $280 flight at 14:30 that fits budget and time. I'll check the user's calendar for conflicts."

Action:
check_calendar('2026-03-14')

Observation:
No events after 11:00 — 14:30 is clear

Agent thought:
"Calendar is clear and preferences match. I'll book the $280 flight."

Action:
book_flight(option_id_for_$280)
```

Each thought step guides the next action; each observation supplies new information for reasoning. Planning turns a sequence of tool calls into a coherent workflow.

Common planning failure modes

* Circling: Repeating the same tool call because the agent doesn't recognize it already has the information.
* Over-planning: Spending too many tokens reasoning instead of taking actions.
* Wrong assumptions: Misinterpreting the task and pursuing the wrong plan.
* Not adapting: Sticking to the original plan even when observations suggest a new approach.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/z7NmHsFQN9LCEiD0/images/AI-Agents-for-Beginners-OpenClaw-Case-Study/Building-AI-Agents/Planning-and-Reasoning/planning-failures-circles-overplan-wrong-assumptions.jpg?fit=max&auto=format&n=z7NmHsFQN9LCEiD0&q=85&s=862a71ec1169ed0dbe4b9114c744ed7f" alt="A poster titled &#x22;PLANNING FAILURES&#x22; showing four common failure modes in boxed panels. The boxes read: &#x22;CIRCLES&#x22; (repeats same tool call), &#x22;OVER-PLAN&#x22; (too many thinking tokens), &#x22;WRONG ASSUMPTIONS&#x22; (misread the task), and &#x22;NOT ADAPTING&#x22; (ignores tool results)." width="1920" height="1080" data-path="images/AI-Agents-for-Beginners-OpenClaw-Case-Study/Building-AI-Agents/Planning-and-Reasoning/planning-failures-circles-overplan-wrong-assumptions.jpg" />
</Frame>

Good agent design anticipates and mitigates these failures. Practical guardrails include:

* Maximum iterations: Cap loop cycles to prevent infinite or endless retry loops (for example, stop after 10 iterations).
* Token budgets: Limit how many tokens the agent can spend on internal reasoning for a single task.
* Explicit instructions: In the system prompt, tell the agent how to behave when specific failures happen (e.g., if a search returns no results, broaden the query).
* Structured output: Require the agent to emit a plan in a fixed format so orchestrators and validators can inspect it before actions are taken.

A well-designed agent loop implements a perceive → reason → act cycle and enforces these guardrails to improve reliability.

Below is a quick reference table that pairs common failure modes with recommended mitigations:

| Failure mode | Symptom | Recommended mitigation |
| - | - | - |
| Circling | Repeated identical tool calls | Add state checks and idempotency detection; track tool results in memory |
| Over-planning | Excessive reasoning tokens, no progress | Enforce token budgets and a time-to-action threshold |
| Wrong assumptions | Plan diverges from user intent | Require plan confirmation or user clarification step |
| Not adapting | Ignores new observations | Allow plan revision and include observation-triggered replanning |

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/WUKBeXdogksN49S5/images/AI-Agents-for-Beginners-OpenClaw-Case-Study/Building-AI-Agents/Planning-and-Reasoning/guardrails-four-layers-neon-infographic.jpg?fit=max&auto=format&n=WUKBeXdogksN49S5&q=85&s=488a33c9f1070156d9d078c3c202d67c" alt="A neon-style infographic titled &#x22;GUARDRAILS — Four layers of protection&#x22; showing four labeled boxes: &#x22;Max Iterations,&#x22; &#x22;Token Budget,&#x22; &#x22;Explicit Instructions,&#x22; and &#x22;Structured Output.&#x22; Each box contains brief guidance like capping loop cycles, limiting reasoning tokens, telling the agent how to fail, and requiring a plan format." width="1920" height="1080" data-path="images/AI-Agents-for-Beginners-OpenClaw-Case-Study/Building-AI-Agents/Planning-and-Reasoning/guardrails-four-layers-neon-infographic.jpg" />
</Frame>

The orchestration layer enforces guardrails, manages maximum iterations, compresses context when the token window fills, and falls back to alternate models if a call fails. These mechanisms make planning less brittle and more recoverable. Typical orchestration responsibilities:

* Enforce iteration caps and token budgets.
* Compress or summarize long context to fit model windows.
* Detect tool failures and retry with fallback strategies.
* Validate structured plans before executing sensitive actions.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/z7NmHsFQN9LCEiD0/images/AI-Agents-for-Beginners-OpenClaw-Case-Study/Building-AI-Agents/Planning-and-Reasoning/openclaw-planning-perceive-reason-act.jpg?fit=max&auto=format&n=z7NmHsFQN9LCEiD0&q=85&s=5d0c9150291dfeffe7e3cfdf8c73e281" alt="A retro neon infographic titled &#x22;OPENCLAW PLANNING&#x22; showing a three-step loop: Perceive → Reason → Act. Below it are three supporting boxes labeled Max Iterations, Context Compression, and Model Fallback." width="1920" height="1080" data-path="images/AI-Agents-for-Beginners-OpenClaw-Case-Study/Building-AI-Agents/Planning-and-Reasoning/openclaw-planning-perceive-reason-act.jpg" />
</Frame>

Key takeaways

* Agents plan; they do not merely react.
* Planning occurs inside the LLM's internal reasoning and is best made explicit for inspection.
* Chain-of-thought prompting encourages step-by-step reasoning before actions.
* ReAct is a practical pattern: think → act → observe → repeat.
* Typical failures (circling, over-planning, wrong assumptions, not adapting) are mitigated with guardrails: iteration caps, token budgets, explicit instructions, and structured output.

<Frame>
  <img src="https://mintcdn.com/kodekloud-c4ac6d9a/WUKBeXdogksN49S5/images/AI-Agents-for-Beginners-OpenClaw-Case-Study/Building-AI-Agents/Planning-and-Reasoning/agents-key-takeaways-plan-react-guardrails.jpg?fit=max&auto=format&n=WUKBeXdogksN49S5&q=85&s=b0daaa37ae0b0ea23f2711308bb79c31" alt="A dark presentation slide titled &#x22;KEY TAKEAWAYS&#x22; with five colored boxes summarizing points about agents: &#x22;AGENTS PLAN&#x22; (Not just react), &#x22;CHAIN‑OF‑THOUGHT&#x22; (Think before acting), &#x22;REACT&#x22; (Think → Act → Observe loop), &#x22;FAILURES&#x22; (Circles · Over‑plan · Wrong · Rigid) and &#x22;GUARDRAILS&#x22; (Iterations · Tokens · Instructions · Format)." width="1920" height="1080" data-path="images/AI-Agents-for-Beginners-OpenClaw-Case-Study/Building-AI-Agents/Planning-and-Reasoning/agents-key-takeaways-plan-react-guardrails.jpg" />
</Frame>

A robust planning system is the foundation of any reliable agent. Zippy and Savvy are complementary: Zippy handles fast reactive tasks, while Savvy handles research-heavy tasks requiring structured planning. Together they cover a wider range of user needs than either could alone.

Links and references

* [ReAct: Reason + Act pattern](https://arxiv.org/abs/2210.03629)
* [Chain-of-Thought prompting overview](https://arxiv.org/abs/2201.11903)
* [Best practices for agent orchestration and guardrails](https://example.com/agent-orchestration)

<CardGroup>
  <Card title="Watch Video" icon="video" cta="Learn more" href="https://learn.kodekloud.com/user/courses/ai-agents-for-beginner-openclaw-case-study/module/d77598d4-d1d3-4768-97da-03ead60bf984/lesson/7447c9c6-d0bc-4773-a3d0-ee7988787c5a" />
</CardGroup>


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.