agents

AI Agent

Learn what AI Agent means in AI and machine learning, with examples and related concepts.

Definition

An AI Agent is an LLM-powered system that can autonomously plan, reason, and take actions to accomplish a goal — including calling external tools, browsing the web, executing code, and reading/writing files.

Unlike a basic chatbot that just responds to one message at a time, an agent operates in a loop: it observes its environment, decides what to do next, takes an action, observes the result, and repeats until the task is done.

Claude Code is a prime example — you give it a task like “refactor this module to use async/await,” and it reads files, plans changes, edits code, runs tests, and fixes errors, all autonomously.

How It Works

┌──────────────────────────────────┐
│          Agent Loop              │
│                                  │
│  1. OBSERVE  ← environment/tool  │
│       ↓         results          │
│  2. THINK   ← reasoning/planning│
│       ↓                          │
│  3. ACT     → call tool, write   │
│       ↓        file, run code    │
│  4. Check: goal achieved?        │
│       ├─ No  → back to step 1   │
│       └─ Yes → return result     │
└──────────────────────────────────┘

The key components:

Why It Matters

Example

# Simplified agent loop using Claude's tool use
from anthropic import Anthropic

client = Anthropic()
tools = [
    {
        "name": "read_file",
        "description": "Read a file from disk",
        "input_schema": {
            "type": "object",
            "properties": {
                "path": {"type": "string", "description": "File path"}
            },
            "required": ["path"]
        }
    },
    {
        "name": "write_file",
        "description": "Write content to a file",
        "input_schema": {
            "type": "object",
            "properties": {
                "path": {"type": "string"},
                "content": {"type": "string"}
            },
            "required": ["path", "content"]
        }
    }
]

messages = [{"role": "user", "content": "Read config.json and add a 'debug' field set to true."}]

# Agent loop
while True:
    response = client.messages.create(
        model="claude-sonnet-4-6",
        max_tokens=1024,
        tools=tools,
        messages=messages
    )

    if response.stop_reason == "end_turn":
        print("Agent finished:", response.content[0].text)
        break

    # Process tool calls
    for block in response.content:
        if block.type == "tool_use":
            result = execute_tool(block.name, block.input)  # your implementation
            messages.append({"role": "assistant", "content": response.content})
            messages.append({
                "role": "user",
                "content": [{"type": "tool_result", "tool_use_id": block.id, "content": result}]
            })

Key Takeaways


Part of the DeepRaft Glossary — AI and ML terms explained for developers.