๐ŸŸข Basic

Introduction to AI Agents:
What They Are and How They Work

๐Ÿค– AI Agentsโฑ 11 min read๐Ÿ—“ May 2026

AI agents are one of the most significant developments in artificial intelligence. They transform LLMs from glorified autocomplete systems into systems that can reason, plan, use tools, and accomplish complex multi-step tasks autonomously. If you've heard the term "agentic AI" โ€” this is the foundation.

What Makes an AI Agent Different from a Chatbot?

A chatbot responds to a message. An AI agent pursues a goal.

Traditional Chatbot

Takes one input โ†’ produces one output. Stateless. Can't take actions. Responds to what's asked.

AI Agent

Receives a goal โ†’ plans โ†’ takes actions โ†’ observes results โ†’ adapts โ†’ repeats until done.

The key difference is that agents can act in the world โ€” browsing the web, writing and running code, calling APIs, managing files, sending emails โ€” and they do so iteratively, adapting based on what they observe.

The Agent Loop

Every AI agent runs some variation of this loop:

๐ŸŽฏ Goal
โ†’
๐Ÿง  Think
โ†’
๐Ÿ”ง Act
โ†’
๐Ÿ‘ Observe
โ†’
๐Ÿง  Think
โ†’
... repeat
โ†’
โœ… Done
  1. Goal: The user provides a high-level objective ("Research competitors and create a summary report")
  2. Think: The LLM reasons about what to do next โ€” what information is needed? what tool should I use?
  3. Act: The agent calls a tool (web search, code execution, file read, API call)
  4. Observe: The result of the action is fed back to the LLM
  5. Repeat: The LLM decides next action based on what it observed
  6. Done: The agent determines the goal is achieved and returns the final result

The Four Core Components of an Agent

๐Ÿง  LLM (the Brain)

The language model that reasons, plans, and decides what to do next. Claude, GPT-4, Gemini, or open-source alternatives.

๐Ÿ”ง Tools

External capabilities the agent can call: web search, code runner, file system, databases, APIs, calendar, email.

๐Ÿ’พ Memory

Short-term (conversation history in context window) and long-term (vector DB, external storage).

๐Ÿ“‹ Planning

The ability to break a goal into steps and adapt the plan as new information arrives.

Tool Use: How Agents Act in the World

Tools are functions the agent can call. Modern LLMs support function/tool calling natively โ€” the model outputs a structured request to call a specific function with specific arguments, instead of plain text.

import anthropic

client = anthropic.Anthropic()

# Define the tools available to the agent
tools = [
    {
        "name": "web_search",
        "description": "Search the web for current information",
        "input_schema": {
            "type": "object",
            "properties": {
                "query": {
                    "type": "string",
                    "description": "The search query"
                }
            },
            "required": ["query"]
        }
    },
    {
        "name": "get_weather",
        "description": "Get current weather for a city",
        "input_schema": {
            "type": "object",
            "properties": {
                "city": {"type": "string"}
            },
            "required": ["city"]
        }
    }
]

# The agent decides which tool to call
response = client.messages.create(
    model="claude-opus-4-6",
    max_tokens=1024,
    tools=tools,
    messages=[
        {"role": "user", "content": "What's the weather in Tokyo right now?"}
    ]
)

# If the model wants to use a tool, it returns a tool_use block
if response.stop_reason == "tool_use":
    tool_call = next(b for b in response.content if b.type == "tool_use")
    print(f"Agent wants to call: {tool_call.name}")
    print(f"With arguments: {tool_call.input}")
    # โ†’ Agent wants to call: get_weather
    # โ†’ With arguments: {"city": "Tokyo"}

A Minimal Working Agent

import anthropic
import json

client = anthropic.Anthropic()

def web_search(query: str) -> str:
    """Simulate a web search (replace with real search API)"""
    return f"[Search results for '{query}': Simulated results here]"

def calculator(expression: str) -> str:
    """Evaluate a math expression"""
    try:
        return str(eval(expression))  # In production, use safer eval
    except Exception as e:
        return f"Error: {e}"

TOOLS = [
    {"name": "web_search", "description": "Search the web",
     "input_schema": {"type": "object", "properties": {
         "query": {"type": "string"}}, "required": ["query"]}},
    {"name": "calculator", "description": "Calculate math",
     "input_schema": {"type": "object", "properties": {
         "expression": {"type": "string"}}, "required": ["expression"]}}
]

TOOL_FUNCTIONS = {"web_search": web_search, "calculator": calculator}

def run_agent(user_goal: str, max_iterations: int = 10) -> str:
    messages = [{"role": "user", "content": user_goal}]

    for i in range(max_iterations):
        response = client.messages.create(
            model="claude-opus-4-6",
            max_tokens=2048,
            tools=TOOLS,
            messages=messages
        )

        # Add assistant response to history
        messages.append({"role": "assistant", "content": response.content})

        if response.stop_reason == "end_turn":
            # Extract final text response
            text = next(b.text for b in response.content if hasattr(b, "text"))
            return text

        if response.stop_reason == "tool_use":
            # Execute each tool call
            tool_results = []
            for block in response.content:
                if block.type == "tool_use":
                    fn = TOOL_FUNCTIONS[block.name]
                    result = fn(**block.input)
                    tool_results.append({
                        "type": "tool_result",
                        "tool_use_id": block.id,
                        "content": result
                    })

            # Feed results back to the agent
            messages.append({"role": "user", "content": tool_results})

    return "Maximum iterations reached."

# Run it!
result = run_agent("What is 2847 * 3.14159 and what is the capital of France?")
print(result)

Types of AI Agents

ReAct Agent

Reason + Act in alternating steps. The most common pattern. Foundation of most frameworks.

Plan & Execute

Make a full plan upfront, then execute step by step. Better for structured tasks.

Multi-Agent

Multiple specialized agents collaborate. One orchestrator, many workers. Better for complex tasks.

Code Agent

Writes and executes code to solve problems. Can iterate until tests pass. (Devin, Claude Code)

Where AI Agents Are Used Today

The key insight: Agents unlock exponential value from LLMs. A chatbot can answer questions about your data. An agent can analyze it, identify trends, write a report, and email it to stakeholders โ€” autonomously.

Key Takeaways