Back to modules
Module 1

Fundamentals: What Are Agents?

Understand the core concept of agents, the agentic loop, and how they differ from traditional LLM APIs.

📖 25 min
Core ConceptsAgentic LoopCLI vs SDKUse Cases

The Agentic Loop Explained

Every agent follows this cycle:

plaintext
1. Receive Task

↓

  • Claude Evaluates
  • "What do I need to do? What tools should I use?"

    ↓

  • Tool Calls
  • Claude requests to use tools (Read, Bash, WebSearch, etc)

    ↓

  • Execute Tools
  • System runs the tools and captures results

    ↓

  • Tool Results
  • Results are sent back to Claude

    ↓

  • Claude Decides
  • "I have the information. Should I use more tools or respond?"

    ↓

    → If more tools needed: Go to step 3

    → If done: Proceed to step 7

    ↓

  • Return Final Response
  • Claude produces text response with no tool calls

    One complete cycle (steps 2-5) is called a turn. The loop continues for multiple turns until Claude decides it has enough information to respond.

    Example: Reading a File

    plaintext
    Agent task: "Read package.json and tell me what version of React is installed"

    Turn 1:

    - Claude sees task

    - Claude says: "I need to read package.json"

    - Agent calls Read("package.json")

    - System returns file contents

    - Claude reads the result

    - Claude says: "React version is 18.2.0"

    - No more tools needed, done!

    Example: Multi-Turn Task

    plaintext
    Agent task: "Find and fix the memory leak in api.ts"

    Turn 1:

    - Claude: "I need to see the code"

    - Agent calls Read("api.ts")

    - System returns code

    - Claude: "I see some event listeners. Let me check what's listening"

    Turn 2:

    - Claude: "I need to search for all addEventListener calls"

    - Agent calls Grep for "addEventListener"

    - System returns matches

    - Claude: "Found the issue! Missing removeEventListener"

    Turn 3:

    - Claude: "I'll fix it"

    - Agent calls Edit() with the fix

    - Claude: "Fixed! Let me verify with tests"

    Turn 4:

    - Claude: "Running tests to confirm"

    - Agent calls Bash("npm test")

    - System returns test results

    - Claude: "Tests pass! Done."

    ---

    Three Execution Environments

    1. Claude Code CLI (Command Line)

    The Claude Code CLI is an interactive assistant that uses agents internally. When you run claude in your terminal, you're using agents.

    Key features:

    • Spawns subagents automatically when needed
  • Reads your codebase and executes commands
  • Stores context across turns in a session
  • Best for: Day-to-day coding tasks, one-off problems, interactive work

    Example:

    bash
    $ claude "Find all console.log statements and replace them with logger.info"

    2. Agent SDK / API

    The Agent SDK is a library (Python or TypeScript) you embed in your own code. You write a program that uses agents to solve problems.

    Key features:

  • Full programmatic control over the agent loop
  • Choose which tools are available
  • Set cost limits, iteration limits
  • Build applications powered by agents
  • Best for: Automated workflows, server-side processing, custom applications

    Example (Python):

    python
    from claudeagentsdk import query
    

    async def main():

    async for message in query(

    prompt="Analyze these logs and find errors",

    options={"allowed_tools": ["Read", "Grep", "WebSearch"]}

    ):

    print(message)

    asyncio.run(main())

    3. Managed Agents

    Anthropic's cloud-hosted managed agents (coming soon). You describe a task and agents run it in the cloud without you managing infrastructure.

    ---

    Why Use Agents?

    Problems Agents Solve

    Problem 1: Multi-step workflows

  • Tasks that require multiple decisions and tool uses
  • Agents can iterate until complete
  • Problem 2: Autonomous operation

  • You can't manually guide each step
  • Agents decide what's needed and execute
  • Problem 3: Complex analysis

  • Tasks requiring reading, searching, comparing multiple sources
  • Agents can gather information systematically
  • When NOT to Use Agents

  • Simple, one-shot tasks ("Explain this code") → Use Claude API directly
  • Real-time interaction required → Use Claude API (agents add latency from tool execution)
  • Highly constrained costs → Agents use more tokens (reasoning + tool loops)
  • ---

    Key Concepts Summary

    ConceptMeaning
    ---------
    AgentAI system that decides what tools to use to complete a task
    Agentic LoopCycle of: decide → use tools → evaluate results → repeat
    TurnOne cycle of Claude evaluating and tool execution
    ToolAn action the agent can take (Read files, run Bash, etc.)
    Tool ResultThe output from a tool, sent back to Claude
    ContextAll conversation history and results accumulated so far

    ---

    Common Gotchas

    Gotcha #1: Agents are slower than one-shot API calls

  • Each tool use adds latency (reading files, running commands)
  • Use agents for complex tasks, not simple ones
  • Gotcha #2: Agents use more tokens

  • Reasoning about what tools to use → tokens
  • Tool results flow back → tokens
  • Budget accordingly
  • Gotcha #3: Agents aren't perfect

  • Claude might misinterpret a task
  • Claude might use the wrong tool
  • Good prompt design helps!
  • ---

    Next Steps

    You now understand what agents are and how the agentic loop works. In the next module, we'll explore Claude Code's CLI agent system — how to spawn subagents, control them, and use them in your workflow.