Skip to content
Learn Agentic AI
Learn Agentic AI11 min read2 views

Ticket Classification with AI Agents: Auto-Routing Support Requests

Implement an AI-powered ticket classification system that automatically assigns priority, department, and SLA to incoming support requests using multi-label classification and intelligent routing rules.

The Cost of Misrouted Tickets

When a billing question lands in the engineering queue, two things happen: the engineer wastes time reading something they cannot act on, and the customer waits an extra cycle for re-routing. Studies show that misrouted tickets add an average of 4.2 hours to resolution time. At scale, this translates to millions in wasted labor and measurably lower customer satisfaction.

AI-powered ticket classification eliminates this bottleneck by analyzing the ticket content, assigning labels, priority, and department in under a second, and routing it to the right team before any human touches it.

Multi-Label Classification Model

Support tickets rarely fit a single category. A message like "My payment failed and now I can't access my account" spans both billing and technical access. The classifier must support multi-label output.

flowchart TD
    START["Ticket Classification with AI Agents: Auto-Routin…"] --> A
    A["The Cost of Misrouted Tickets"]
    A --> B
    B["Multi-Label Classification Model"]
    B --> C
    C["SLA Assignment Engine"]
    C --> D
    D["Routing Engine"]
    D --> E
    E["Putting It All Together"]
    E --> F
    F["FAQ"]
    F --> DONE["Key Takeaways"]
    style START fill:#4f46e5,stroke:#4338ca,color:#fff
    style DONE fill:#059669,stroke:#047857,color:#fff
from dataclasses import dataclass
from openai import AsyncOpenAI
import json

DEPARTMENTS = [
    "billing", "technical", "shipping",
    "account", "product", "legal"
]
PRIORITIES = ["low", "medium", "high", "urgent"]

@dataclass
class TicketClassification:
    departments: list[str]
    primary_department: str
    priority: str
    sla_hours: int
    confidence: float
    reasoning: str

CLASSIFICATION_PROMPT = """Analyze this support ticket and return a JSON object:
{
  "departments": ["list of relevant departments"],
  "primary_department": "the single most relevant department",
  "priority": "low|medium|high|urgent",
  "confidence": 0.0-1.0,
  "reasoning": "brief explanation"
}

Departments: billing, technical, shipping, account, product, legal
Priority rules:
- urgent: service outage, security breach, legal threat
- high: payment failure, account locked, data loss
- medium: feature questions, general complaints
- low: feedback, feature requests, general inquiries

Ticket: {ticket_text}"""

async def classify_ticket(
    client: AsyncOpenAI, ticket_text: str
) -> TicketClassification:
    response = await client.chat.completions.create(
        model="gpt-4o-mini",
        messages=[
            {
                "role": "system",
                "content": "You are a support ticket classifier. Return valid JSON only.",
            },
            {
                "role": "user",
                "content": CLASSIFICATION_PROMPT.format(
                    ticket_text=ticket_text
                ),
            },
        ],
        response_format={"type": "json_object"},
        max_tokens=200,
    )
    data = json.loads(response.choices[0].message.content)
    sla = compute_sla(data["priority"])
    return TicketClassification(
        departments=data["departments"],
        primary_department=data["primary_department"],
        priority=data["priority"],
        sla_hours=sla,
        confidence=data["confidence"],
        reasoning=data["reasoning"],
    )

SLA Assignment Engine

SLA deadlines are computed from the priority level and department. Urgent billing tickets get a 1-hour SLA, while low-priority feedback might have a 72-hour window.

SLA_MATRIX = {
    ("urgent", "billing"): 1,
    ("urgent", "technical"): 2,
    ("urgent", "account"): 1,
    ("urgent", "shipping"): 4,
    ("urgent", "legal"): 2,
    ("high", "billing"): 4,
    ("high", "technical"): 4,
    ("high", "account"): 4,
    ("high", "shipping"): 8,
    ("medium", "billing"): 12,
    ("medium", "technical"): 12,
    ("medium", "shipping"): 24,
    ("low", "billing"): 48,
    ("low", "technical"): 48,
    ("low", "shipping"): 72,
}

def compute_sla(priority: str, department: str = "technical") -> int:
    return SLA_MATRIX.get(
        (priority, department),
        {"urgent": 2, "high": 8, "medium": 24, "low": 72}[priority],
    )

Routing Engine

The routing engine maps classifications to specific teams and agents. It considers agent availability, current workload, and skill matching.

See AI Voice Agents Handle Real Calls

Book a free demo or calculate how much you can save with AI voice automation.

from typing import Optional

@dataclass
class Agent:
    id: str
    name: str
    department: str
    skills: list[str]
    current_load: int
    max_load: int

@dataclass
class RoutingDecision:
    assigned_agent: Optional[Agent]
    queue: str
    sla_hours: int
    priority: str
    tags: list[str]

class TicketRouter:
    def __init__(self, agents: list[Agent]):
        self.agents = agents

    def find_best_agent(
        self, department: str, required_skills: list[str]
    ) -> Optional[Agent]:
        candidates = [
            a for a in self.agents
            if a.department == department
            and a.current_load < a.max_load
        ]
        if required_skills:
            skilled = [
                a for a in candidates
                if any(s in a.skills for s in required_skills)
            ]
            if skilled:
                candidates = skilled

        if not candidates:
            return None
        # Assign to agent with lowest current load
        return min(candidates, key=lambda a: a.current_load)

    def route(self, classification: TicketClassification) -> RoutingDecision:
        agent = self.find_best_agent(
            classification.primary_department,
            classification.departments,
        )
        queue = (
            f"{classification.primary_department}-"
            f"{classification.priority}"
        )
        return RoutingDecision(
            assigned_agent=agent,
            queue=queue,
            sla_hours=classification.sla_hours,
            priority=classification.priority,
            tags=classification.departments,
        )

Putting It All Together

The complete pipeline classifies, assigns SLA, and routes in a single async call.

async def process_new_ticket(
    client: AsyncOpenAI,
    router: TicketRouter,
    ticket_text: str,
    ticket_id: str,
) -> dict:
    classification = await classify_ticket(client, ticket_text)
    routing = router.route(classification)

    return {
        "ticket_id": ticket_id,
        "classification": classification,
        "routing": routing,
        "auto_routed": routing.assigned_agent is not None,
    }

FAQ

How accurate does ticket classification need to be before deploying?

Aim for 90%+ accuracy on your top five ticket categories before going live. Below that, misrouting causes more frustration than manual triage. Start by running the classifier in shadow mode — it classifies every ticket but a human still routes. Compare results for two weeks before switching to auto-routing.

How do I handle tickets that span multiple departments?

Assign the ticket to the primary department but tag all relevant departments. The primary department agent resolves their portion and can transfer to secondary departments. This avoids the ticket sitting in limbo between teams.

What happens when the classifier has low confidence?

Route low-confidence tickets (below 0.7) to a triage queue where a human reviews and classifies them. Log these cases as training data — they represent the boundary cases your classifier needs to improve on.


#TicketClassification #AutoRouting #SLAManagement #SupportAutomation #AIAgents #AgenticAI #LearnAI #AIEngineering

Share
C

Written by

CallSphere Team

Expert insights on AI voice agents and customer communication automation.

Try CallSphere AI Voice Agents

See how AI voice agents work for your industry. Live demo available -- no signup required.

Related Articles You May Like

Use Cases

Automating Client Document Collection: How AI Agents Chase Missing Tax Documents and Reduce Filing Delays

See how AI agents automate tax document collection — chasing missing W-2s, 1099s, and receipts via calls and texts to eliminate the #1 CPA bottleneck.

Use Cases

Returns and Exchanges Create Avoidable Tickets: Use Chat and Voice Agents to Pre-Handle the Workflow

Many return and exchange contacts should never become full support tickets. Learn how AI chat and voice agents automate policy checks, labels, and next steps.

Learn Agentic AI

API Design for AI Agent Tool Functions: Best Practices and Anti-Patterns

How to design tool functions that LLMs can use effectively with clear naming, enum parameters, structured responses, informative error messages, and documentation.

Learn Agentic AI

Computer Use in GPT-5.4: Building AI Agents That Navigate Desktop Applications

Technical guide to GPT-5.4's computer use capabilities for building AI agents that interact with desktop UIs, browser automation, and real-world application workflows.

Learn Agentic AI

Prompt Engineering for AI Agents: System Prompts, Tool Descriptions, and Few-Shot Patterns

Agent-specific prompt engineering techniques: crafting effective system prompts, writing clear tool descriptions for function calling, and few-shot examples that improve complex task performance.

Learn Agentic AI

AI Agents for IT Helpdesk: L1 Automation, Ticket Routing, and Knowledge Base Integration

Build IT helpdesk AI agents with multi-agent architecture for triage, device, network, and security issues. RAG-powered knowledge base, automated ticket creation, routing, and escalation.