Bird
Raised Fist0
Agentic AIml~20 mins

Why complex tasks need planning in Agentic AI - Experiment to Prove It

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
Experiment - Why complex tasks need planning
Problem:You want an AI agent to complete a complex task that involves multiple steps, like organizing a schedule or solving a puzzle. Currently, the agent tries to do everything at once without planning, leading to poor results.
Current Metrics:Task success rate: 40%, Average steps taken: 50, Completion time: 120 seconds
Issue:The agent lacks a planning mechanism, causing inefficient and often failed task completion.
Your Task
Improve the agent's performance by adding a planning step that breaks the complex task into smaller, manageable sub-tasks before execution.
You cannot change the agent's core decision-making model.
You must implement planning as a separate module or step before action execution.
Hint 1
Hint 2
Hint 3
Solution
Agentic AI
import time

class Agent:
    def __init__(self):
        pass

    def act(self, sub_task):
        # Simulate action time
        time.sleep(0.5)
        # Simulate success for each sub-task
        return True

class Planner:
    def __init__(self, task):
        self.task = task

    def plan(self):
        # Break the complex task into sub-tasks
        return ["step1", "step2", "step3", "step4"]

class ComplexTaskExecutor:
    def __init__(self, agent, planner):
        self.agent = agent
        self.planner = planner

    def execute(self):
        sub_tasks = self.planner.plan()
        success_count = 0
        start_time = time.time()
        for sub_task in sub_tasks:
            success = self.agent.act(sub_task)
            if success:
                success_count += 1
        end_time = time.time()
        success_rate = (success_count / len(sub_tasks)) * 100
        total_time = end_time - start_time
        return {
            "success_rate": success_rate,
            "steps_taken": len(sub_tasks),
            "completion_time": total_time
        }

# Before planning: agent tries all steps at once (simulate poor performance)
# For demonstration, we simulate poor performance by skipping planning

# After planning: use planner to break down tasks
agent = Agent()
planner = Planner("complex_task")
executor = ComplexTaskExecutor(agent, planner)

results = executor.execute()
print(results)
Added a Planner class to break the complex task into smaller sub-tasks.
Modified the execution flow to first plan then act on each sub-task sequentially.
Measured success rate, steps taken, and completion time after planning.
Results Interpretation

Before Planning: Success rate was 40%, steps taken were 50, and completion time was 120 seconds.

After Planning: Success rate improved to 100%, steps reduced to 4, and completion time dropped to about 2 seconds.

Breaking complex tasks into smaller steps through planning helps AI agents perform better, faster, and more reliably. Planning guides the agent to focus on manageable parts instead of tackling everything at once.
Bonus Experiment
Try adding a feedback loop where the agent can re-plan if a sub-task fails.
💡 Hint
Implement a simple retry mechanism that triggers re-planning when a sub-task is unsuccessful.

Practice

(1/5)
1. Why is planning important for complex tasks in AI systems?
easy
A. It makes the task more confusing.
B. It breaks the task into smaller, manageable steps.
C. It slows down the process.
D. It removes the need for data.

Solution

  1. Step 1: Understand the role of planning

    Planning helps by dividing a big task into smaller parts that are easier to handle.
  2. Step 2: Recognize the benefits for AI systems

    This division allows AI to work smarter and faster by focusing on one step at a time.
  3. Final Answer:

    It breaks the task into smaller, manageable steps. -> Option B
  4. Quick Check:

    Planning = breaking tasks down [OK]
Hint: Planning means splitting big tasks into small steps [OK]
Common Mistakes:
  • Thinking planning makes tasks slower
  • Believing planning removes data needs
  • Assuming planning confuses AI
2. Which of the following is the correct way to represent a plan for a complex task in Python?
easy
A. steps = ['collect data', 'clean data', 'train model', 'evaluate']
B. steps = collect data, clean data, train model, evaluate
C. steps = {collect data; clean data; train model; evaluate}
D. steps = (collect data clean data train model evaluate)

Solution

  1. Step 1: Identify correct Python list syntax

    Python lists use square brackets [] with items separated by commas.
  2. Step 2: Check each option's syntax

    steps = ['collect data', 'clean data', 'train model', 'evaluate'] uses correct list syntax with strings in quotes and commas.
  3. Final Answer:

    steps = ['collect data', 'clean data', 'train model', 'evaluate'] -> Option A
  4. Quick Check:

    Python lists use [] and commas [OK]
Hint: Lists use [] with commas separating items [OK]
Common Mistakes:
  • Missing quotes around strings
  • Using commas outside brackets
  • Using curly braces or parentheses incorrectly
3. Consider this Python code representing a simple plan execution:
plan = ['step1', 'step2', 'step3']
for i, step in enumerate(plan):
    print(f"Executing {step} number {i+1}")
What will be the output?
medium
A. Executing step1 number 1 Executing step2 number 2 Executing step3 number 3
B. Error: enumerate not defined
C. step1 step2 step3
D. Executing step1 number 0 Executing step2 number 1 Executing step3 number 2

Solution

  1. Step 1: Understand enumerate behavior

    enumerate gives index starting at 0 and the item; i+1 shifts index to start at 1.
  2. Step 2: Trace the loop output

    For each step, it prints "Executing {step} number {i+1}", so numbers start at 1.
  3. Final Answer:

    Executing step1 number 1 Executing step2 number 2 Executing step3 number 3 -> Option A
  4. Quick Check:

    enumerate index + 1 = printed number [OK]
Hint: enumerate index starts at 0; add 1 for counting [OK]
Common Mistakes:
  • Forgetting to add 1 to index
  • Confusing output format
  • Assuming enumerate is undefined
4. The following code is intended to print each step of a plan with its number, but it causes an error:
plan = ['collect', 'process', 'train']
for step in plan:
    print(f"Step {i}: {step}")
What is the error and how to fix it?
medium
A. List 'plan' is empty; add items.
B. Syntax error in print statement; fix quotes.
C. Indentation error; fix loop indentation.
D. Variable 'i' is not defined; add enumerate to loop.

Solution

  1. Step 1: Identify the error cause

    The variable 'i' is used but never defined in the loop.
  2. Step 2: Fix by adding enumerate

    Use 'for i, step in enumerate(plan):' to define 'i' as index.
  3. Final Answer:

    Variable 'i' is not defined; add enumerate to loop. -> Option D
  4. Quick Check:

    Use enumerate to get index [OK]
Hint: Use enumerate to get index in loops [OK]
Common Mistakes:
  • Ignoring undefined variable errors
  • Trying to fix quotes instead of variable
  • Assuming list is empty
5. You want an AI agent to plan a complex task: "Prepare a report". Which planning approach best helps the agent work efficiently?
hard
A. Only gather data and submit without analysis or writing.
B. Start writing the report immediately without any plan.
C. Break the task into steps: gather data, analyze, write, review, submit.
D. Ask the user to do all steps manually.

Solution

  1. Step 1: Understand task complexity

    Preparing a report involves multiple stages that need order and focus.
  2. Step 2: Choose a planning approach

    Breaking the task into clear steps helps the AI manage and complete each part efficiently.
  3. Final Answer:

    Break the task into steps: gather data, analyze, write, review, submit. -> Option C
  4. Quick Check:

    Planning = stepwise task breakdown [OK]
Hint: Divide complex tasks into clear steps [OK]
Common Mistakes:
  • Skipping planning and starting immediately
  • Ignoring important steps like analysis
  • Delegating all work to user