๐Ÿ“˜ Basics

AI Agents: Build Your First One in 30 Minutes

What an AI agent is, when to use one, and a working ReAct agent from scratch. The architecture that powers Claude Code, Devin, and Manus.

๐Ÿ“… June 30, 2026 ๐Ÿ“Š Level: intermediate ๐Ÿ“ฆ GitHub: anthropics/claude-agent-sdk-python

Sponsored

AI Agents: Build Your First One in 30 Minutes

An AI agent is an LLM that can use tools and make decisions in a loop. Claude Code, Devin, and Manus are all agents. This tutorial builds one from scratch.

What is an agent?

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”     โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚   LLM    โ”‚โ”€โ”€โ”€โ”€โ–บโ”‚  Action  โ”‚โ”€โ”€โ”€โ”€โ–บโ”‚ Observe  โ”‚
โ”‚ (think)  โ”‚     โ”‚ (use toolโ”‚     โ”‚ (result) โ”‚โ”€โ”€โ”
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜     โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚
      โ–ฒ                                         โ”‚
      โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

The LLM thinks โ†’ picks a tool โ†’ observes result โ†’ repeats until done.

From LLM to agent

def naive_agent(user_request):
    response = llm(user_request)
    return response  # one-shot, no tools

Thatโ€™s just an LLM. Not an agent.

def real_agent(user_request, tools):
    messages = [{"role": "user", "content": user_request}]
    while True:
        response = llm_with_tools(messages, tools=tools)
        if response.tool_call:
            result = execute_tool(response.tool_call)
            messages.append({"role": "tool", "content": result})
        else:
            return response.content

Thatโ€™s an agent.

Your first ReAct agent

import openai
import json

client = openai.OpenAI()

def calculator(expression: str) -> str:
    return str(eval(expression))  # don't do this in prod

def search_web(query: str) -> str:
    # Call your search API here
    return f"Top result for {query}: ..."

tools = [
    {"type": "function", "function": {
        "name": "calculator",
        "description": "Evaluate a math expression",
        "parameters": {"type": "object", "properties": {"expression": {"type": "string"}}, "required": ["expression"]}
    }},
    {"type": "function", "function": {
        "name": "search_web",
        "description": "Search the web for current information",
        "parameters": {"type": "object", "properties": {"query": {"type": "string"}}, "required": ["query"]}
    }},
]

def run_agent(user_request):
    messages = [{"role": "user", "content": user_request}]
    for _ in range(5):  # max iterations
        response = client.chat.completions.create(
            model="gpt-4o-mini",
            messages=messages,
            tools=tools,
        )
        msg = response.choices[0].message
        messages.append(msg)
        if msg.tool_calls:
            for tool in msg.tool_calls:
                args = json.loads(tool.function.arguments)
                result = globals()[tool.function.name](**args)
                messages.append({"role": "tool", "tool_call_id": tool.id, "content": result})
        else:
            return msg.content
    return "Max iterations reached"

print(run_agent("What's 25 * 4 and what's the weather in Tokyo?"))

Key takeaways

๐Ÿ“ฆ ๅผ€ๆบ้กน็›ฎ

ๆœฌๆ•™็จ‹ๅŸบไบŽๅผ€ๆบ้กน็›ฎ anthropics/claude-agent-sdk-python ๆ•ด็†ใ€‚

โญ View on GitHub โ†’

Sponsored

๐Ÿ› ๏ธ Related Tools & Resources

Mechanical Keyboards โ†’
For coding & writing tutorials
USB-C Hubs โ†’
Multi-monitor dev setup
Noise-Cancelling Headphones โ†’
Focus while learning
Laptop Stands โ†’
Ergonomics for long tutorials