Course overview

The Agent Loop: Perceive, Reason, Act, Reflect

What makes an agent actually autonomous?

Here's the thing, when most people hear "AI agent," they picture a chatbot that responds to prompts. From what I've seen, agents are fundamentally different from LLMs in one crucial way: they operate in a continuous loop, not one-shot exchanges. An LLM waits for you to ask a question, generates text, and stops. An agent perceives its environment, reasons about what to do next, acts through tool calls, and reflects on the results, then does it all over again until the job is done.

This cognitive cycle is what makes agents autonomous. They don't need you to prompt them at every step. You give them a goal ("process this customer inquiry") and they figure out the sequence: check the CRM, validate the contact info, route to the right team, log the interaction. The loop keeps running until they decide the task is complete.

Chi Wang and Qingyun Wu, who created AutoGen (now AG2) at Microsoft Research, pioneered this shift from conversational turns to persistent agent loops. Their work showed that real business workflows need agents that can maintain state, execute tools, and adapt, not just generate polite replies.

Diagram showing the perceive-reason-act cognitive cycle with arrows connecting environment, beliefs, goals, plan library, and actions
The fundamental agent loop: agents perceive their environment, reason about goals and context, and act through tool execution in a continuous cycle.

Check your understanding

Match each phase of the agent loop to what happens during that step.

ReAct: the pattern that makes agents work

Most production agents today use a pattern called ReAct (Reasoning + Acting), formalized by Shunyu Yao in 2022. The core idea is simple: instead of trying to reason through an entire problem in one shot, the agent interleaves thinking with doing. It thinks ("I need to find recent conversations from the healthcare vertical"), acts (searches the CRM), observes the result, thinks again ("Okay, these three accounts look promising"), acts again (pulls contact details), and keeps going.

This sounds obvious, but it's a huge shift from older chain-of-thought prompting. Chain-of-thought asks the LLM to reason about a problem entirely in text, then answer. ReAct lets the agent take actions mid-reasoning and learn from real feedback. When a CTF cybersecurity agent using ReAct with GPT-4o was tested, it hit 83% task completion. Add a planning step upfront (a hybrid called ReAct&Plan), and success jumped to 95%. The loop works.

Here's what a ReAct cycle looks like for a sales lead qualification agent: Thought ("I need to check if this lead matches our ICP") → Action (query CRM for company size and industry) → Observation ("Series B SaaS, 150 employees, healthcare vertical") → Thought ("Strong fit, let's see recent engagement") → Action (pull email opens and demo requests). The agent builds understanding incrementally, not all at once.

Why ReAct beats pure reasoning

Chain-of-thought prompting tries to solve problems entirely in the LLM's "head." ReAct lets the agent test ideas in the real world and course-correct based on actual results. For exploratory tasks where you don't know the path upfront, that feedback loop is everything.

Check your understanding

A customer service agent needs to handle a refund request, but the business rules vary by product type, subscription status, and purchase date. Why would ReAct be a better choice than generating a full plan upfront?

Plan-and-Execute: when you know the workflow upfront

ReAct is great for exploration, but sometimes you already know the shape of the solution and just need to execute it reliably. That's where Plan-and-Execute comes in. This pattern splits the work between two agents: a Planner that decomposes the goal into ordered steps (without calling any tools), and an Executor (usually a ReAct agent) that runs those steps one by one.

IBM's multi-agent RAG system uses this approach with six specialized agents. The Planner agent breaks down "generate a quarterly research report" into discrete tasks: gather documents from the vector store, extract key metrics, summarize findings, format the report. The Executor agents handle each step in sequence, calling the right tools at the right time. The separation of concerns makes the system more predictable and easier to debug than a single ReAct loop trying to figure everything out on the fly.

Oracle Integration's enterprise inquiry management system demonstrates this beautifully. The Planner decomposes "process customer inquiry" into: validate contact info, check account status in the CRM, route to the appropriate support team, log the interaction in the ticketing system. The Executor then runs each step, handles errors, and reports completion. For well-defined workflows where the steps are known, this beats ReAct on cost and reliability.

Plan-and-Execute can be too rigid

If your workflow involves genuine uncertainty or branching logic that depends on real-time data, a pure Plan-and-Execute approach can fail. The Planner doesn't see tool results, so it can't adapt mid-flight. That's why hybrid approaches (ReAct&Plan) are becoming the production standard.

Check your understanding

In the cybersecurity CTF challenge study, a pure ReAct agent achieved 83% task completion, but adding an upfront planning step (ReAct&Plan hybrid) improved success to ____%.

Tool calling: the bridge from text to action

All of this, ReAct, Plan-and-Execute, hybrid loops, depends on one core capability: tool calling. This is what transforms an LLM from a text generator into an agent that can actually do things. When the agent decides it needs to "search the CRM for recent healthcare leads," tool calling is the infrastructure that translates that intent into a structured API request with authentication, parameter validation, error handling, and response parsing.

From what I've seen, people underestimate how much engineering goes into tool calling. It's not just "the LLM picks a function and calls it." You need schemas so the LLM knows what parameters each tool expects. You need credential management so the agent can authenticate securely. You need error recovery so a failed API call doesn't crash the entire loop. And you need result processing so the agent can observe the outcome and feed it back into reasoning.

A Salesforce account creation workflow shows this in action. The agent calls the Salesforce API to create an Account record, parses the response to extract the new AccountID, then uses that ID in a second tool call to create a Task and assign ownership. State management across tool calls, remembering the AccountID from step one to use in step two, is what makes multi-step workflows possible. Modern frameworks like AG2 (the 2026 evolution of AutoGen) use event-driven architectures with pub/sub patterns to handle this stateful coordination at production scale.

Six-step tool calling loop diagram showing Tool Discovery, LLM Processing, Tool Selection, Execution, Result Processing, and Response Formation
Modern tool calling in 2026 includes dynamic tool discovery via MCP or vector stores before the LLM selects and executes appropriate tools.

Novo Nordisk's drug discovery agents

Novo Nordisk uses AG2 to coordinate specialized agents for pharmaceutical research: a planner that decomposes research questions, a research assistant that queries scientific databases and internal corpora, and a report generator that synthesizes findings. Each agent calls domain-specific tools (PubMed APIs, molecular simulation engines, internal document stores) through a shared tool-calling layer with credential vaulting and audit logging.

Reflection and memory: how agents get smarter over time

The loop doesn't end with action and observation. Reflection is what closes the cycle, the agent looks at the result of its last action and decides whether to keep going, change strategy, or declare success. This is where memory comes in. Without persistent storage, every loop iteration starts from scratch. With memory, agents can learn from past interactions, avoid repeating mistakes, and maintain context across long-running tasks.

Production agents use a few types of memory. Working memory holds the current conversation and recent tool results (usually in the LLM's context window). Episodic memory stores past interactions in a vector database so the agent can retrieve relevant examples ("Last time a customer asked about refunds for subscriptions, we checked the cancellation date first"). State checkpoints let you pause and resume workflows without losing progress, critical for tasks that span hours or days.

AG2's Beta architecture, released in March 2026, introduced event-driven pub/sub patterns specifically to handle stateful agents at scale. Agents publish observations and decisions to named event streams; other agents subscribe and react. This decouples reasoning from state management, so you can scale agents horizontally without tangling their memory. For enterprise workflows like multi-day approval chains or background research tasks, this architecture is table stakes.

Key takeaways

  • Agents run continuous perceive-reason-act-reflect loops, not one-shot prompt-response cycles, that's what makes them autonomous.
  • ReAct interleaves thinking with doing, letting agents learn from real tool feedback and adapt mid-execution, ideal for exploratory tasks.
  • Plan-and-Execute separates strategic planning from execution, making workflows more predictable for well-defined processes, but hybrid approaches (ReAct&Plan) are often best.
  • Tool calling is the engineering layer that turns LLM text into real actions, handling authentication, parameter validation, error recovery, and state management across multi-step workflows.
  • Reflection and memory (working, episodic, checkpointed state) let agents improve over time and maintain coherent behavior across long-running tasks.

Your product check-in

Apply “The Agent Loop: Perceive, Reason, Act, Reflect” to a product or workflow you know. What would you try, what could go wrong, and what evidence would help you decide?

Ask AI
AI Learning Assistant