Connect with me via the floating button
Ship a working TypeScript agent that classifies tasks and recommends next actions.
Now you will build a small but real agent: it reads a task, classifies urgency, and outputs an action plan. This example is intentionally narrow so you can ship it today.
Create a minimal TypeScript app with one model client and one tool.
pnpm add openai zod
Use server-side environment variables only. Never expose keys in client bundles.
import 'server-only';
import OpenAI from 'openai';
export const client = new OpenAI({ apiKey: process.env.OPENAI_API_KEY! });
Your agent should return structured JSON, not free text.
import { z } from 'zod';
export const triageSchema = z.object({
priority: z.enum(['low', 'medium', 'high']),
owner: z.string().min(1),
nextAction: z.string().min(10),
dueInHours: z.number().int().min(1).max(168),
});
export type TriageResult = z.infer<typeof triageSchema>;
Keep tool scope small: normalize due dates and estimate urgency from tags.
type TaskInput = { title: string; tags: string[]; customerTier?: 'standard' | 'vip' };
function scoreUrgency(task: TaskInput): number {
let score = 0;
if (task.tags.includes('outage')) score += 5;
if (task.tags.includes('billing')) score += 2;
if (task.customerTier === 'vip') score += 3;
return score;
}
Prompt for JSON matching triageSchema, parse it, and reject invalid output.
const parsed = triageSchema.safeParse(modelOutput);
if (!parsed.success) {
throw new Error('Invalid agent output');
}
return parsed.data;
Practical advice: log raw model output before parsing, but never log secrets or customer PII.
If these cases fail gracefully, you already have a production-ready foundation for simple internal automations.
Build this triage agent and run it against ten real tasks from your backlog. Compare agent recommendations with your manual decisions. Measure agreement rate and edit your scoring logic before adding more tools.
Full access
Unlock all 5 lessons, templates, and resources for AI Agent Fundamentals. Free.