Alejandro Rioja.
AI Agents

How to Build Your First AI Agent in 15 Minutes

Alejandro Rioja
Alejandro Rioja
6 min read
TL;DR

You don't need a framework, a course, or a PhD. You need Node.js, the Anthropic SDK, and 25 lines of TypeScript. This tutorial builds a real, working agent — a structured content summarizer you can deploy to Cloudflare in the same session. The only prerequisite is a free API key.

Free newsletter

Every Wednesday. 28,400+ operators. Zero fluff.

Table of contents

Open Table of contents

Why most “build an AI agent” tutorials fail you

They either use Python (fine for ML engineers, friction for everyone else), hide the real code behind a framework like LangChain, or build something too abstract to connect to your actual work.

This tutorial does three things differently:

  1. TypeScript only — if you’ve ever written JavaScript, you can follow this
  2. No framework — you’ll see every line of code that touches the model
  3. A useful output — you’ll build a structured summarizer you can actually use on customer emails, reviews, or meeting notes

What you’re building

A content summarizer agent: paste any block of text, get back a structured summary in a consistent format. One HTTP request in, one clean summary out.

Why this as a first project: the pattern — system prompt + user input → structured output — is the foundation of every agent I run. Swap the system prompt and you have a question-answerer, a tone rewriter, a classifier, or a draft generator. Learn this once and you’ve learned 80% of what production agents actually do.

Prerequisites (2 minutes)

No Docker. No virtual environment. No pip install anything.

Step 1: Create the project (2 minutes)

bash
mkdir my-first-agent && cd my-first-agent
npm init -y
npm install @anthropic-ai/sdk
npm install -D tsx typescript

Add a script to package.json so you can run the agent easily:

json
{
  "scripts": {
    "agent": "tsx agent.ts"
  }
}

Step 2: Write the agent (5 minutes)

Create agent.ts and paste this:

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

const client = new Anthropic({
  apiKey: process.env.ANTHROPIC_API_KEY,
});

const SYSTEM_PROMPT = `You are a precise content summarizer. When given any block of text, return a structured summary in this exact format:

**One-line summary:** <the core point in one sentence>

**Key points:**
- <point 1>
- <point 2>
- <point 3 if applicable>

**Action item (if any):** <one concrete next step, or "None">

Be specific. No filler. Under 150 words total.`;

async function summarize(text: string): Promise<string> {
  const message = await client.messages.create({
    model: "claude-haiku-4-5",
    max_tokens: 512,
    system: SYSTEM_PROMPT,
    messages: [{ role: "user", content: text }],
  });

  const block = message.content[0];
  if (block.type !== "text") throw new Error("Unexpected response type");
  return block.text;
}

const sample = `
  Hey team — following up on the Q2 review meeting.
  We agreed to push the launch to July 15th instead of June 30th
  due to the payment integration delay. Marketing needs the new
  landing page copy by June 20th or we can't start the email campaign.
  Budget for the launch campaign is confirmed at $8,000.
  Please confirm receipt.
`;

const result = await summarize(sample);
console.log(result);

Step 3: Run it (1 minute)

bash
ANTHROPIC_API_KEY=sk-ant-... npm run agent

Expected output:

code
**One-line summary:** Launch pushed to July 15th due to payment delay; landing page copy needed by June 20th to unblock email campaign.

**Key points:**
- Launch date moved from June 30th to July 15th
- Landing page copy deadline: June 20th (blocks email campaign)
- Campaign budget confirmed at $8,000

**Action item (if any):** Confirm receipt and deliver landing page copy by June 20th.

That’s a working AI agent. Real input, custom system prompt, structured output. The whole thing is 30 lines of code.

Step 4: Customize it for your use case

The system prompt is the only thing that makes this agent yours. Here are three drop-in alternatives:

Customer review classifier:

code
Classify this customer review as POSITIVE, NEGATIVE, or MIXED.
Then extract the main complaint or praise in one sentence.
Format: SENTIMENT: <label>
RESUME: <one sentence>

Meeting transcript → action items:

code
Extract all action items from this meeting transcript.
Format each as: [OWNER if mentioned] [ACTION] by [DEADLINE if mentioned]
If owner or deadline is not stated, leave those fields blank.
Return a numbered list. No preamble.

Tone rewriter for social:

code
Rewrite this text in a direct, confident, first-person tone for LinkedIn.
Remove hedging language ("I think", "maybe", "sort of").
Keep it under 200 words. Return only the rewritten text, no commentary.

Each of these is the same 30-line agent with a different system prompt. You don’t need a new project for each — just update SYSTEM_PROMPT and re-run.

Step 5: Deploy to production

A local script is a prototype. A production agent runs on a schedule or in response to events. The path I use: Cloudflare Workers.

Workers are free up to 100k requests/day, deploy in seconds, and give you cron triggers, KV storage, and queues without managing any infrastructure.

Install Wrangler and scaffold a Worker:

bash
npm install -g wrangler
wrangler init my-agent-worker --template worker-typescript
cd my-agent-worker
npm install @anthropic-ai/sdk

Store your API key as a secret (never in code):

bash
wrangler secret put ANTHROPIC_API_KEY

Replace src/index.ts with:

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

export default {
  async fetch(request: Request, env: Env): Promise<Response> {
    const { text } = await request.json<{ text: string }>();

    const client = new Anthropic({ apiKey: env.ANTHROPIC_API_KEY });
    const message = await client.messages.create({
      model: "claude-haiku-4-5",
      max_tokens: 512,
      system: YOUR_SYSTEM_PROMPT,
      messages: [{ role: "user", content: text }],
    });

    const block = message.content[0];
    if (block.type !== "text") return Response.json({ error: "Bad response" }, { status: 500 });
    return Response.json({ summary: block.text });
  },
};

Deploy:

bash
wrangler deploy

You now have a live API endpoint at https://my-agent-worker.<your-subdomain>.workers.dev. Call it from Zapier, a Google Sheets script, a mobile app — anywhere that can make an HTTP request.

What to build next

Once you have the basic pattern working, complexity comes in three flavors:

Tool use — let the model decide when to call external APIs. Instead of always running the same logic, the model chooses which tool to invoke based on the input. This is how you build agents that search, write to databases, or send notifications.

Chaining — pass one agent’s output as another agent’s input. A classifier routes to a responder; a summarizer feeds a translator. Most of the agents I run in production are two- or three-step chains, not single calls.

Cron triggers — add [triggers] crons = ["0 8 * * *"] to wrangler.toml and your agent runs on a schedule. No polling, no always-on server. This is how the content pipeline I use to run this site works.

I covered all three patterns with full TypeScript code in The Agent Stack I Use to Run 30+ Production Agents — that post picks up where this one ends.

The operator’s bottom line

The gap between “thinking about building an agent” and “having a deployed agent” is about 15 minutes and 30 lines of code. The system prompt is the product — spend your energy there, not on picking a framework. If the agent saves you one hour a week, that’s 50 hours a year. Build the simple version first, see if it earns its keep, then add complexity only when the use case demands it.

Keep reading

Get the AI playbook in your inbox

Every Wednesday. 28,400+ operators. Zero fluff.

↵ to see all results esc esc to close