Building an AI Agent for Ticket Routing: Four Architecture Iterations
This article walks through four architecture iterations of an AI agent built to route support tickets to the right engineers. It covers why bad routing costs more than no routing, how Model Context Protocol (MCP) connectors and low-code orchestration were used in early prototypes, why a hosted agent runtime hit network and security boundaries, and how rebuilding on self-managed cloud infrastructure solved permissions, data freshness, and observability. It ends with five practical lessons and a minimal, read-only starting point for teams attempting something similar.
1. Where It Started: A Wrong Assignment Costs More Than No Assignment
Most teams treat ticket routing as a process problem. In reality, it is an information retrieval and judgment problem. The cost of a wrong assignment is asymmetric: sending a bug to an engineer who knows the module but is currently at capacity costs a few hours of queue time; sending it to someone who has never touched the subsystem can cost days of rework and a production incident.
The traditional approach is to maintain a “module-to-owner” mapping table and have the on-call engineer look up assignments. This works for a team of ten. Once the number of modules grows into the dozens, staff turnover increases, and request types expand from bugs to technical consulting and compliance reviews, the mapping table decays quickly. It becomes legacy that nobody dares to change and nobody trusts.
My initial conclusion was that the information needed for routing decisions was already scattered across the ticket system, the code hosting platform, monitoring alerts, and chat history. What was missing was an executor that could retrieve that information on demand and weigh it. That led to the first version of the agent.
2. Version One: Connecting the Ticket System with an AI Coding Tool to Validate the Decision Path
The goal of the first version was to validate, at minimal cost, whether an agent could produce better routing suggestions than a mapping table. I used the AI coding tool I had at hand as the runtime and connected to the ticket system through a standard Model Context Protocol (MCP) connector. MCP is an open convention that lets a model discover and use external tools and data sources in a uniform way. It abstracts actions such as listing, fetching details, and posting comments into callable tool descriptions, and the model decides the call order on its own.
The input was only two things: a ticket ID and a natural language prompt. The output was a suggested owner with a rationale. The core constraint in the prompt was to gather evidence before drawing a conclusion:
You are a routing assistant. Follow these steps:1. Fetch the ticket details and extract the affected module, error signature, and report time;2. Query the commits for that module over the last 30 days and count the actual contributors;3. Query the on-call schedule and current open ticket volume;4. Output: suggested owner, backup candidate, confidence, and rationale (cite specific evidence).Do not output a person's name without evidence.
This version surfaced valuable problems. The model tended to pick “the person with the most historical commits,” which often conflicts with “the person who is currently available and has context.” Cross-system evidence gathering was also serial, so a single routing decision waited on multiple round trips and the latency was unacceptable. The conclusion was clear: the decision logic itself was viable, but placing it in an interactive coding environment made scheduled triggering difficult and made concurrency and retry impractical.
3. Version Two: Moving to a Low-Code Orchestration Framework to Make the Flow an Operable Asset
In the second version, I moved the entire pipeline into a low-code development framework and built it as an orchestrated agent. The value of low-code orchestration is not “less code.” It is making implicit flows explicit: each node is one tool call or one decision, inputs and outputs are observable, and failures can be replayed individually.
There were three key changes. First, serial evidence gathering became parallel evidence gathering: module commits, on-call load, and similar historical tickets were requested at the same time, then aggregated for the model to judge. Second, the mapping table was downgraded to retrieval results inside the prompt instead of hard-coded rules; vector search recalled similar historical tickets and their final handlers, injected as few-shot evidence. Third, I added a confidence threshold and a fallback strategy: below the threshold, the agent does not guess a person but escalates to a human with a summary of the evidence already collected.
if confidence < 0.6:route = "human_triage"payload = {evidence, candidates, missing_info}else:route = "assignee"
This version could scan for new tickets on a schedule and route them automatically, a significant improvement in operability. But a new bottleneck appeared around permissions: the orchestration framework ran in my own development environment, so the systems it could access were exactly those within my personal permission scope. That was both a security risk and a sign that it could not make decisions on behalf of the team.
4. Version Three: A Hosted Agent Runtime for Easier Operations and Tighter Boundaries
In the third version, I used a hosted agent runtime offered by a cloud provider. The value of hosting was real: session state, sandbox isolation for tool calls, logging and tracing, and concurrency scaling were all handled by the platform, so I no longer maintained a long-running process. The cost was equally real: the runtime could not reach my production network or internal data plane. The ticket system, the code hosting platform, and monitoring alerts were all outside the boundary.
I tried several workarounds: exporting data to object storage for the agent to pull, relaying requests through a message queue, and using scheduled jobs to write results back. All of them ran, but they introduced data freshness problems and security review challenges. Opening a channel so an external runtime could read internal data was nearly impossible to get approved. The takeaway from this version was a clear architectural constraint: an agent should sit close to the data and permission boundaries, not the other way around.
5. Version Four: Rebuilding on Self-Managed Cloud Close to Production Infrastructure
In the fourth version, I rebuilt the agent on the cloud platform the team runs itself, the same environment as the production infrastructure. This brought three decisive changes.
First, permissions can be narrowed. The agent runs under a controlled service identity and is granted only three minimal read permissions: reading tickets, reading code hosting metadata, and reading monitoring alerts. Write operations are limited to appending comments and setting the routing field, and all calls are logged and auditable. Second, there is zero data copying. No export is needed; queries run in place, so the data freshness problem disappears. Third, it can plug into the existing observability stack, with metrics, logs, and traces collected in a unified way.
When implementing this on Baidu AI Cloud, I used only general capability categories: a container platform to host the agent runtime and guarantee elastic scaling; object storage to hold prompt templates, retrieval indexes, and historical decision samples; a message queue to receive ticket creation events and handle peak shaving and retries; logging and monitoring services for call chain tracing and threshold alerts; and centralized key and configuration management for credentials, avoiding any hard-coding.
The core decision logic can be abstracted as:
def decide(ticket):features = extract(ticket) # module, error signature, urgencyhistory = vector_search(features, k=8) # similar historical tickets and final handlersload = query_workload(candidates) # current open volume and on-call statusprompt = render(TEMPLATE, features, history, load)result = model.invoke(prompt, tools=[read_only_tools])if result.confidence < THRESHOLD:return escalate(result.evidence) # escalate to a human with evidencereturn assign(result.assignee, result.reason)
6. Five Lessons from Four Iterations
First, the upper limit of an agent’s value is determined by the reachability of tools and data, not by model capability. Second, hosted versus self-managed is not a question of better or worse but of boundaries: the closer you get to the data plane, the more you need to self-manage. Third, observability must be designed on day one; otherwise you cannot answer “why did it route this way.” Fourth, confidence thresholds and fallback paths are prerequisites for production use; it is better to escalate to a human than to guess wrong silently. Fifth, and most important: an agent is like a mirror. It exposes the team’s real information flow, ambiguous ownership, and missing documentation. When it repeatedly returns low confidence for a certain class of tickets, the problem is usually not the model but the fact that the team never defined that responsibility.
If you are about to attempt something similar, start with a minimal closed loop that is read-only, rollback-friendly, and has a fallback. Run it in shadow mode alongside humans for a while, use agreement rate rather than accuracy as the acceptance metric for the first version, and then gradually open up write permissions.
