5.2 Creating and Executing LLM Plans
8/5/2026, 5:11:49 PM
Creating and Executing LLM Plans: when to use it, why it works, where it sits in an agentic system, and how to implement, evaluate, and harden it in production.
5.2 Creating and Executing LLM Plans
Learning objectives
After this section, you should be able to:
- Explain what creating and executing llm plans contributes to an agentic system.
- Decide when to use it and when a simpler design is sufficient.
- Implement the pattern as observable, testable components.
- Identify its principal cost, safety, and reliability risks.
When to use it
Use explicit plans when operators or the system need visibility into dependencies and intended actions.
Why it works
Separating plan creation from execution enables review, modification, and safer orchestration.
How it fits the system
The arrows show control and data movement, not necessarily separate models. A deterministic function, one model called multiple times, or several models may implement the boxes. Preserve trace identifiers across the flow.
Step-by-step implementation
- Represent steps with ids, dependencies, tools, and success criteria. Write the input, expected output, owner, and failure condition before implementation.
- Validate feasibility and permissions. Keep the decision observable in logs or structured state so it can be evaluated.
- Topologically order dependent work. Apply least privilege and validate assumptions at this boundary.
- Execute ready steps. Capture the result and enough metadata to reproduce or diagnose it.
- Store results in structured state. Compare the result with explicit acceptance criteria before continuing.
- Revise the plan when a step fails. Route failures to retry, fallback, or human review according to policy.
- Verify the final goal. Add the observed behavior to the regression suite and operating notes.
Technical implementation notes
- State: Keep messages, tool calls, observations, artifacts, decision reasons, attempt count, token use, latency, and final status in a structured run record.
- Contracts: Define each component with typed inputs, typed outputs, allowed side effects, timeouts, and error categories.
- Controls: Use least-privilege credentials, allowlisted tools, bounded loops, input validation, output validation, and approval gates for consequential actions.
- Observability: Record prompts or prompt versions, model and parameters, tool arguments, tool results, exceptions, timestamps, and cost—subject to privacy rules.
- Evaluation: Test representative, edge, adversarial, and failure-recovery cases. Compare against the simplest viable baseline.
Worked example
A plan specifies schema lookup before SQL generation and query validation before execution.
INPUT: user goal + constraints
STATE: {run_id, step, observations, budget, status}
DECIDE: next bounded action
VALIDATE: permissions, arguments, and policy
EXECUTE: model call, deterministic code, or tool
OBSERVE: structured result or categorized error
STOP: acceptance criteria pass, budget reached, or human escalation
Failure modes and mitigations
| Failure mode | Signal | Mitigation |
|---|---|---|
| Vague objective | Output appears fluent but misses the task | Convert the request into measurable acceptance criteria |
| Unbounded loop | Repeated calls without material progress | Set iteration, token, time, and cost limits |
| Bad intermediate state | Later steps amplify an early mistake | Validate each component contract and retain traces |
| Unsafe side effect | Tool attempts an unauthorized change | Apply authorization, least privilege, dry-run, and approval gates |
| Evaluation blind spot | Demo succeeds but real cases fail | Expand the test set using production-like and adversarial cases |
Verification checklist
- The use case justifies this pattern over a simpler one-shot call.
- Inputs, outputs, and success criteria are explicit.
- Tool calls and side effects are validated and permissioned.
- Loops have hard budgets and meaningful stop conditions.
- Failures produce safe retries, fallbacks, or escalation.
- Quality, latency, and cost are measured together.
- Regression tests include at least one failure case.
Review questions
- What observable failure would show that this pattern is misapplied?
- Which part should be deterministic rather than delegated to an LLM?
- What is the minimum context required at each step?
- Where should a human approval or escalation gate sit?
- Which metric would prove that the added complexity is worthwhile?
Practical exercise
Implement a minimal version for one narrow task. Save three traces: a successful run, a recoverable failure, and a case that must stop or escalate. Write one regression test for each trace and compare the result with a direct-generation baseline.
Learning map
Page 33 of 40 in DeepLearningAI > Agentic AI. Read after "5.1 Planning Workflows". Continue to "5.3 Planning with Code Execution" next. All 37 numbered lesson pages (1.1-5.7) share one template — state, contracts, controls, observability, and evaluation, introduced in full in 1.1 Course Overview — so this page assumes that shape and focuses on what's unique to its own topic.
Get hands-on — step by step
Complete the Practical exercise at the end of this page: implement a minimal version of creating and executing llm plans, save a successful trace, a recoverable-failure trace, and an escalation trace, then write one regression test per trace and compare against a direct-generation baseline.
Top 3 sources
- 1Anthropic Engineering Blog
Practical write-ups on building, evaluating, and operating agentic systems.
https://www.anthropic.com/engineering
- 2DeepLearning.AI Course Catalog
The broader DeepLearning.AI curriculum this study guide's structure is organized around.
https://www.deeplearning.ai/courses/
Links are AI-suggested — worth a quick sanity check before diving in.