• 訊息
  • 託管代理
  • 管理

Search...
⌘K
使用案例
概覽工單路由客戶支援代理內容審核法律摘要
提示工程
概覽提示最佳實務Claude Fable 5 提示技巧Claude Opus 4.8 提示技巧Console 提示工具
測試與評估
定義成功並建構評估在 Console 中使用評估工具降低延遲
強化防護措施
減少幻覺提高輸出一致性緩解越獄減少提示洩漏
參考
詞彙表

Log in
客戶支援代理
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...

Solutions

  • AI agents
  • Code modernization
  • Coding
  • Customer support
  • Education
  • Financial services
  • Government
  • Life sciences

Partners

  • Amazon Bedrock
  • Google Cloud's Vertex AI

Learn

  • Blog
  • Courses
  • Use cases
  • Connectors
  • Customer stories
  • Engineering at Anthropic
  • Events
  • Powered by Claude
  • Service partners
  • Startups program

Company

  • Anthropic
  • Careers
  • Economic Futures
  • Research
  • News
  • Responsible Scaling Policy
  • Security and compliance
  • Transparency

Learn

  • Blog
  • Courses
  • Use cases
  • Connectors
  • Customer stories
  • Engineering at Anthropic
  • Events
  • Powered by Claude
  • Service partners
  • Startups program

Help and security

  • Availability
  • Status
  • Support
  • Discord

Terms and policies

  • Privacy policy
  • Responsible disclosure policy
  • Terms of service: Commercial
  • Terms of service: Consumer
  • Usage policy
最佳實務/使用案例

客戶支援代理

本指南將逐步說明如何運用 Claude 的進階對話能力來即時處理客戶詢問,提供全天候支援、縮短等待時間,並以準確的回應和正向的互動來管理大量的支援需求。

使用 Claude 建置之前

決定是否使用 Claude 進行支援聊天

以下是一些關鍵指標,顯示您應該採用像 Claude 這樣的 LLM 來自動化部分客戶支援流程:

選擇 Claude 而非其他 LLM 的一些考量因素:

  • 您重視自然、細膩的對話:Claude 精密的語言理解能力可實現更自然、具上下文感知的對話,比與其他 LLM 的聊天更像真人互動。
  • 您經常收到複雜且開放式的查詢:Claude 可以處理廣泛的主題和詢問,而不會產生制式回應,也不需要針對使用者話語的各種排列組合進行大量程式設計。
  • 您需要可擴展的多語言支援:Claude 的多語言能力使其能夠以超過 200 種語言進行對話,而無需為每種支援的語言建立獨立的聊天機器人或進行大量的翻譯流程。

定義您理想的聊天互動

勾勒出理想的客戶互動,以定義您期望客戶如何以及何時與 Claude 互動。此大綱將有助於確定您解決方案的技術需求。

以下是汽車保險客戶支援的聊天互動範例:

  • 客戶: 啟動支援聊天體驗
    • Claude: 親切地問候客戶並開啟對話
  • 客戶: 詢問其新電動車的保險
    • Claude: 提供有關電動車保險的相關資訊
  • 客戶: 詢問與電動車保險獨特需求相關的問題
    • Claude: 以準確且具資訊性的答案回應,並提供來源連結
  • 客戶: 詢問與保險或汽車無關的離題問題
    • Claude: 說明它不討論無關的主題,並將使用者引導回汽車保險話題
  • 客戶: 表示對保險報價感興趣
    • Claude: 提出一系列問題以確定適當的報價,並根據客戶的回應進行調整
    • Claude: 發送請求以使用報價產生 API 工具,並附上從使用者收集的必要資訊
    • Claude: 接收來自 API 工具使用的回應資訊,將資訊整合成自然的回應,並向使用者呈現所提供的報價
  • 客戶: 提出後續問題
    • Claude: 視需要回答後續問題
    • Claude: 引導客戶進入保險流程的下一步並結束對話

在您為自己的使用案例撰寫的實際範例中,您可能會發現寫出此互動中的實際對話內容很有幫助,這樣您也可以了解您希望 Claude 具備的理想語氣、回應長度和詳細程度。

將互動拆解為獨立任務

客戶支援聊天是多種不同任務的集合,從回答問題到資訊擷取,再到針對請求採取行動,全部包裝在單一的客戶互動中。在開始建置之前,請將您理想的客戶互動拆解為您希望 Claude 能夠執行的每一項任務。這可確保您能針對每項任務對 Claude 進行提示和評估,並讓您清楚了解在撰寫測試案例時需要考量的互動範圍。


客戶有時會發現,將此視覺化為互動流程圖很有幫助,該流程圖會根據使用者請求顯示可能的對話轉折點。

以下是與上述保險互動範例相關的關鍵任務:

  1. 問候與一般指引

    • 親切地問候客戶並開啟對話
    • 提供有關公司和互動的一般資訊
  2. 產品資訊

    • 提供有關電動車保險的資訊
      
      這將需要 Claude 在其上下文中具備必要的資訊,並可能意味著需要 RAG 整合。
    • 回答與電動車保險獨特需求相關的問題
    • 回答有關報價或保險詳情的後續問題
    • 在適當時提供來源連結
  3. 對話管理

    • 保持主題(汽車保險)
    • 將離題的問題重新導向回相關主題
  4. 報價產生

    • 提出適當的問題以確定報價資格
    • 根據客戶回應調整問題
    • 將收集的資訊提交至報價產生 API
    • 向客戶呈現所提供的報價

建立成功標準

與您的支援團隊合作,定義成功標準並撰寫詳細的評估,包含可衡量的基準和目標。

以下是可用於評估 Claude 執行已定義任務成功程度的標準和基準:

以下是可用於評估採用 Claude 進行支援的業務影響的標準和基準:

如何將 Claude 實作為客戶服務代理

選擇合適的 Claude 模型

模型的選擇取決於成本、準確度和回應時間之間的權衡。

對於客戶支援聊天,Claude Opus 4.8 非常適合在智慧、延遲和成本之間取得平衡。然而,對於具有多個提示的對話流程(包括 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."""

雖然您可能會想將所有資訊放入系統提示中,以將指令與使用者對話分開,但 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。

對於此範例,從一個用於計算報價的工具開始。


提醒您,此工具不會執行實際的計算,它只會向應用程式發出訊號,表示應使用指定的任何參數來使用工具。

保險報價計算器範例:

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_message 和 process_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

評估您的提示

提示通常需要測試和最佳化才能達到生產就緒狀態。為了確定您解決方案的就緒程度,請使用結合量化和質化方法的系統化流程來評估聊天機器人的效能。根據您定義的成功標準建立強大的實證評估,將使您能夠最佳化您的提示。


Claude Console 現在具備評估工具,可讓您在各種情境下測試您的提示。

改善效能

在複雜的情境中,除了標準的提示工程技術和防護措施實作策略之外,考慮其他策略來改善效能可能會有所幫助。以下是一些常見的情境:

使用 RAG 減少長上下文延遲

在處理大量靜態和動態上下文時,將所有資訊包含在提示中可能會導致高成本、較慢的回應時間,以及達到上下文視窗限制。在此情境中,實作「Retrieval Augmented Generation」(檢索增強生成),即 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 服務可以接受使用者輸入並完整回傳助理回應。因此,您的服務可以具有以下特性:

    • 「Server-Sent Events」(伺服器發送事件),即 SSE:SSE 允許從伺服器即時串流回應到用戶端。這對於在使用 LLM 時提供流暢、互動式的體驗至關重要。
    • 快取:實作快取可以顯著改善回應時間並減少不必要的 API 呼叫。
    • 上下文保留:當使用者離開並返回時維持上下文,對於對話的連續性很重要。
  2. 建置網頁介面:實作使用者友善的網頁 UI,以與由 Claude 驅動的代理進行互動。


檢索增強生成(RAG)cookbook


造訪 RAG cookbook 範例以取得更多範例程式碼和詳細指引。


引用 cookbook


探索引用 cookbook 範例,了解如何確保資訊的準確性和可解釋性。

Was this page helpful?

  • 使用 Claude 建置之前
  • 決定是否使用 Claude 進行支援聊天
  • 定義您理想的聊天互動
  • 將互動拆解為獨立任務
  • 建立成功標準
  • 如何將 Claude 實作為客戶服務代理
  • 選擇合適的 Claude 模型
  • 建立強大的提示
  • 透過工具使用新增動態和代理能力
  • 部署您的提示
  • 建置您的使用者介面
  • 評估您的提示
  • 改善效能
  • 將 Claude 整合到您的支援工作流程中