Bird
Raised Fist0
Agentic AIml~20 mins

Plan-and-execute pattern in Agentic AI - Practice Problems & Coding Challenges

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Challenge - 5 Problems
🎖️
Plan-and-Execute Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
2:00remaining
Understanding the Plan-and-Execute Pattern

In the plan-and-execute pattern, an AI agent first creates a plan and then executes it step-by-step. Which of the following best describes the main advantage of this pattern?

AIt allows the agent to adapt its plan dynamically after each step without a fixed sequence.
BIt guarantees the agent will always find the optimal solution without errors.
CIt requires less computation because the agent skips planning and acts randomly.
DIt separates decision-making from action, enabling clearer control and debugging of each phase.
Attempts:
2 left
💡 Hint

Think about how separating planning and execution helps in understanding and controlling the agent's behavior.

Predict Output
intermediate
2:00remaining
Output of a Simple Plan-and-Execute Agent

Consider this simplified Python code of a plan-and-execute agent. What will be printed when running it?

Agentic AI
class Agent:
    def plan(self):
        return ['step1', 'step2', 'step3']

    def execute(self, plan):
        for step in plan:
            print(f'Executing {step}')

agent = Agent()
plan = agent.plan()
agent.execute(plan)
AExecuting step3\nExecuting step2\nExecuting step1
BExecuting step1\nExecuting step2\nExecuting step3
CNo output because execute method is not called
Dstep1\nstep2\nstep3
Attempts:
2 left
💡 Hint

Look at the execute method and how it prints each step.

Model Choice
advanced
2:00remaining
Choosing a Model for Plan Generation

You want to build an agent that uses the plan-and-execute pattern. Which model type is best suited for generating a detailed multi-step plan before execution?

AA sequence-to-sequence model that generates a list of steps as output.
BA simple linear regression model predicting a single output value.
CA clustering model that groups similar data points without outputting sequences.
DA k-nearest neighbors model that classifies inputs based on neighbors.
Attempts:
2 left
💡 Hint

Think about which model can produce ordered sequences as output.

Hyperparameter
advanced
2:00remaining
Hyperparameter Impact on Plan Quality

In a plan-and-execute agent using a neural network for planning, increasing which hyperparameter is most likely to improve the detail and length of generated plans?

AIncreasing the maximum output sequence length during training and inference.
BReducing the learning rate drastically to near zero.
CDecreasing the batch size to 1 for faster updates.
DUsing fewer hidden layers to simplify the model.
Attempts:
2 left
💡 Hint

Consider what controls how long the generated plans can be.

🔧 Debug
expert
2:00remaining
Debugging a Plan-and-Execute Agent Failure

An agent using the plan-and-execute pattern sometimes fails because the execution phase tries to run steps not in the plan. Which code mistake below causes this issue?

class Agent:
    def plan(self):
        return ['step1', 'step2']

    def execute(self, plan):
        for step in ['step1', 'step2', 'step3']:
            print(f'Executing {step}')

agent = Agent()
plan = agent.plan()
agent.execute(plan)
AThe execute method correctly uses the plan argument, so no error occurs.
BThe plan method returns an incomplete list missing 'step3'.
CThe execute method ignores the plan argument and uses a fixed list with an extra step.
DThe agent never calls the execute method, so no steps run.
Attempts:
2 left
💡 Hint

Look at what the execute method loops over compared to the plan.

Practice

(1/5)
1. What is the main idea behind the plan-and-execute pattern in agentic AI?
easy
A. Execute the whole task at once without planning
B. Randomly try different actions until one works
C. Break a big task into smaller steps and do them one by one
D. Only plan without doing any steps

Solution

  1. Step 1: Understand the pattern purpose

    The plan-and-execute pattern is designed to handle big tasks by dividing them into smaller, manageable steps.
  2. Step 2: Match the description to options

    Break a big task into smaller steps and do them one by one clearly states breaking a big task into smaller steps and doing them one by one, which matches the pattern.
  3. Final Answer:

    Break a big task into smaller steps and do them one by one -> Option C
  4. Quick Check:

    Plan-and-execute = break big task into steps [OK]
Hint: Think: big task needs small steps first [OK]
Common Mistakes:
  • Confusing planning with skipping execution
  • Thinking AI acts randomly without plan
  • Believing the task is done all at once
2. Which of these code snippets correctly shows the start of a plan-and-execute loop in Python?
easy
A. execute(plan) for step in plan:
B. while plan: execute(plan)
C. if plan: execute(plan)
D. for step in plan: execute(step)

Solution

  1. Step 1: Identify correct loop structure for steps

    The plan is a list of steps, so we loop over each step with for step in plan:.
  2. Step 2: Check execution inside loop

    Inside the loop, each step is executed with execute(step), matching the pattern.
  3. Final Answer:

    for step in plan: execute(step) -> Option D
  4. Quick Check:

    Loop over steps then execute each [OK]
Hint: Loop over plan steps, then execute each [OK]
Common Mistakes:
  • Using while without updating plan
  • Executing whole plan at once
  • Incorrect loop syntax or order
3. Given this code snippet using plan-and-execute pattern:
plan = ['step1', 'step2', 'step3']
results = []
for step in plan:
    results.append(f"done {step}")
print(results)

What is the output?
medium
A. ['step1', 'step2', 'step3']
B. ['done step1', 'done step2', 'done step3']
C. ['done step3']
D. Error: append not defined

Solution

  1. Step 1: Understand the loop and append

    The loop goes through each step in plan and appends the string 'done ' plus the step name to results.
  2. Step 2: Trace the results list after loop

    After all steps, results contains ['done step1', 'done step2', 'done step3'].
  3. Final Answer:

    ['done step1', 'done step2', 'done step3'] -> Option B
  4. Quick Check:

    Each step marked done in list [OK]
Hint: Append 'done' + step for each plan item [OK]
Common Mistakes:
  • Confusing original steps with done steps
  • Thinking only last step is appended
  • Assuming append causes error
4. This code tries to implement plan-and-execute but has a bug:
plan = ['step1', 'step2']
for step in plan:
    execute(step)
    plan.remove(step)

What is the main problem?
medium
A. Modifying the plan list while looping causes skipping steps
B. The execute function is not defined
C. The loop should be a while loop
D. There is no problem; code works fine

Solution

  1. Step 1: Analyze loop and list modification

    The code removes items from the plan list while looping over it, which changes the list size and order during iteration.
  2. Step 2: Understand effect on iteration

    Removing items causes the loop to skip some steps because the list indices shift unexpectedly.
  3. Final Answer:

    Modifying the plan list while looping causes skipping steps -> Option A
  4. Quick Check:

    Changing list during loop skips items [OK]
Hint: Never change list while looping over it [OK]
Common Mistakes:
  • Thinking execute is missing
  • Believing while loop fixes skipping
  • Ignoring list modification effects
5. You want an AI to plan and execute cleaning a house room by room. Which approach best uses the plan-and-execute pattern safely and clearly?
hard
A. Create a list of rooms, plan = ['kitchen', 'bathroom', 'bedroom'], then loop: for room in plan: clean(room)
B. Start cleaning randomly without a plan, hoping all rooms get cleaned
C. Plan all rooms but clean only the first one repeatedly
D. Clean the whole house at once without breaking into rooms

Solution

  1. Step 1: Identify safe planning method

    Breaking the big task (clean house) into smaller steps (clean each room) is safe and clear.
  2. Step 2: Match approach to plan-and-execute pattern

    Create a list of rooms, plan = ['kitchen', 'bathroom', 'bedroom'], then loop: for room in plan: clean(room) creates a plan list of rooms and executes cleaning each room in order, matching the pattern well.
  3. Final Answer:

    Create a list of rooms, plan = ['kitchen', 'bathroom', 'bedroom'], then loop: for room in plan: clean(room) -> Option A
  4. Quick Check:

    Plan rooms, then clean each step [OK]
Hint: Plan rooms first, then clean one by one [OK]
Common Mistakes:
  • Skipping planning and acting randomly
  • Repeating same step only
  • Trying to do all at once without steps