以下是一些关键指标,表明您应该使用像 Claude 这样的 LLM 而非传统机器学习方法来完成分类任务:
在深入自动化之前,了解您现有的工单系统至关重要。首先调查您的支持团队目前如何处理工单路由。
请考虑以下问题:
您对人工如何处理某些案例了解得越多,就越能更好地与 Claude 协作完成任务。
一份定义明确的用户意图类别列表对于使用 Claude 准确分类支持工单至关重要。Claude 在您的系统中有效路由工单的能力与您系统类别的定义清晰程度成正比。
以下是一些用户意图类别和子类别的示例。
除了意图之外,工单路由和优先级排序还可能受到其他因素的影响,例如紧急程度、客户类型、SLA 或语言。在构建自动化路由系统时,请务必考虑其他路由标准。
与您的支持团队合作,定义明确的成功标准,并设定可衡量的基准、阈值和目标。
以下是使用 LLM 进行支持工单路由时的一些标准准则和基准:
以下是一些无论是否使用 LLM 都可能有用的常见成功标准:
模型的选择取决于成本、准确性和响应时间之间的权衡。
许多客户发现 claude-haiku-4-5-20251001 是工单路由的理想模型,因为它是 Claude 4 系列中速度最快、最具成本效益的模型,同时仍能提供出色的结果。如果您的分类问题需要深厚的专业知识或大量需要复杂推理的意图类别,您可以选择更大的 Sonnet 模型。
工单路由是一种分类任务。Claude 分析支持工单的内容,并根据问题类型、紧急程度、所需专业知识或其他相关因素将其分类到预定义的类别中。
让我们编写一个工单分类提示。我们的初始提示应包含用户请求的内容,并返回推理过程和意图。
尝试使用 Claude Console 上的提示生成器,让 Claude 为您编写初稿。
以下是一个工单路由分类提示的示例:
def classify_support_request(ticket_contents):
# 定义分类任务的提示
classification_prompt = f"""You will be acting as a customer support ticket classification system. Your task is to analyze customer support requests and output the appropriate classification intent for each request, along with your reasoning.
Here is the customer support request you need to classify:
<request>{ticket_contents}</request>
Please carefully analyze the above request to determine the customer's core intent and needs. Consider what the customer is asking for has concerns about.
First, write out your reasoning and analysis of how to classify this request inside <reasoning> tags.
Then, output the appropriate classification label for the request inside a <intent> tag. The valid intents are:
<intents>
<intent>Support, Feedback, Complaint</intent>
<intent>Order Tracking</intent>
<intent>Refund/Exchange</intent>
</intents>
A request may have ONLY ONE applicable intent. Only include the intent that is most applicable to the request.
As an example, consider the following request:
<request>Hello! I had high-speed fiber internet installed on Saturday and my installer, Kevin, was absolutely fantastic! Where can I send my positive review? Thanks for your help!</request>
Here is an example of how your output should be formatted (for the above example request):
<reasoning>The user seeks information in order to leave positive feedback.</reasoning>
<intent>Support, Feedback, Complaint</intent>
Here are a few more examples:
<examples>
<example 2>
Example 2 Input:
<request>I wanted to write and personally thank you for the compassion you showed towards my family during my father's funeral this past weekend. Your staff was so considerate and helpful throughout this whole process; it really took a load off our shoulders. The visitation brochures were beautiful. We'll never forget the kindness you showed us and we are so appreciative of how smoothly the proceedings went. Thank you, again, Amarantha Hill on behalf of the Hill Family.</request>
Example 2 Output:
<reasoning>User leaves a positive review of their experience.</reasoning>
<intent>Support, Feedback, Complaint</intent>
</example 2>
<example 3>
...
</example 8>
<example 9>
Example 9 Input:
<request>Your website keeps sending ad-popups that block the entire screen. It took me twenty minutes just to finally find the phone number to call and complain. How can I possibly access my account information with all of these popups? Can you access my account for me, since your website is broken? I need to know what the address is on file.</request>
Example 9 Output:
<reasoning>The user requests help accessing their web account information.</reasoning>
<intent>Support, Feedback, Complaint</intent>
</example 9>
Remember to always include your classification reasoning before your actual intent output. The reasoning should be enclosed in <reasoning> tags and the intent in <intent> tags. Return only the reasoning and the intent.
"""让我们分解此提示的关键组成部分:
ticket_contents 插入到 <request> 标签中。<reasoning> 标签内提供其推理和分析,然后在 <intent> 标签内提供适当的分类标签。我们希望 Claude 将其响应拆分为多个 XML 标签部分的原因是,这样我们可以使用正则表达式从输出中分别提取推理和意图。这使我们能够在工单路由工作流中创建有针对性的后续步骤,例如仅使用意图来决定将工单路由给哪个人。
如果不在测试生产环境中部署提示并运行评估,就很难知道您的提示效果如何。
让我们构建部署结构。首先定义用于封装 Claude 调用的方法签名。我们将采用已经开始编写的方法,该方法以 ticket_contents 作为输入,现在返回一个包含 reasoning 和 intent 的元组作为输出。如果您已有使用传统机器学习的自动化流程,则应遵循该方法签名。
import re
# 创建 Claude API 客户端实例
client = anthropic.Anthropic()
# 设置默认模型
DEFAULT_MODEL = "claude-haiku-4-5-20251001"
def classify_support_request(ticket_contents):
# 定义分类任务的提示
classification_prompt = f"""You will be acting as a customer support ticket classification system.
...
... The reasoning should be enclosed in <reasoning> tags and the intent in <intent> tags. Return only the reasoning and the intent.
"""
# 将提示发送到 API 以对支持请求进行分类。
message = client.messages.create(
model=DEFAULT_MODEL,
max_tokens=500,
temperature=0,
messages=[{"role": "user", "content": classification_prompt}],
stream=False,
)
reasoning_and_intent = message.content[0].text
# 使用 Python 的正则表达式库提取 `reasoning`。
reasoning_match = re.search(
r"<reasoning>(.*?)</reasoning>", reasoning_and_intent, re.DOTALL
)
reasoning = reasoning_match.group(1).strip() if reasoning_match else ""
# 同样地,也提取 `intent`。
intent_match = re.search(r"<intent>(.*?)</intent>", reasoning_and_intent, re.DOTALL)
intent = intent_match.group(1).strip() if intent_match else ""
return reasoning, intent此代码:
classify_support_request 函数,该函数接受一个 ticket_contents 字符串。classification_prompt 将 ticket_contents 发送给 Claude 进行分类。reasoning 和 intent。由于我们需要等待整个推理和意图文本生成完毕后再进行解析,因此我们设置 stream=False(默认值)。
提示通常需要经过测试和优化才能投入生产使用。要确定您的解决方案是否就绪,请根据您之前建立的成功标准和阈值来评估性能。
要运行评估,您需要测试用例。本指南的其余部分假设您已经开发了测试用例。
本指南的示例评估沿三个关键指标衡量 Claude 的性能:
根据对您重要的因素,您可能需要在其他维度上评估 Claude。
为了进行评估,我们首先必须修改我们编写的脚本,添加一个函数来比较预测意图与实际意图,并计算正确预测的百分比。我们还必须添加成本计算和时间测量功能。
import re
# 创建 Claude API 客户端实例
client = anthropic.Anthropic()
# 设置默认模型
DEFAULT_MODEL = "claude-haiku-4-5-20251001"
def classify_support_request(request, actual_intent):
# 定义分类任务的提示
classification_prompt = f"""You will be acting as a customer support ticket classification system.
...
...The reasoning should be enclosed in <reasoning> tags and the intent in <intent> tags. Return only the reasoning and the intent.
"""
message = client.messages.create(
model=DEFAULT_MODEL,
max_tokens=500,
temperature=0,
messages=[{"role": "user", "content": classification_prompt}],
)
usage = message.usage # Get the usage statistics for the API call for how many input and output tokens were used.
reasoning_and_intent = message.content[0].text
# 使用 Python 的正则表达式库提取 `reasoning`。
reasoning_match = re.search(
r"<reasoning>(.*?)</reasoning>", reasoning_and_intent, re.DOTALL
)
reasoning = reasoning_match.group(1).strip() if reasoning_match else ""
# 同样地,也提取 `intent`。
intent_match = re.search(r"<intent>(.*?)</intent>", reasoning_and_intent, re.DOTALL)
intent = intent_match.group(1).strip() if intent_match else ""
# 检查模型的预测是否正确。
correct = actual_intent.strip() == intent.strip()
# 返回 reasoning、intent、correct 和 usage。
return reasoning, intent, correct, usage让我们分解我们所做的修改:
actual_intent 添加到 classify_support_request 方法中,并设置了一个比较来评估 Claude 的意图分类是否与我们的标准意图分类相匹配。正确的评估需要明确的阈值和基准来确定什么是好的结果。上面的脚本为我们提供了准确率、响应时间和每次分类成本的运行时值,但我们仍然需要明确建立的阈值。例如:
有了这些阈值,您就可以快速、轻松地大规模判断哪种方法最适合您,并以客观的实证方式确定可能需要进行哪些更改以更好地满足您的需求。
在复杂场景中,除了标准的提示工程技术和防护栏实施策略之外,考虑其他策略来提升性能可能会有所帮助。以下是一些常见场景:
随着类别数量的增加,所需的示例数量也会增加,可能使提示变得难以管理。作为替代方案,您可以考虑使用分类器组合来实现分层分类系统。
例如,您可能有一个顶层分类器,将工单大致分类为"技术问题"、"账单问题"和"一般咨询"。然后,每个类别都可以有自己的子分类器来进一步细化分类。

优点 - 更细致和准确: 您可以为每个父路径创建不同的提示,从而实现更有针对性和特定上下文的分类。这可以提高准确性并更细致地处理客户请求。
缺点 - 延迟增加: 请注意,多个分类器可能会导致延迟增加,我们建议使用我们最快的模型 Haiku 来实现此方法。
尽管提供示例是提升性能最有效的方法,但如果支持请求高度多变,则很难在单个提示中包含足够的示例。
在这种情况下,您可以使用向量数据库从示例数据集中进行相似性搜索,并检索与给定查询最相关的示例。
这种方法在我们的分类指南中有详细说明,已被证明可以将性能从 71% 的准确率提高到 93%。
以下是 Claude 可能对工单进行错误分类的一些场景(可能还有其他特定于您情况的场景)。在这些场景中,请考虑在提示中提供明确的说明或示例,指导 Claude 应如何处理边缘案例:
正确的集成要求您就基于 Claude 的工单路由脚本如何融入更大的工单路由系统架构做出一些决策。有两种方法可以实现:
对于这两种方法中的任何一种,您都需要将脚本封装在一个服务中。方法的选择取决于您的支持工单系统提供哪些 API。
Was this page helpful?