Skip to main content

Lesson 9: The Anatomy of an Agent

Topics Covered
  • The Core Loop: The circular architecture of autonomous systems.
  • Sense: Normalizing the messy world into tokens.
  • Think: The cognitive engine (Planning and Routing).
  • Guardrails: The critical safety layer (Input/Output checks).
  • Act: The difference between "generation" and "side effects."

An AI Agent isn't just "smarter" software; it is a system designed to mirror biological cognition. To build one, we must replicate the fundamental phases of intelligent life: Sensing, Thinking, and Acting, with a critical layer of Safety.

1. Sense (Perception & Normalization)​

Before an agent can act, it must understand the state of the world. Since LLMs only understand tokens (text/code), the "Sense" phase is entirely about converting raw signals into text.

  • User Input: The prompt (e.g., "Refund this order").
  • Digital State: Reading database rows, checking API status codes, or parsing email headers.
  • Physical Sensors: Converting camera pixels or microphone audio into text descriptions.

The Engineering Goal: Create a unified "Context Object" that represents the current reality.

2. Think (The Cognitive Engine)​

This is the Agent's "Brain." It takes the Context Object and decides what to do next using the ReACT pattern.

  • Plan: Break the user's goal into steps. ("First verify the order, then check the policy, then process the refund.")
  • Route: Decide which specialized tool is needed. ("This is a billing issue, not technical support.")
  • Memory Access: Retrieve user preferences from the Vector Database.

3. Guardrails (The Safety Layer)​

An autonomous agent needs a conscience. Guardrails are programmable rules that sit between the Brain and the World.

  • Input Rails (Before the LLM):
    • PII Scrubbing: Automatically redaction of credit card numbers or SSNs before they reach the model.
    • Jailbreak Detection: Blocking prompts that try to trick the agent (e.g., "Ignore all previous instructions").
  • Output Rails (Before the Action):
    • Hallucination Check: Does the answer cite a source that actually exists?
    • Forbidden Topics: Ensuring the "Travel Agent" doesn't give medical advice.
    • Syntax Validation: Ensuring the SQL query generated by the model doesn't contain DROP TABLE commands.

4. Act (The Hands)​

This is where the agent leaves the safety of the chat window and touches the real world.

  • Digital Actions: Executing a SQL query, sending a POST request to Stripe, or posting to Slack.
  • Physical Actions: Sending a signal to a robotic arm.

Critical Concept: Side Effects In Generative AI, the output is just pixels on a screen. In Agentic AI, the output is a Side Effect (money moved, data deleted). This requires strict permission layers—agents should often have "Read" access by default but require human confirmation for "Write" actions.

5. Learn (The Feedback Loop)​

How does an agent get better?

  1. Runtime Observation: The agent acts -> The tool returns an error -> The agent reads the error -> The agent tries a different parameter (Self-Correction).
  2. Offline Fine-Tuning (RLHF): Engineers review logs. Successful paths are reinforced; failed paths are penalized.

6. Applied Anatomy: The "Refund Bot"​

PhaseActionSystem Component
SenseIngest email: "Where is my refund?"NLP Parser
ThinkLookup User ID. Retrieve Order #123.RAG + LLM Logic
GuardrailCheck: Is the refund amount < $50 (Auto-approve) or > $50 (Manager Approval)?Python Policy Logic
ActCall StripeAPI.issueRefund(123).Tool / API Client
LearnAPI returns "Success." Close ticket.Feedback Loop