Day 4 — Adding Reasoning: Make Your Agent Think in Steps

Welcome to Day 4 of the Task Helper Agent (Gemini Edition) series!
So far, you’ve built a simple but functional planning agent that turns a user goal into a clean task list.

Today marks a major milestone:
You’ll upgrade your agent from a one-shot planner to a two-step reasoning agent.

This is where your project truly becomes agentic.


Goal for the Reader

By the end of Day 4, you will:

  • Move from a one-step “generate a plan” approach
  • To a two-step agent that:
    1. Breaks the goal into high-level phases
    2. Expands each phase into detailed steps

This mirrors how human planners think — and significantly improves output quality.


1. Why Reasoning Helps

Reasoning turns your assistant into a true agent:

Better plans

Instead of shallow steps, you get thoughtful structure.

Clearer task breakdowns

High-level → expanded → actionable.

More “agent-like” behaviour

Your AI now thinks through the problem instead of guessing a final answer in one shot.

This is the essence of agentic AI.


2. Designing a Two-Call Workflow

Instead of asking Gemini:

“Give me the entire task plan in one go.”

…you first guide it through a thinking sequence:


Call 1 — “List high-level phases.”

Example for starting a fitness routine:

  • Assess current fitness level
  • Learn proper techniques
  • Build a weekly schedule
  • Start training gradually

Call 2 — “Expand each phase into detailed steps.”

Example expansion:

  • Phase 1: Assess current fitness
    • Do a beginner self-evaluation
    • Identify constraints
    • Set an achievable timeline

This simple change dramatically improves clarity, structure, and actionability.


3. Implementing the Two-Step Agent (Full Day 4 Version)

Below is the complete Day 4 code update, ready to paste into src/agent.py.


src/agent.py (Day 4 — Full Updated Version)

from textwrap import dedent
from typing import List

from llm_client import generate_text


class TaskHelperAgent:
    """
    V2: Reasoning + planning agent.
    """

    def __init__(self):
        pass

    # --- V1 method still works ---
    def plan_task(self, user_goal: str) -> str:
        prompt = dedent(f"""
        You are an AI task planning assistant.

        The user will give you a goal. Your job:
        1. Clarify the goal briefly in one sentence.
        2. Break it into 5–10 clear, numbered steps.
        3. Keep the language simple and actionable.

        User goal:
        "{user_goal}"

        Respond using:

        Goal:
        - <one sentence>

        Plan:
        1. ...
        2. ...
        3. ...
        """).strip()

        return generate_text(prompt)

    # === New V2 methods below ===

    def _draft_phases(self, user_goal: str) -> List[str]:
        """
        Ask Gemini to break the goal into 3–6 high-level phases.
        Returns a list of phase titles.
        """
        prompt = dedent(f"""
        You are helping plan a multi-step goal.

        Goal:
        "{user_goal}"

        1. Identify 3–6 high-level phases that someone should go through.
        2. Each phase should be short (max 8 words).
        3. Return ONLY a numbered list of phase titles, no extra text.
        """).strip()

        raw = generate_text(prompt)

        # Simple parsing: split by lines that start with digits
        phases = []
        for line in raw.splitlines():
            line = line.strip()
            if not line:
                continue
            if line[0].isdigit():
                parts = line.split(".", 1)

                if len(parts) == 2:
                    phases.append(parts[1].strip())
                else:
                    phases.append(line)

        return phases

    def _expand_phases(self, user_goal: str, phases: List[str]) -> str:
        """
        Ask Gemini to expand each phase into detailed steps.
        """
        phases_bullets = "\n".join(f"- {p}" for p in phases)

        prompt = dedent(f"""
        You are an AI task planning assistant.

        The user has this goal:
        "{user_goal}"

        We've already decided on these phases:
        {phases_bullets}

        For EACH phase:
        1. Briefly describe the phase (1–2 sentences).
        2. Provide 3–5 bullet steps under it.

        Format exactly like this:

        Goal:
        - <one sentence>

        Plan:
        Phase 1: <title>
        - ...
        - ...

        Phase 2: <title>
        - ...
        """).strip()

        return generate_text(prompt)

    def plan_task_reasoned(self, user_goal: str) -> str:
        """
        Full reasoning-based planning:
        1) Draft phases
        2) Expand them into a detailed plan
        """
        phases = self._draft_phases(user_goal)
        return self._expand_phases(user_goal, phases)

4. Update main.py to Use the New Method

To test the new reasoning agent, temporarily modify your main file:

from agent import TaskHelperAgent


def main():
    agent = TaskHelperAgent()
    goal = "Get into a consistent 3-day-per-week workout routine in 1 month"
    plan = agent.plan_task_reasoned(goal)
    print("=== AI Task Helper Agent (Reasoned) ===")
    print(plan)


if __name__ == "__main__":
    main()

Run it:

python src/main.py

5. Explaination

What you’ve built today is no longer a simple prompt → answer script.

You now have:

A multi-step, reasoning-capable agent

Gemini now:

  1. Thinks about the structure
  2. Produces intermediate plans
  3. Builds a detailed final output

True Agentic Behavior

Your AI is now performing deliberate reasoning, not one-shot guessing.

A solid foundation for Day 5

Tomorrow, you’ll create a CLI interface so users can run commands like:

python -m src.main "Plan my workout routine"

This makes your agent feel like a real tool — not just a script.

Recommended Reading

Beginner’s Guide to AI Agents: Smarter, Faster, More Useful

A great follow-up for readers who want to better understand how agentic systems work.
https://tooltechsavvy.com/beginners-guide-to-ai-agents-smarter-faster-more-useful/


How to Adopt the Agentic AI Mindset in 2025

Helps readers shift their thinking from prompts → processes → agents.
https://tooltechsavvy.com/how-to-adopt-the-agentic-ai-mindset-in-2025/


Prompt Chaining Made Easy: Learn with Real-World Examples

Directly connected to what Day 4 teaches — multi-step prompting and reasoning.
https://tooltechsavvy.com/prompt-chaining-made-easy-learn-with-real-world-examples/

Leave a Comment

Your email address will not be published. Required fields are marked *