Loading...
    • 開發者指南
    • API 參考
    • MCP
    • 資源
    • 發行說明
    Search...
    ⌘K
    資源
    概覽術語表系統提示詞
    概覽工單路由客戶支援代理內容審核法律摘要
    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
    • Catalog
    • 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
    • Catalog
    • 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 的進階對話能力即時處理客戶諮詢,提供全天候支援、減少等待時間,並以準確的回應和正面的互動來管理大量的支援需求。

    Was this page helpful?

    • 在使用 Claude 建構之前
    • 決定是否使用 Claude 進行支援聊天
    • 如何將 Claude 實作為客戶服務代理
    • 選擇合適的 Claude 模型
    • 將 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. 對話管理

      • 保持主題(汽車保險)
      • 將離題問題重新導向相關主題

    建立成功標準

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

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

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

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

    選擇合適的 Claude 模型

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

    對於客戶支援聊天,Claude Opus 4.6 非常適合在智慧、延遲和成本之間取得平衡。然而,對於包含多個提示(包括 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"""
        # You can call an http endpoint or a database to get the quote.
        # Here, we simulate a delay of 1 seconds and return a fixed quote of 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")

    建構您的使用者介面

    使用 Streamlit 的 main 方法測試部署此程式碼。這個 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)
    
       # Display user and assistant messages skipping the first two
       for message in st.session_state.messages[2:]:
           # ignore tool use blocks
           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 減少長上下文延遲

    在處理大量靜態和動態上下文時,將所有資訊包含在提示中可能導致高成本、較慢的回應時間以及達到上下文視窗限制。在這種情況下,實施檢索增強生成(RAG)技術可以顯著改善效能和效率。

    透過使用像 Voyage 這樣的嵌入模型將資訊轉換為向量表示,您可以建立更具可擴展性和回應性的系統。這種方法允許根據當前查詢動態檢索相關資訊,而不是在每個提示中包含所有可能的上下文。

    為支援使用案例實施 RAG 的 RAG 食譜已被證明可以在具有大量上下文需求的系統中提高準確性、減少回應時間和降低 API 成本。

    使用工具使用整合即時資料

    在處理需要即時資訊的查詢時,例如帳戶餘額或保單詳情,基於嵌入的 RAG 方法是不夠的。相反,您可以利用工具使用來顯著增強聊天機器人提供準確、即時回應的能力。例如,您可以使用工具使用來查詢客戶資訊、檢索訂單詳情,以及代表客戶取消訂單。

    這種方法在我們的工具使用:客戶服務代理食譜中有詳細說明,允許您將即時資料無縫整合到 Claude 的回應中,並提供更個人化和高效的客戶體驗。

    加強輸入和輸出防護措施

    在部署聊天機器人時,特別是在客戶服務場景中,防止與濫用、超出範圍的查詢和不當回應相關的風險至關重要。雖然 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. 建構網頁介面:實施一個使用者友善的網頁 UI 來與 Claude 驅動的代理互動。

    檢索增強生成(RAG)食譜
  1. 報價生成

    • 提出適當的問題以確定報價資格
    • 根據客戶回應調整問題
    • 將收集的資訊提交至報價生成 API
    • 向客戶呈現提供的報價
  2. 造訪我們的 RAG 食譜以獲取更多範例程式碼和詳細指導。

    引用食譜

    探索我們的引用食譜,了解如何確保資訊的準確性和可解釋性。