Tutorial·3 min read·

YourFirstAgent

Build a working AI agent in 30 minutes. No frameworks, no abstractions — just TypeScript and an API call.

Abdulhadi Alturafi
Abdulhadi AlturafiApr 20, 2026
Your First Agent
0

What Is an AI Agent?#

An AI agent is an LLM that can take actions. That's it. Not a framework, not a library, not a buzzword.

It's a loop:

  1. Read the situation
  2. Decide what to do
  3. Do it
  4. Check the result
  5. Repeat

Like this? Get the next post in your inbox — two emails a week, every one shippable.

The Simplest Agent#

Here's a complete, working agent in TypeScript:

import Anthropic from "@anthropic-ai/sdk";

const client = new Anthropic();

const tools = [
  {
    name: "read_file",
    description: "Read a file from disk",
    input_schema: {
      type: "object" as const,
      properties: {
        path: { type: "string", description: "File path" },
      },
      required: ["path"],
    },
  },
];

async function runAgent(task: string) {
  const messages: Anthropic.MessageParam[] = [
    { role: "user", content: task },
  ];

  while (true) {
    const response = await client.messages.create({
      model: "claude-sonnet-4-6",
      max_tokens: 4096,
      tools,
      messages,
    });

    if (response.stop_reason === "end_turn") {
      return response.content;
    }

    // Agent wants to use a tool
    messages.push({ role: "assistant", content: response.content });

    const toolResults = [];
    for (const block of response.content) {
      if (block.type === "tool_use") {
        const result = await executeTool(block.name, block.input);
        toolResults.push({
          type: "tool_result" as const,
          tool_use_id: block.id,
          content: result,
        });
      }
    }

    messages.push({ role: "user", content: toolResults });
  }
}
Insight

The entire "agent framework" is a while loop. The LLM decides when to stop. That's the only magic.

Adding More Tools#

The power of an agent comes from its tools. Want it to write files? Add a write_file tool. Want it to run commands? Add a run_bash tool.

const tools = [
  { name: "read_file", /* ... */ },
  { name: "write_file", /* ... */ },
  { name: "run_command", /* ... */ },
  { name: "search_code", /* ... */ },
];

Each tool is just a function. The LLM decides which ones to call and in what order.

Warning

Start with read-only tools. Add write tools only after you trust the agent's judgment. A run_command tool with no restrictions is a footgun.

From Agent to System#

A single agent is useful. Multiple agents working together is transformative.

That's what I'll cover in the next post: how to orchestrate multiple agents, share context between them, and build systems that are greater than the sum of their parts.


The best way to understand agents is to build one. Copy the code above, add your API key, and run it. You'll learn more in 30 minutes than from any framework tutorial.

Like this? Get the next post in your inbox — two emails a week, every one shippable.

0
MCP servers, zero to one
Read next

MCP servers, zero to one

How to wire up your first Model Context Protocol server in under twenty minutes.

Continue reading

More from How to A1