How to Build an AI First-Response Generator for Tickets
Generate first responses to support tickets instantly using AI.
Jay Banlasan
The AI Systems Guy
An ai first response generator for support tickets cuts your first response time from hours to seconds. I build these for teams where the initial reply is usually a template anyway. The AI reads the ticket, pulls from your knowledge base, and drafts a personalized response that either solves the issue or asks the right follow-up question.
Agents review and send. They do not start from blank.
What You Need Before Starting
- A ticketing system with API access
- Your knowledge base or FAQ content
- Python 3.8+ with the Anthropic SDK
- Historical resolved tickets for quality reference
Step 1: Load Your Knowledge Base
Structure your support content so the AI can reference it:
import json
def load_knowledge_base():
with open("support_kb.json") as f:
articles = json.load(f)
return "\n\n".join([
f"Topic: {a['title']}\nAnswer: {a['content']}"
for a in articles
])
Step 2: Build the Response Generator
import anthropic
client = anthropic.Anthropic()
SYSTEM_PROMPT = """You are drafting a first response to a support ticket for [Your Company].
Rules:
- Address the customer by name if available
- Directly answer their question if the knowledge base has the answer
- If you need more info, ask ONE specific clarifying question
- Keep responses under 200 words
- Professional but warm tone
- Never make up information not in the knowledge base
- End with a clear next step
KNOWLEDGE BASE:
{kb}"""
def generate_first_response(ticket):
kb = load_knowledge_base()
response = client.messages.create(
model="claude-sonnet-4-20250514",
max_tokens=400,
system=SYSTEM_PROMPT.format(kb=kb),
messages=[{
"role": "user",
"content": f"""Generate a first response for this ticket:
Customer: {ticket.get('customer_name', 'Customer')}
Subject: {ticket['subject']}
Message: {ticket['body']}"""
}]
)
return response.content[0].text
Step 3: Auto-Draft on New Tickets
Hook into your ticketing system webhook:
from flask import Flask, request, jsonify
app = Flask(__name__)
@app.route("/new-ticket", methods=["POST"])
def new_ticket():
ticket = request.json
draft = generate_first_response(ticket)
save_draft(ticket["id"], draft)
return jsonify({
"ticket_id": ticket["id"],
"draft": draft,
"status": "draft_ready"
})
Step 4: Let Agents Review and Edit
Present drafts in a simple review interface. The agent can approve, edit, or reject:
@app.route("/review-draft/<ticket_id>", methods=["POST"])
def review_draft(ticket_id):
action = request.json["action"] # approve, edit, reject
if action == "approve":
draft = get_draft(ticket_id)
send_reply(ticket_id, draft)
log_review(ticket_id, "approved", draft)
elif action == "edit":
edited = request.json["edited_text"]
send_reply(ticket_id, edited)
log_review(ticket_id, "edited", edited)
elif action == "reject":
log_review(ticket_id, "rejected", get_draft(ticket_id))
return jsonify({"status": "processed"})
Step 5: Track Approval Rates
Measure how often agents approve vs edit to gauge quality:
def get_quality_metrics():
conn = sqlite3.connect("drafts.db")
stats = conn.execute("""
SELECT action, COUNT(*) as count
FROM draft_reviews
WHERE reviewed_at > datetime('now', '-7 days')
GROUP BY action
""").fetchall()
total = sum(s[1] for s in stats)
approved = next((s[1] for s in stats if s[0] == "approved"), 0)
return {
"total_drafts": total,
"auto_approved": approved,
"approval_rate": round(approved / total * 100, 1) if total else 0
}
What to Build Next
For tickets with a 90%+ approval rate pattern (like password reset requests), switch to auto-send. The agent reviews after instead of before. That is where the real time savings stack up.
Related Reading
- AI in Customer Service - first response automation in the full support picture
- AI-Powered Reporting That Actually Gets Read - reporting on response quality and speed
- Minimum Viable Automation - start with drafts, graduate to auto-send
Want this system built for your business?
Get a free assessment. We will map every system your business needs and show you the ROI.
Get Your Free Assessment