客户支持代理

本指南介绍如何利用 Claude 先进的对话能力实时处理客户咨询,提供 7x24 小时支持,减少等待时间,并以准确的回复和积极的互动管理高支持量。


使用 Claude 构建之前

决定是否使用 Claude 进行支持聊天

以下是一些关键指标,表明您应该使用像 Claude 这样的 LLM 来自动化客户支持流程的部分环节:

大量重复性查询

Claude 擅长高效处理大量类似问题,让人工客服专注于更复杂的问题。

需要快速信息整合

Claude 可以快速检索、处理和组合来自庞大知识库的信息,而人工客服可能需要时间来研究或咨询多个来源。

7x24 小时可用性需求

Claude 可以提供全天候支持而不会疲劳,而安排人工客服提供持续覆盖可能成本高昂且具有挑战性。

高峰期快速扩展

Claude 可以处理查询量的突然增加,无需雇用和培训额外的员工。

一致的品牌声音

您可以指示 Claude 一致地代表您品牌的语气和价值观,而人工客服的沟通风格可能各不相同。

选择 Claude 而非其他 LLM 的一些考虑因素:

  • 您优先考虑自然、细致的对话:Claude 复杂的语言理解能力可以实现更自然、上下文感知的对话,比与其他 LLM 的聊天更像人类。
  • 您经常收到复杂和开放式查询:Claude 可以处理广泛的主题和查询,而无需生成预设回复或对用户话语的排列进行大量编程。
  • 您需要可扩展的多语言支持:Claude 的多语言能力使其能够以超过 200 种语言进行对话,无需为每种支持的语言维护单独的聊天机器人或进行大量翻译流程。

定义理想的聊天交互

概述理想的客户交互,以定义您期望客户何时以及如何与 Claude 交互。此概述将帮助确定解决方案的技术要求。

以下是汽车保险客户支持的示例聊天交互:

  • 客户: 发起支持聊天体验
    • Claude: 热情问候客户并发起对话
  • 客户: 询问关于新电动汽车的保险
    • Claude: 提供关于电动车保险覆盖的相关信息
  • 客户: 询问与电动车保险独特需求相关的问题
    • Claude: 以准确且信息丰富的回复回答,并提供来源链接
  • 客户: 询问与保险或汽车无关的话题外问题
    • Claude: 澄清不讨论无关话题,并将用户引导回汽车保险主题
  • 客户: 表示对保险报价感兴趣
    • Claude: 询问一系列问题以确定适当的报价,并根据客户的回复进行调整
    • Claude: 向报价生成 API 工具发送请求,附带从用户收集的必要信息
    • Claude: 从 API 工具使用中接收响应信息,将信息整合为自然回复,并向用户呈现提供的报价
  • 客户: 询问后续问题
    • Claude: 根据需要回答后续问题
    • Claude: 引导客户进入保险流程的后续步骤并结束对话
Tip
在您为自己用例编写的实际示例中,您可能会发现写出此交互中的实际对话很有用,这样您也可以了解 Claude 理想的语气、响应长度和详细程度。

将交互分解为独立任务

客户支持聊天是多个不同任务的集合,从问答到信息检索再到执行请求操作,都包含在一次客户交互中。在开始构建之前,将理想的客户交互分解为您希望 Claude 能够执行的每个任务。这确保您可以针对每个任务提示和评估 Claude,并让您很好地了解编写测试用例时需要考虑的交互范围。

Tip
客户有时发现将其可视化为根据用户请求的可能对话转折点的交互流程图很有帮助。

以下是与上面示例保险交互相关的关键任务:

  1. 问候和一般指导

    • 热情问候客户并发起对话
    • 提供关于公司和交互的一般信息
  2. 产品信息

    • 提供关于电动车保险覆盖的信息
      Note
      这将要求 Claude 的上下文中包含必要的信息,可能意味着需要 RAG 集成
    • 回答与电动车保险独特需求相关的问题
    • 回答关于报价或保险详情的后续问题
    • 在适当时提供来源链接
  3. 对话管理

    • 保持话题(汽车保险)
    • 将话题外问题引导回相关主题
  4. 报价生成

    • 询问适当的问题以确定报价资格
    • 根据客户回复调整问题
    • 将收集的信息提交给报价生成 API
    • 向客户呈现提供的报价

建立成功标准

与您的支持团队合作,定义成功标准并编写详细评估,包括可衡量的基准和目标。

以下是可以用来评估 Claude 执行定义任务成功程度的标准和基准:

查询理解准确性

此指标评估 Claude 对各种主题客户查询的理解准确性。通过审查对话样本并评估 Claude 是否正确解释了客户意图、关键后续步骤、成功解决方案的样子等来衡量。目标是理解准确率达到 95% 或更高。

响应相关性

此指标评估 Claude 的回复对客户特定问题或疑虑的解决程度。评估一组对话并为每个回复的相关性打分(使用基于 LLM 的评分进行规模化)。目标是相关性得分达到 90% 或以上。

响应准确性

评估提供给用户的一般公司和产品信息的正确性,基于在上下文中提供给 Claude 的信息。目标是此类介绍性信息的准确率达到 100%。

引用提供的相关性

跟踪所提供链接或来源的频率和相关性。目标是在 80% 的交互中提供相关来源(在提供额外信息可能有益的情况下)。

话题坚持度

衡量 Claude 保持话题的能力,例如示例实现中的汽车保险话题。目标是 95% 的回复与汽车保险或客户的特定查询直接相关。

内容生成效果

衡量 Claude 在决定何时生成信息内容以及该内容相关性方面的成功程度。例如,在此实现中,您将确定 Claude 对何时生成报价的理解程度以及该报价的准确性。目标是 100% 准确率,因为这是成功客户互动的关键信息。

升级效率

此指标衡量 Claude 识别查询何时需要人工干预并适当升级的能力。跟踪正确升级的对话与应该升级但未升级的对话的百分比。目标是升级准确率达到 95% 或更高。

以下是可以用来评估使用 Claude 进行支持的业务影响的标准和基准:

情感维护

此指标评估 Claude 在整个对话中维持或改善客户情感的能力。使用情感分析工具衡量每次对话开始和结束时的情感。目标是在 90% 的交互中维持或改善情感。

偏转率

聊天机器人在无人工干预的情况下成功处理的客户查询百分比。通常目标是 70-80% 的偏转率,具体取决于查询的复杂性。

客户满意度评分

衡量客户对其聊天机器人交互满意度的指标。通常通过交互后调查完成。目标是 CSAT 评分达到 4 分(满分 5 分)或更高。

平均处理时间

聊天机器人解决查询所需的平均时间。这因问题的复杂性而差异很大,但通常目标是比人工客服更低的 AHT。

如何将 Claude 实现为客户服务代理

选择合适的 Claude 模型

模型的选择取决于成本、准确性和响应时间之间的权衡。

对于客户支持聊天,Claude Opus 4.7 非常适合平衡智能、延迟和成本。但是,如果您的对话流程包含多个提示词(包括 RAG、工具使用和/或长上下文提示词),Claude Haiku 4.5 可能更适合优化延迟。

构建强大的提示词

使用 Claude 进行客户支持需要 Claude 拥有足够的指导和上下文来适当地响应,同时有足够的灵活性来处理各种客户查询。

首先编写强大提示词的要素,从系统提示词开始:

IDENTITY = """You are Eva, a friendly and knowledgeable AI assistant for Acme Insurance
Company. Your role is to warmly welcome customers and provide information on
Acme's insurance offerings, which include car insurance and electric car
insurance. You can also help customers get quotes for their insurance needs."""
Tip
虽然您可能倾向于将所有信息放在系统提示词中,以此将指令与用户对话分开,但 Claude 实际上在将大部分提示词内容写在第一个 User 轮次中时效果最好(唯一的例外是角色提示)。更多信息请阅读使用系统提示词赋予 Claude 角色

最好将复杂的提示词分解为子部分,一次编写一个部分。对于每个任务,您可能会发现通过逐步过程来定义 Claude 执行任务所需的提示词部分会取得更大的成功。对于这个汽车保险客户支持示例,您将从"问候和一般指导"任务开始,逐步编写提示词的所有部分。这也使调试提示词更容易,因为您可以更快地调整整体提示词的各个部分。

将所有这些部分放在一个名为 config.py 的文件中。

STATIC_GREETINGS_AND_GENERAL = """
<static_context>
Acme Auto Insurance: Your Trusted Companion on the Road

About:
At Acme Insurance, we understand that your vehicle is more than just a mode of transportation—it's your ticket to life's adventures.
Since 1985, we've been crafting auto insurance policies that give drivers the confidence to explore, commute, and travel with peace of mind.
Whether you're navigating city streets or embarking on cross-country road trips, Acme is there to protect you and your vehicle.
Our innovative auto insurance policies are designed to adapt to your unique needs, covering everything from fender benders to major collisions.
With Acme's award-winning customer service and swift claim resolution, you can focus on the joy of driving while we handle the rest.
We're not just an insurance provider—we're your co-pilot in life's journeys.
Choose Acme Auto Insurance and experience the assurance that comes with superior coverage and genuine care. Because at Acme, we don't just
insure your car—we fuel your adventures on the open road.

Note: We also offer specialized coverage for electric vehicles, ensuring that drivers of all car types can benefit from our protection.

Acme Insurance offers the following products:
- Car insurance
- Electric car insurance
- Two-wheeler insurance

Business hours: Monday-Friday, 9 AM - 5 PM EST
Customer service number: 1-800-123-4567
</static_context>
"""

然后为您的汽车保险和电动车保险信息做同样的事情。

STATIC_CAR_INSURANCE = """
<static_context>
Car Insurance Coverage:
Acme's car insurance policies typically cover:
1. Liability coverage: Pays for bodily injury and property damage you cause to others.
2. Collision coverage: Pays for damage to your car in an accident.
3. Comprehensive coverage: Pays for damage to your car from non-collision incidents.
4. Medical payments coverage: Pays for medical expenses after an accident.
5. Uninsured/underinsured motorist coverage: Protects you if you're hit by a driver with insufficient insurance.

Optional coverages include:
- Rental car reimbursement
- Roadside assistance
- New car replacement
</static_context>
"""

STATIC_ELECTRIC_CAR_INSURANCE = """
<static_context>
Electric Car Insurance:
Our specialized electric car insurance goes beyond traditional auto coverage,
offering tailored protection for your high-tech investment. In addition to standard coverages, we offer:
- Safeguarding expensive battery systems
- Covering home charging equipment
- Adapting to the rapidly evolving world of electric vehicles

Whether you're driving a Rivian, Nissan Leaf, Chevrolet Bolt,
or any other electric vehicle, our knowledgeable agents are ready to craft a policy
that gives you the confidence to enjoy every electron-powered mile.
</static_context>
"""

现在您有了静态内容,添加至少 4-5 个示例"良好"交互来引导 Claude 的回复。这些示例应代表您理想的客户交互,可以包括护栏、工具调用等。

EXAMPLES = """
Here are a few examples of how you can interact with customers:

<example 1>
H: Hi, do you offer commercial insurance for small businesses?

A: Ah! Unfortunately, we don't offer commercial insurance at this time.
However, we do provide a range of personal insurance products including car insurance and electric car insurance.
Would you like to know more about these offerings?
</example 1>

<example 2>
H: Hi, what are your business hours?

A: Our business hours are Monday to Friday, 9 AM to 5 PM EST.
If you have any questions or need assistance, feel free to reach out during those times.
How else can I assist you today?
</example 2>

<example 3>
H: I'm shopping for car insurance. What does Acme offer?

A: Great choice! Acme's car insurance policies typically include:
- Liability coverage: Protects you if you're at fault in an accident
- Collision coverage: Pays for damage to your car in an accident
- Comprehensive coverage: Covers non-collision incidents like theft or vandalism
- Medical payments coverage: Pays for medical expenses after an accident
- Uninsured/underinsured motorist coverage: Protects you from drivers with insufficient insurance

We also offer optional coverages like rental car reimbursement, roadside assistance, and new car replacement.
Would you like more details on any of these coverages, or do you have specific questions about insuring your vehicle?
</example 3>

<example 4>
H: I'd like to hear about your electric car insurance.

A: Certainly! Our electric car insurance is specially designed to meet the unique needs of electric vehicle owners.
In addition to all the standard coverages we offer for regular cars, our electric car policies include:

- Battery coverage: Protection against damage or degradation of your vehicle's expensive battery system
- Tech package: Covers repairs or replacement of advanced electronics and onboard computer systems
- Charging station coverage: Protects both home and portable charging equipment
- Cybersecurity protection: Coverage against hacking or digital threats
- Specialized roadside assistance: Includes flatbed towing to protect the vehicle's undercarriage

We cover a wide range of electric vehicles, including popular models from Tesla, Rivian, Nissan, Chevrolet, and more.
Is there a specific electric vehicle you're looking to insure, or would you like more details on any of these coverages?
</example 4>

<example 5>
H: I'd like to get a quote for my car insurance.

A: Certainly! I'd be happy to help you get a quote for your car insurance.
To provide you with an accurate quote, I'll need to collect some information about your vehicle and the primary driver.
Let's start with the basics:

1. What is the make and model of your vehicle?
2. What year was it manufactured?
3. Approximately how many miles have you driven?
4. What is the age of the primary driver?

Once you provide this information, I'll use our quoting tool to generate a personalized insurance quote for you.
</example 5>
"""

您还需要包含任何重要的指令,概述 Claude 应如何与客户交互的注意事项。 这些内容可能来自品牌护栏或支持政策。

ADDITIONAL_GUARDRAILS = """Please adhere to the following guardrails:
1. Only provide information about insurance types listed in our offerings.
2. If asked about an insurance type we don't offer, politely state
that we don't provide that service.
3. Do not speculate about future product offerings or company plans.
4. Don't make promises or enter into agreements it's not authorized to make.
You only provide information and guidance.
5. Do not mention any competitor's products or services.
"""

现在将所有这些部分组合成一个字符串作为您的提示词。

TASK_SPECIFIC_INSTRUCTIONS = " ".join(
    [
        STATIC_GREETINGS_AND_GENERAL,
        STATIC_CAR_INSURANCE,
        STATIC_ELECTRIC_CAR_INSURANCE,
        EXAMPLES,
        ADDITIONAL_GUARDRAILS,
    ]
)

使用工具使用添加动态和代理能力

Claude 能够使用客户端工具使用功能动态执行操作和检索信息。首先列出提示词应利用的任何外部工具或 API。

对于此示例,从一个计算报价的工具开始。

Tip
提醒一下,此工具不会执行实际计算,它只会向应用发出信号,表明应使用指定的参数调用工具。

示例保险报价计算器:

TOOLS = [
    {
        "name": "get_quote",
        "description": "Calculate the insurance quote based on user input. Returned value is per month premium.",
        "input_schema": {
            "type": "object",
            "properties": {
                "make": {"type": "string", "description": "The make of the vehicle."},
                "model": {"type": "string", "description": "The model of the vehicle."},
                "year": {
                    "type": "integer",
                    "description": "The year the vehicle was manufactured.",
                },
                "mileage": {
                    "type": "integer",
                    "description": "The mileage on the vehicle.",
                },
                "driver_age": {
                    "type": "integer",
                    "description": "The age of the primary driver.",
                },
            },
            "required": ["make", "model", "year", "mileage", "driver_age"],
        },
    }
]


def get_quote(make, model, year, mileage, driver_age):
    """Returns the premium per month in USD"""
    # 您可以调用 http 端点或数据库来获取报价。
    # 这里我们模拟 1 秒延迟并返回固定报价 100。
    time.sleep(1)
    return 100

部署您的提示词

如果不部署到测试生产环境并运行评估,很难知道提示词的效果如何。让我们使用提示词、Anthropic SDK 和 Streamlit 构建一个小型应用作为用户界面。

在一个名为 chatbot.py 的文件中,首先设置 ChatBot 类,它将封装与 Anthropic SDK 的交互。

该类应该有两个主要方法:generate_messageprocess_user_input

from anthropic import Anthropic
from config import IDENTITY, TOOLS, MODEL, get_quote
from dotenv import load_dotenv

load_dotenv()


class ChatBot:
    def __init__(self, session_state):
        self.anthropic = Anthropic()
        self.session_state = session_state

    def generate_message(
        self,
        messages,
        max_tokens,
    ):
        try:
            response = self.anthropic.messages.create(
                model=MODEL,
                system=IDENTITY,
                max_tokens=max_tokens,
                messages=messages,
                tools=TOOLS,
            )
            return response
        except Exception as e:
            return {"error": str(e)}

    def process_user_input(self, user_input):
        self.session_state.messages.append({"role": "user", "content": user_input})

        response_message = self.generate_message(
            messages=self.session_state.messages,
            max_tokens=2048,
        )

        if "error" in response_message:
            return f"An error occurred: {response_message['error']}"

        if response_message.content[-1].type == "tool_use":
            tool_use = response_message.content[-1]
            func_name = tool_use.name
            func_params = tool_use.input
            tool_use_id = tool_use.id

            result = self.handle_tool_use(func_name, func_params)
            self.session_state.messages.append(
                {"role": "assistant", "content": response_message.content}
            )
            self.session_state.messages.append(
                {
                    "role": "user",
                    "content": [
                        {
                            "type": "tool_result",
                            "tool_use_id": tool_use_id,
                            "content": f"{result}",
                        }
                    ],
                }
            )

            follow_up_response = self.generate_message(
                messages=self.session_state.messages,
                max_tokens=2048,
            )

            if "error" in follow_up_response:
                return f"An error occurred: {follow_up_response['error']}"

            response_text = follow_up_response.content[0].text
            self.session_state.messages.append(
                {"role": "assistant", "content": response_text}
            )
            return response_text

        elif response_message.content[0].type == "text":
            response_text = response_message.content[0].text
            self.session_state.messages.append(
                {"role": "assistant", "content": response_text}
            )
            return response_text

        else:
            raise Exception("An error occurred: Unexpected response type")

    def handle_tool_use(self, func_name, func_params):
        if func_name == "get_quote":
            premium = get_quote(**func_params)
            return f"Quote generated: ${premium:.2f} per month"

        raise Exception("An unexpected tool was used")

构建用户界面

使用 main 方法和 Streamlit 测试部署此代码。此 main() 函数设置基于 Streamlit 的聊天界面。

在一个名为 app.py 的文件中完成

import streamlit as st
from chatbot import ChatBot
from config import TASK_SPECIFIC_INSTRUCTIONS


def main():
    st.title("Chat with Eva, Acme Insurance Company's Assistant🤖")

    if "messages" not in st.session_state:
        st.session_state.messages = [
            {"role": "user", "content": TASK_SPECIFIC_INSTRUCTIONS},
            {"role": "assistant", "content": "Understood"},
        ]

    chatbot = ChatBot(st.session_state)

    # 显示用户和助手消息,跳过前两条
    for message in st.session_state.messages[2:]:
        # 忽略工具使用块
        if isinstance(message["content"], str):
            with st.chat_message(message["role"]):
                st.markdown(message["content"])

    if user_msg := st.chat_input("Type your message here..."):
        st.chat_message("user").markdown(user_msg)

        with st.chat_message("assistant"):
            with st.spinner("Eva is thinking..."):
                response_placeholder = st.empty()
                full_response = chatbot.process_user_input(user_msg)
                response_placeholder.markdown(full_response)


if __name__ == "__main__":
    main()

使用以下命令运行程序:

streamlit run app.py

评估您的提示词

提示词通常需要测试和优化才能达到生产就绪状态。要确定解决方案的就绪状态,请使用结合定量和定性方法的系统流程评估聊天机器人性能。基于您定义的成功标准创建强有力的实证评估将使您能够优化提示词。

Tip
Claude 控制台现在具有评估工具,允许您在各种场景下测试提示词。

提升性能

在复杂场景中,考虑在标准提示工程技术护栏实施策略之外的额外策略来提升性能可能会有所帮助。以下是一些常见场景:

使用 RAG 减少长上下文延迟

当处理大量静态和动态上下文时,将所有信息包含在提示词中可能导致高成本、更慢的响应时间以及达到上下文窗口限制。在这种情况下,实施检索增强生成(RAG)技术可以显著提高性能和效率。

通过使用 Voyage 等嵌入模型将信息转换为向量表示,您可以创建更具扩展性和响应性的系统。这种方法允许根据当前查询动态检索相关信息,而不是在每个提示词中包含所有可能的上下文。

在支持用例中实施 RAG 的 RAG 配方已被证明可以提高准确性、减少响应时间并降低具有大量上下文需求的系统中的 API 成本。

使用工具使用集成实时数据

当处理需要实时信息的查询(如账户余额或保单详情)时,基于嵌入的 RAG 方法是不够的。相反,您可以利用工具使用来显著增强聊天机器人提供准确实时响应的能力。例如,您可以使用工具使用来查找客户信息、检索订单详情和代表客户取消订单。

此方法在工具使用:客户服务代理配方中概述,允许您将实时数据无缝集成到 Claude 的响应中,并提供更个性化和高效的客户体验。

加强输入和输出护栏

部署聊天机器人时,特别是在客户服务场景中,防止与误用、超出范围查询和不当响应相关的风险至关重要。虽然 Claude 本身对此类场景具有韧性,但以下是加强聊天机器人护栏的一些额外步骤:

  • 减少幻觉:实施事实核查机制和引用以将响应基于提供的信息。
  • 交叉检查信息:验证代理的响应是否符合您公司的政策和已知事实。
  • 避免合同承诺:确保代理不会做出未经授权的承诺或达成协议。
  • 缓解越狱:使用无害性屏幕和输入验证等方法来防止用户利用模型漏洞生成不当内容。
  • 避免提及竞争对手:实施竞争对手提及过滤器以保持品牌焦点,不提及任何竞争对手的产品或服务。
  • 提高输出一致性:防止 Claude 改变风格或跳出角色,即使在长时间复杂的交互中也是如此。
  • 移除个人可识别信息(PII):除非明确需要并授权,否则从响应中剥离任何 PII。

使用流式传输减少感知响应时间

当处理可能较长的响应时,实施流式传输可以显著提高用户参与度和满意度。在这种情况下,用户逐步接收答案,而不是等待整个响应生成完毕。

以下是实施流式传输的方法:

  1. 使用 Anthropic 流式传输 API 支持流式响应。
  2. 设置前端以处理传入的文本块。
  3. 在每个块到达时显示,模拟实时打字。
  4. 实施机制以保存完整响应,允许用户在离开后返回时查看。

在某些情况下,流式传输使得可以使用具有更高基础延迟的更高级模型,因为渐进式显示减轻了更长处理时间的影响。

扩展您的聊天机器人

随着聊天机器人复杂性的增长,您的应用架构可以相应演进。在向架构添加更多层之前,考虑以下不太详尽的选项:

  • 确保充分利用提示词并通过提示工程进行优化。使用提示工程指南编写最有效的提示词。
  • 向提示词添加额外的工具(可以包括提示链),看看是否可以实现所需的功能。

如果您的聊天机器人处理极其多样化的任务,您可能考虑添加一个单独的意图分类器来路由初始客户查询。对于现有应用,这将涉及创建一个决策树,通过分类器路由客户查询,然后到专门的对话(带有各自的工具集和系统提示词)。请注意,此方法需要对 Claude 的额外调用,可能会增加延迟。

将 Claude 集成到您的支持工作流中

虽然上面的示例侧重于可在 Streamlit 环境中调用的 Python 函数,但部署 Claude 进行实时支持聊天机器人需要一个 API 服务。

以下是您可以采取的方法:

  1. 创建 API 包装器:围绕您的分类函数开发一个简单的 API 包装器。例如,您可以使用 Flask API 或 Fast API 将代码包装成 HTTP 服务。您的 HTTP 服务可以接受用户输入并返回完整的助手响应。因此,您的服务可以具有以下特征:

    • 服务器发送事件(SSE):SSE 允许从服务器到客户端的实时流式响应。这对于在使用 LLM 时提供流畅、交互式的体验至关重要。
    • 缓存:实施缓存可以显著提高响应时间并减少不必要的 API 调用。
    • 上下文保留:当用户离开后返回时保持上下文对于对话的连续性很重要。
  2. 构建 Web 界面:实施一个用户友好的 Web UI 来与 Claude 驱动的代理交互。