Example: Support Triage
Build a support ticket triage agent that classifies and routes tickets.
Overview
This example builds an agent that:
- Reads a support ticket
- Classifies it (billing, technical, general)
- Assigns priority (low, medium, high)
- Routes to the appropriate team
Implementation
import { defineAgent, defineTool, createLLM } from '@ahzan-agentforge/core';
import { z } from 'zod';
const classifyTool = defineTool({
name: 'classify-ticket',
description: 'Classify a support ticket by category and priority',
input: z.object({
ticketId: z.string(),
content: z.string(),
}),
output: z.object({
category: z.enum(['billing', 'technical', 'general']),
priority: z.enum(['low', 'medium', 'high']),
reason: z.string(),
}),
execute: async ({ ticketId, content }) => {
// In production, this might call a classification model or rules engine
return {
category: 'technical',
priority: 'medium',
reason: 'Customer reports a bug in the checkout flow',
};
},
});
const routeTool = defineTool({
name: 'route-ticket',
description: 'Route a classified ticket to the appropriate team',
input: z.object({
ticketId: z.string(),
category: z.string(),
priority: z.string(),
}),
output: z.object({
team: z.string(),
assignee: z.string(),
escalated: z.boolean(),
}),
execute: async ({ ticketId, category, priority }) => {
const teams = { billing: 'billing-team', technical: 'eng-team', general: 'support-team' };
return {
team: teams[category as keyof typeof teams] || 'support-team',
assignee: 'auto-assigned',
escalated: priority === 'high',
};
},
});
const agent = defineAgent({
name: 'support-triage',
description: 'Triages support tickets by classifying and routing them',
tools: [classifyTool, routeTool],
llm: createLLM({ provider: 'anthropic', model: 'claude-sonnet-4-20250514' }),
systemPrompt: `You are a support triage agent. When given a ticket:
1. Classify it by category and priority
2. Route it to the appropriate team
Always explain your reasoning.`,
maxSteps: 5,
budget: { maxCostUsd: 0.10 },
});
// Run
const result = await agent.run({
task: 'Triage ticket #1234: "My checkout page shows a 500 error when I try to pay"',
});
console.log(result.output);How it works
Tools handle the domain logic (classification, routing). The agent decides which tools to call based on the LLM's reasoning. Budget limits prevent runaway costs, and every step shows up in the trace.
Next Steps
- Research Assistant — more complex example
- Testing Agent — test this agent