Check my levelCoursesProgramsFor teamsPricing
UKSign inSign up
Check my levelCoursesProgramsFor teamsPricingClaude quizPromptsBlogFAQSearchSign upUK
AcademlCoursesAI Agents: From Architecture to ProductionThe Agent Loop: Perception → Reasoning → Action
An agent trace: a run with model calls and a tool call on a time axisThe agent loop: reason, act, observeOne MCP connector linking files, Git and memory
Get started free
Course

AI Agents: From Architecture to Production

Module 1 · AI Agent Architecture
01The Agent Loop: Perception → Reasoning → Action02Tool Calling: Deep Dive03Agent Memory Patterns
Module 2 · Multi-Agent Systems
04Orchestrator–Worker Pattern05Model Context Protocol (MCP)06Agent-to-Agent (A2A) Protocol
Module 3 · Agents in Production
07Evaluating Agents08Agent Guardrails09Production Deployment
AI Agents: From Architecture to Production · Lesson 1

The Agent Loop: Perception → Reasoning → Action → Observation

Breaking down the perception → reasoning → action → observation cycle, how LLMs make decisions inside an agent, and why agents are fundamentally different from chatbots.

30 min readUpdated Nov 9, 20262 questions in quizReady prompt included

What is the perception–reasoning–action loop of an AI agent?

An AI agent repeats four steps: perception (it reads the request, memory and earlier tool results), reasoning (the model decides to answer, call a tool or stop), action (your code runs the tool) and observation (the result goes back into the context). The loop ends with a final answer or at an iteration limit.

Start free: 7 days of full access →
Lesson 1 of 9free after sign-up

AI Agents: From Architecture to Production

From the agent loop and tool calling to memory, orchestrator–worker systems, MCP and production concerns. Based on Microsoft's open AI Agents for Beginners course, with code on the Claude API.

Course program →

The rest of this lesson opens after a free sign-up

Sign up with email or Google: the first two lessons of every course stay open for good, and the whole catalog is open for 7 days. No card needed.

Sign up freeOr a trial lesson, no sign-up →

Chatbot vs AI agent

ChatbotAI agent
Passes per requestOne replyMany: a loop of model calls
ToolsNoneCalls tools: search, code, APIs, files
PlanningAnswers the message as writtenPlans steps and revises the plan mid-task
When it stopsAfter one replyFinal answer, iteration limit or a stop signal from a tool
Who controls itThe user, message by messageThe model inside limits set by your code
Adapted from the lesson's comparison table.

One iteration of the loop

  1. PerceptionRequest, memory, previous tool results
    →
  2. ReasoningThe model picks: answer, call a tool or finish
    →
  3. ActionYour code runs the tool or API call
    →
  4. ObservationThe result is appended to messages, then back to step 1
    →
In the Claude API, stop_reason "tool_use" means run the tools and loop again; "end_turn" means the model has answered.

Notes for running the lesson code

Checked on 9 Nov 2026 against the Claude docs and Anthropic's engineering guide.

In this lesson
What Is an AI AgentThe Agent LoopHow the LLM Makes DecisionsAgents vs ChatbotsWhen the Loop StopsReady-Made HarnessesPracticeReady promptQuiz
CoursesLLM coursesFor teamsPricingFAQBlogAboutPrivacy
© 2026 AcademlDevelopment & promotion —MMIX — Marketing Mix
  • Anthropic describes agents as “LLMs using tools based on environmental feedback in a loop” and recommends stopping conditions such as a maximum number of iterations: the lesson's for _ in range(MAX_ITER) loop with MAX_ITER = 10 is that guard.
  • Anthropic separates workflows (LLM calls on predefined code paths) from agents (the model directs its own tool use) and advises starting with the simplest option that works.
  • The example now calls claude-opus-5-5, the model the Claude docs suggest starting with for most workloads. The earlier version used claude-opus-4-5, a legacy model with retirement not sooner than 24 Nov 2026.
  • response.content is a list of blocks, and a thinking block can come first: take the text from blocks whose type is "text", and send every tool_result back with the matching tool_use_id.
  • Handle the other stop reasons too: on pause_turn send the response back as-is; on max_tokens or refusal stop the loop. max_tokens counts thinking and the answer together, so the lesson sets it to 16000.
  • Microsoft's AI Agents for Beginners, the course this one builds on, is MIT-licensed, has 18 lessons and now uses Microsoft Agent Framework in its examples.

Sources we checked

  • Anthropic: Building effective agents
  • Claude docs: Tool use overview
  • Claude docs: Handling stop reasons
  • Claude docs: Model deprecations
  • Microsoft: AI Agents for Beginners (GitHub)
  • Yao et al. (2022): ReAct

FAQ

What are the main parts of an AI agent's architecture?+

A model that reasons, tools it can call, the context it perceives (request, memory, tool results) and the loop code that runs tools, feeds results back and enforces limits. Larger systems add planning, long-term memory and several cooperating agents.

How does the agent loop relate to ReAct?+

ReAct (Yao et al., 2022) interleaves reasoning steps with actions and their observations. Tool-calling APIs implement the same cycle: the model reasons, emits a tool call, your code returns the observation, and the model continues.

When does an agent loop stop?+

When the model returns a final answer with no tool calls (stop_reason "end_turn" in the Claude API), when the iteration limit is reached, or when a tool returns a stop signal. Always set the limit: an agent can loop forever if a tool keeps failing.

Why does my agent loop forever or forget tool results?+

The usual causes from the lesson: no iteration limit, tool results never appended to messages (so the model cannot see what happened), code that keeps calling the model after end_turn, and a loop that handles only end_turn and tool_use, so on max_tokens or refusal it resends the same request.

Do I need a framework like LangGraph or an agents SDK?+

The loop itself fits in a few dozen lines, as the lesson shows. Frameworks add state, memory, tracing and multi-agent routing; Anthropic suggests starting with direct API calls and adding a framework when the task needs it. The lesson names ready-made harnesses: Claude Agent SDK, Claude Managed Agents (beta) and Microsoft Agent Framework.

Is this lesson free?+

Yes. It is lesson 1 of 9 in “AI Agents: From Architecture to Production”, and a free account keeps the first two lessons of every Academl course open for good. A free account opens all lessons for 7 days with no card; after that Pro costs $9 a month or $79 a year.

Related lessons and courses

Next: tool calling deep dive →AI agents course →pip install anthropic: your first request →Claude tool use course →AI agents fundamentals →Advanced AI agents track →

Next: tools, memory and multi-agent systems

The following lessons go deeper into tool calling, agent memory patterns, orchestrator–worker systems and MCP. A free account opens all 9 lessons for 7 days.

Create a free account →

What Is an AI Agent

A chatbot replies and stops. An AI agent is a system that decides what to do next on its own: call a tool, wait for a result, revise its plan, and repeat the cycle until the task is complete.

The key distinction: agents operate in a loop of many passes.