Skip to main content

CS Team Agent

The CS (Customer Success) Team Agent is responsible for handling customer inquiries, automatically generating FAQs, analyzing customer sentiment, and determining escalations. It improves CSAT (Customer Satisfaction Score) through fast and consistent customer responses.

CS Agent Implementationโ€‹

// src/agents/cs.ts
import { query } from "@anthropic-ai/claude-agent-sdk";
import { AgentResponse } from "../shared/types";
import { extractText, log } from "../shared/utils";

const CS_SYSTEM_PROMPT = `You are a highly empathetic Customer Success expert.
First acknowledge the customer's feelings, and provide clear, actionable solutions.
Explain technical concepts simply so non-experts can understand them.
If escalation is needed, connect to the appropriate team without delay.
Always respond in a friendly and professional manner, avoiding excessive repetition of apologies.`;

export async function runCSAgent(task: string): Promise<AgentResponse> {
log("CS", `Task start: ${task.slice(0, 40)}...`);

// Run sentiment analysis first
const sentiment = await analyzeSentiment(task);
const needsEscalation = sentiment === "very_negative" ||
task.includes("refund") ||
task.includes("legal") ||
task.includes("press");

const response = await query({
prompt: `${CS_SYSTEM_PROMPT}

Customer sentiment state: ${sentiment}
Needs escalation: ${needsEscalation ? "Yes" : "No"}

---

${task}`,
options: {
maxTurns: 8,
tools: ["Read", "Write"]
}
});

const result = extractText(response);
log("CS", `Task complete (Escalation: ${needsEscalation})`);

return {
department: "cs",
result,
confidence: needsEscalation ? "low" : "high",
escalationNeeded: needsEscalation,
actionItems: needsEscalation ? ["Connect to CS Manager immediately"] : []
};
}

async function analyzeSentiment(
text: string
): Promise<"positive" | "neutral" | "negative" | "very_negative"> {
const response = await query({
prompt: `Analyze the sentiment state of the following customer message.
Output only one of positive/neutral/negative/very_negative.

Message: ${text}`,
options: { maxTurns: 2 }
});

const result = extractText(response).trim().toLowerCase();

if (result.includes("very_negative")) return "very_negative";
if (result.includes("negative")) return "negative";
if (result.includes("positive")) return "positive";
return "neutral";
}

Main CS Workflowsโ€‹

1. Automated Customer Inquiry Responseโ€‹

Customer Inquiry:
"Hello, I was issued an API key but I keep getting a 401 error.
I need to prepare a demo urgently and this is very frustrating."

CS Agent Response:
"I can imagine your frustration. It must be very disconcerting to encounter this situation while preparing for a demo.

Let's resolve this quickly!

Please check the most common causes for a 401 error:

1. Check API Key Format
Authorization: Bearer sk-ant-xxxxx
โ† There must be a space after 'Bearer '

2. Check Key Permissions
Dashboard > API Keys > Verify that the permission for the key is 'Active'

3. Check Environment Variables
Ensure you are using the same key in your .env file and actual code

If the issue persists after trying the above, please try issuing a new key.
When is your demo time? We will help you get it resolved before then."

2. Automated FAQ Generationโ€‹

async function generateFAQ(
ticketHistory: string[],
topN: number = 20
) {
return runCSAgent(
`Extract the top ${topN} frequently asked questions from the following customer support ticket history and write an FAQ document.

Ticket History:
${ticketHistory.join("\n\n")}

FAQ Format:
## [Category]
**Q: Question**
A: Answer (Including step-by-step solutions)

Categories: Installation/Setup, API Integration, Billing/Subscription, Data/Security, Others`
);
}

3. Customer VOC Analysisโ€‹

async function analyzeVOC(
feedbacks: string[],
period: string
) {
return runCSAgent(
`Analyze customer feedback for the ${period} period and derive insights.

Feedback Data:
${feedbacks.join("\n")}

Analysis Items:
1. Main themes of positive feedback (Strengths to maintain)
2. Main issues in negative feedback (Improvement priorities)
3. Top 5 feature request frequencies
4. Churn risk signal patterns
5. 3 immediately improvable UX issues
6. Core insights to deliver to the product team`
);
}

4. Escalation Determination Logicโ€‹

interface EscalationRule {
condition: (text: string) => boolean;
target: string;
priority: "urgent" | "high" | "normal";
}

const ESCALATION_RULES: EscalationRule[] = [
{
condition: (t) => t.includes("refund") || t.includes("cancel"),
target: "CS Manager",
priority: "high"
},
{
condition: (t) => t.includes("legal") || t.includes("lawsuit") || t.includes("lawyer"),
target: "Legal Team",
priority: "urgent"
},
{
condition: (t) => t.includes("data leak") || t.includes("personal information"),
target: "Security Team + Legal Team",
priority: "urgent"
},
{
condition: (t) => t.includes("press") || t.includes("article"),
target: "PR Team + Executives",
priority: "urgent"
}
];

function checkEscalation(text: string) {
for (const rule of ESCALATION_RULES) {
if (rule.condition(text)) {
return { shouldEscalate: true, ...rule };
}
}
return { shouldEscalate: false };
}

CSAT Monitoring Automationโ€‹

// Analyze daily CSAT status and detect anomalies
async function dailyCSATMonitor(csatData: string) {
const analysis = await runCSAgent(
`Analyze today's CSAT data.

CSAT Data:
${csatData}

Analysis:
- Today's average CSAT score vs 7-day average
- Common patterns in low-score (3 or below) tickets
- Recurring issues with specific agents or issue types
- List of customers needing immediate follow-up`
);

// Alert CS Team Lead if CSAT drops below 3.0
if (analysis.result.includes("below 3.0") ||
analysis.result.includes("plummeted")) {
await alertCSManager(analysis.result);
}

return analysis;
}
CS Agent Usage Tips
  • Include product documentation and release notes in the system prompt to guarantee accurate answers.
  • Adjust prompts to respond with a more empathetic tone when negative sentiment is detected.
  • Construct a loop that automatically adds recurring inquiries to the FAQ.