ASAmol Shukla
Projects
Courses
Prompts
Skills
Contact
Resume
Course Outline
Syllabus Overview

AI Tools: LLM & Prompt Engineering Mastery

Courses/AI Tools: LLM & Prompt Engineering Mastery/Lesson 10: What Is an Agentic Loop?
50 mins lesson duration•10 mins read

Lesson 10: What Is an Agentic Loop?

One prompt = one answer. An agentic loop = the model plans, acts, observes, and repeats until the job is done.

From Chatbot to Agent

A plain LLM call is a single shot: prompt in, answer out. An agent wraps the LLM in a loop that lets it take actions and use the results:

        ┌─────────────┐
        │   THINK     │  decide what to do next
        └──────┬──────┘
               ▼
        ┌─────────────┐
        │    ACT      │  call a tool (search, code, API)
        └──────┬──────┘
               ▼
        ┌─────────────┐
        │  OBSERVE    │  read the tool's result
        └──────┬──────┘
               │
        ┌──────▼──────┐
        │  DONE?      │── no ──▶ back to THINK
        └─────────────┘
               │ yes
               ▼
          FINAL ANSWER

The Loop Phases

Phase What Happens Example
Think The model reasons about the goal and picks the next step "I need the current price, so I'll call get_stock_price"
Act The model calls a tool with arguments get_stock_price("RELIANCE")
Observe The tool's output is fed back into the context "₹2,940.50 as of 10:04 AM"
Repeat Loop until the goal is met or a stop condition fires Re-check, compare, summarize
Answer Produce the final response "RELIANCE is up 1.2% today…"

What Makes It "Agentic"

The key property: the model decides the next action based on what it just observed. It's not a fixed script — it adapts. That's what lets one agent write code, run it, read the error, fix the bug, and rerun — autonomously.

Agent vs. Chatbot vs. Workflow

Definition Example
Chatbot Single-turn Q&A, no tools "What's the weather?"
Workflow Fixed, predefined steps Summarize → Translate → Email
Agent Model decides steps dynamically Research → plan → execute → verify

Real-World Agent Examples

  • Coding agents: read your repo, write code, run tests, iterate on failures.
  • Research agents: search the web, read pages, cross-check sources, write a report.
  • Data agents: query databases, clean data, build charts, explain findings.
  • Customer-service agents: check orders, refund policies, draft replies.

Stop Conditions (Crucial!)

Agents need to know when to stop, or they loop forever (and burn tokens):

  1. Goal achieved (final answer ready).
  2. Max steps reached (e.g. 10 tool calls).
  3. Model decides it needs human input.
  4. Budget/token limit hit.
  5. Tool error that can't be recovered.

Key Takeaways

  • An agentic loop = Think → Act → Observe → Repeat → Answer.
  • The model decides the next action from observations — that's the "agentic" part.
  • Agents shine at multi-step, adaptive tasks; workflows win for fixed pipelines.
  • Always define stop conditions — unbounded loops are a real failure mode.

Next up: Tools and function calling — how agents actually do things.

Interactive Lesson Code Snippet
# The agentic loop in its simplest form: plan -> act -> observe -> repeat
def agent_loop(task, max_steps=3):
    print(f"Task: {task}\n")
    for step in range(1, max_steps + 1):
        print(f"Step {step}:")
        print("  Thought: I need more information to complete this task.")
        action = f"search('{task.split('about ')[-1]}')"
        print(f"  Action: {action}")
        print("  Observation: 3 results found.")
        if step == max_steps:
            print("  Final Answer: Task complete based on gathered evidence.")
            break
        print()

agent_loop("Find facts about the Eiffel Tower", max_steps=3)
Language: python

Lesson Code (Python)

# The agentic loop in its simplest form: plan -> act -> observe -> repeat
def agent_loop(task, max_steps=3):
    print(f"Task: {task}\n")
    for step in range(1, max_steps + 1):
        print(f"Step {step}:")
        print("  Thought: I need more information to complete this task.")
        action = f"search('{task.split('about ')[-1]}')"
        print(f"  Action: {action}")
        print("  Observation: 3 results found.")
        if step == max_steps:
            print("  Final Answer: Task complete based on gathered evidence.")
            break
        print()

agent_loop("Find facts about the Eiffel Tower", max_steps=3)

Console Output

Task: Find facts about the Eiffel Tower

Step 1:
  Thought: I need more information to complete this task.
  Action: search('the Eiffel Tower')
  Observation: 3 results found.

Step 2:
  Thought: I need more information to complete this task.
  Action: search('the Eiffel Tower')
  Observation: 3 results found.

Step 3:
  Thought: I need more information to complete this task.
  Action: search('the Eiffel Tower')
  Observation: 3 results found.
  Final Answer: Task complete based on gathered evidence.

Code Visualization Tips

  • 🧠Draw the loop as a circle with the five phases and an arrow back from OBSERVE to THINK.
  • 🧠Trace a real task (e.g. 'book a flight') through the loop, writing each tool call.
  • 🧠Annotate where stop conditions fire — circle the moment the agent should stop.

Professional Tips & Tricks

  • ⚡Start with a workflow; upgrade to an agent only when the steps genuinely vary per task.
  • ⚡Log every Think/Action/Observation — agent debugging is impossible without traces.
  • ⚡Give agents a 'ask the user' tool: knowing when to stop and ask is a feature, not a failure.

Python Code Judge & Practice Arena

LeetCode Style

Run real Python 3.12 WebAssembly code directly in your browser against automated test suites.

Solved:0 / 1
0 / 20 XP
Challenges:
Problem 1 of 1

Trace an Agentic Loop

Medium+20 XP
Trace how an agent would answer 'Is it cheaper to fly or take the train from Delhi to Mumbai next Friday?' — write the Think/Action/Observation sequence and the stop condition.
main.pyPython 3.12 (WASM)
1
2
3
4
5
6
7
8
9
10
11
12
Press Run Code to test or Submit to verify test cases

Test Your Knowledge

Instant feedback

Quick Check: Agentic Loops & AI Agents

1 / 3
What are the phases of the agentic loop?

Up next · Continue learning

Tools & Function Calling

Tools are how agents touch the world. Learn function calling, tool schemas, and the ReAct pattern with a real example.

11 mins read60 mins
Start next lesson
Previous: Detecting & Reducing HallucinationsNext: Tools & Function Calling
Made withbyAmol Shukla·amolshukla.online
ASAmol Shukla

AI Developer, Trainer & Agentic AI Expert building practical learning systems and real-world AI applications.

Explore

  • Projects
  • Courses
  • Prompts
  • Skills
  • Contact
  • Experience
  • Blogs

Connect

  • Resume
  • Contact
© 2026 Amol Shukla·Created withbyamolshukla.online
Back to top