Support Reply Generator

Generate contextual support responses by analyzing ticket history and knowledge base.

This workflow retrieves relevant documentation, analyzes conversation history, and drafts personalized responses.

Implementation

1import { relay } from "@relayplane/workflows";
2
3const result = await relay
4 .workflow("support-reply-generator")
5
6 // Step 1: Search knowledge base for relevant articles
7 .step("search-kb")
8 .with("openai:gpt-4o")
9 .prompt(`Given this support ticket, identify the most relevant help articles:
10
11Current Message: {{currentMessage}}
12Previous Messages: {{conversationHistory}}
13
14Our knowledge base categories:
15- Getting Started
16- API Documentation
17- Billing & Plans
18- Troubleshooting
19- Integrations
20
21Return top 3 most relevant article titles and why they're relevant.`)
22
23 // Step 2: Analyze customer sentiment and issue severity
24 .step("analyze-context")
25 .with("anthropic:claude-3.5-sonnet")
26 .depends("search-kb")
27 .prompt(`Analyze this support conversation:
28
29History: {{conversationHistory}}
30Latest: {{currentMessage}}
31
32Assess:
33- Customer sentiment and frustration level
34- Issue severity (blocker vs nice-to-have)
35- How many times they've asked similar question
36- Whether they're a churning risk
37
38Relevant KB Articles: {{search-kb.output}}`)
39
40 // Step 3: Draft personalized response
41 .step("draft-reply")
42 .with("anthropic:claude-3.5-sonnet")
43 .depends("search-kb", "analyze-context")
44 .prompt(`Draft a support response:
45
46Context Analysis: {{analyze-context.output}}
47Relevant Articles: {{search-kb.output}}
48
49Customer Message: {{currentMessage}}
50Customer Name: {{customerName}}
51
52Requirements:
53- Address their specific question directly
54- Reference conversation history if they're repeating
55- Link to 1-2 most relevant help articles
56- Match tone to their sentiment (extra empathy if frustrated)
57- Provide code examples if technical
58- End with "anything else?" to encourage resolution
59
60Maximum 250 words.`)
61
62 .run({
63 currentMessage: ticket.latestMessage,
64 conversationHistory: ticket.previousMessages.join("\n\n"),
65 customerName: ticket.customer.name,
66 });
67
68console.log("Draft Reply:", result.steps["draft-reply"].output);
69console.log("Sentiment:", result.steps["analyze-context"].output);

For production use, replace the search-kb step with vector similarity search:

1import { relay } from "@relayplane/workflows";
2import { searchDocs } from "./vector-db";
3
4// Pre-process: Get relevant docs from vector DB
5const relevantDocs = await searchDocs(ticket.latestMessage, {
6 limit: 5,
7 threshold: 0.7,
8});
9
10const result = await relay
11 .workflow("support-reply-generator")
12 .step("draft-reply")
13 .with("anthropic:claude-3.5-sonnet")
14 .prompt(`Draft a support response using these relevant docs:
15
16{{relevantDocs}}
17
18Customer question: {{currentMessage}}
19Tone: {{sentiment}}`)
20 .run({
21 relevantDocs: relevantDocs.map(d => d.content).join("\n\n"),
22 currentMessage: ticket.latestMessage,
23 sentiment: "empathetic",
24 });

Quality Metrics

  • Response time: Under 5 seconds
  • Accuracy: 80%+ responses require minimal editing
  • Customer satisfaction: 4.5/5 average rating
  • Agent productivity: 3x more tickets handled per day