基于步骤配置与中间件的客服Agent交接流程
该资料介绍用步骤配置和中间件构建客服Agent,按保修收集、问题分类、解决三阶段切换系统提示与工具,并在多轮对话中保持状态。
那个... [状态机器图案](<https://docs.langchain.com/oss/python/langchain/multi-agent/handoffs>) 描述一个代理在任务的不同状态下改变行为的工作流程。此教程显示如何通过使用工具调用来动态改变单个代理的配置来实施状态机器,同时根据当前状态更新其可用的工具和指令。状态可以从多个来源决定:代理的过去动作(工具调用),外部状态(如API调用结果),甚至初始用户输入(例如运行一个分类器来确定用户意图). 在这个教程中,您将构建一个客户客服智能体,执行以下任务: - 行动前收集保修资料。 - 将问题归类为硬件或软件。 - 提供解决方案或升级为人类支持. - 保持多个回合间的对话状态。 与 [子剂图案](<https://docs.langchain.com/oss/python/langchain/multi-agent/subagents-personal-assistant>) 将子代理人称为工具的地方, **状态机器图案** 使用一个单一的代理,其配置根据工作流程的进展而改变。每个“步骤”仅仅是同一个基本代理的不同配置(系统即时+工具),根据状态动态选择。这里是我们将构建的工作流程: ## 设置 ### 安装 此教程要求 `langchain` 软件包 : ``` pip install langchain ``` ``` uv add langchain ``` ``` conda install langchain -c conda-forge ``` 详细情况请见我们 [安装指南](<https://docs.langchain.com/oss/python/langchain/install>). ### LangSmith 设置 [LangSmith](<https://smith.langchain.com/?utm_source=docs&utm_medium=cta&utm_campaign=langsmith-signup&utm_content=oss-langchain-multi-agent-handoffs-customer-support>) 以检查您的代理服务器内发生的情况。然后设置以下环境变量: ``` export LANGSMITH_TRACING="true" export LANGSMITH_API_KEY="..." ``` ``` import getpass import os os.environ["LANGSMITH_TRACING"] = "true" os.environ["LANGSMITH_API_KEY"] = getpass.getpass() ``` ### 选择一个 LLM 从 LangChain 的整合套件中选择聊天模式 : - OpenAI - 人类 - 阿苏雷 - 谷歌双子座 - AWS 贝德洛克 - HuggingFace - OpenRouter 读吧 [OpenAI 聊天模式集成文件](<https://docs.langchain.com/oss/python/integrations/chat/openai/>) ``` pip install -U "langchain[openai]" ``` ``` uv add "langchain[openai]" ``` ``` import os from langchain.chat_models import init_chat_model os.environ["OPENAI_API_KEY"] = "sk-..." model = init_chat_model("gpt-6.1-sol") ``` ``` import os from langchain_openai import ChatOpenAI os.environ["OPENAI_API_KEY"] = "sk-..." model = ChatOpenAI(model="gpt-6.1-sol") ``` 读吧 [Anthropic 聊天模式集成文件](<https://docs.langchain.com/oss/python/integrations/chat/anthropic/>) ``` pip install -U "langchain[anthropic]" ``` ``` uv add "langchain[anthropic]" ``` ``` import os from langchain.chat_models import init_chat_model os.environ["ANTHROPIC_API_KEY"] = "sk-..." model = init_chat_model("claude-sonnet-4-6") ``` ``` import os from langchain_anthropic import ChatAnthropic os.environ["ANTHROPIC_API_KEY"] = "sk-..." model = ChatAnthropic(model="claude-sonnet-4-6") ``` 读吧 [Azure 聊天模式集成文件](<https://docs.langchain.com/oss/python/integrations/chat/azure_chat_openai/>) ``` pip install -U "langchain[openai]" ``` ``` uv add "langchain[openai]" ``` ``` import os from langchain.chat_models import init_chat_model os.environ["AZURE_OPENAI_API_KEY"] = "..." os.environ["AZURE_OPENAI_ENDPOINT"] = "..." os.environ["OPENAI_API_VERSION"] = "2025-03-01-preview" model = init_chat_model( "azure_openai:gpt-6.1-sol", azure_deployment=os.environ["AZURE_OPENAI_DEPLOYMENT_NAME"], ) ``` ``` import os from langchain_openai import AzureChatOpenAI os.environ["AZURE_OPENAI_API_KEY"] = "..." os.environ["AZURE_OPENAI_ENDPOINT"] = "..." os.environ["OPENAI_API_VERSION"] = "2025-03-01-preview" model = AzureChatOpenAI( model="gpt-6.1-sol", azure_deployment=os.environ["AZURE_OPENAI_DEPLOYMENT_NAME"] ) ``` 读吧 [Google GenAI 聊天模式集成文件](<https://docs.langchain.com/oss/python/integrations/chat/google_generative_ai/>) ``` pip install -U "langchain[google-genai]" ``` ``` uv add "langchain[google-genai]" ``` ``` import os from langchain.chat_models import init_chat_model os.environ["GOOGLE_API_KEY"] = "..." model = init_chat_model("google_genai:gemini-4-hydrogen") ``` ``` import os from langchain_google_genai import ChatGoogleGenerativeAI os.environ["GOOGLE_API_KEY"] = "..." model = ChatGoogleGenerativeAI(model="gemini-4-hydrogen") ``` 读吧 [AWS Bedrock 聊天模式集成文件](<https://docs.langchain.com/oss/python/integrations/chat/bedrock/>) ``` pip install -U "langchain[aws]" ``` ``` uv add "langchain[aws]" ``` ``` from langchain.chat_models import init_chat_model # Follow the steps here to configure your credentials: # https://docs.aws.amazon.com/bedrock/latest/userguide/getting-started.html model = init_chat_model( "us.anthropic.claude-sonnet-4-6", model_provider="bedrock_converse", ) ``` ``` from langchain_aws import ChatBedrock model = ChatBedrock(model="us.anthropic.claude-sonnet-4-6") ``` 读吧 [HuggingFace 聊天模式集成文件](<https://docs.langchain.com/oss/python/integrations/chat/huggingface/>) ``` pip install -U "langchain[huggingface]" ``` ``` uv add "langchain[huggingface]" ``` ``` import os from langchain.chat_models import init_chat_model os.environ["HUGGINGFACEHUB_API_TOKEN"] = "hf_..." model = init_chat_model( "microsoft/Phi-3-mini-4k-instruct", model_provider="huggingface", temperature=0.7, max_tokens=1024, ) ``` ``` import os from langchain_huggingface import ChatHuggingFace, HuggingFaceEndpoint os.environ["HUGGINGFACEHUB_API_TOKEN"] = "hf_..." llm = HuggingFaceEndpoint( repo_id="microsoft/Phi-3-mini-4k-instruct", temperature=0.7, max_length=1024, ) model = ChatHuggingFace(llm=llm) ``` 读吧 [OpenRouter 聊天模式集成文件](<https://docs.langchain.com/oss/python/integrations/chat/openrouter/>) ``` pip install -U "langchain-openrouter" ``` ``` uv add "langchain-openrouter" ``` ``` import os from langchain.chat_models import init_chat_model os.environ["OPENROUTER_API_KEY"] = "sk-..." model = init_chat_model( "auto", model_provider="openrouter", ) ``` ``` import os from langchain_openrouter import ChatOpenRouter os.environ["OPENROUTER_API_KEY"] = "sk-..." model = ChatOpenRouter(model="auto") ``` ## 1. 定义自定义状态 首先,定义一个自定义状态方案,用于跟踪当前活动的步骤: ``` from langchain.agents import AgentState from typing_extensions import NotRequired from typing import Literal # Define the possible workflow steps SupportStep = Literal["warranty_collector", "issue_classifier", "resolution_specialist"] class SupportState(AgentState): """State for customer support workflow.""" current_step: NotRequired[SupportStep] warranty_status: NotRequired[Literal["in_warranty", "out_of_warranty"]] issue_type: NotRequired[Literal["hardware", "software"]] ``` 那个... `current_step` 字段是状态机器模式的核心-它决定了每个回合装入哪个配置(即时+工具). ## 2. 创建管理工作流程状态的工具 创建更新工作流程状态的工具。 这些工具允许代理记录信息并转换到下一步。 关键是使用 `Command` 更新状态,包括 `current_step` 字段 : ``` from langchain.tools import tool, ToolRuntime from langchain.messages import ToolMessage from langgraph.types import Command @tool def record_warranty_status( status: Literal["in_warranty", "out_of_warranty"], runtime: ToolRuntime[None, SupportState], ) -> Command: """Record the customer's warranty status and transition to issue classification.""" return Command( update={ "messages": [ ToolMessage( content=f"Warranty status recorded as: {status}", tool_call_id=runtime.tool_call_id, ) ], "warranty_status": status, "current_step": "issue_classifier", } ) @tool def record_issue_type( issue_type: Literal["hardware", "software"], runtime: ToolRuntime[None, SupportState], ) -> Command: """Record the type of issue and transition to resolution specialist.""" return Command( update={ "messages": [ ToolMessage( content=f"Issue type recorded as: {issue_type}", tool_call_id=runtime.tool_call_id, ) ], "issue_type": issue_type, "current_step": "resolution_specialist", } ) @tool def escalate_to_human(reason: str) -> str: """Escalate the case to a human support specialist.""" # In a real system, this would create a ticket, notify staff, etc. return f"Escalating to human support. Reason: {reason}" @tool def provide_solution(solution: str) -> str: """Provide a solution to the customer's issue.""" return f"Solution provided: {solution}" ``` 注意到如何 `record_warranty_status` 财务报告和财务报告 `record_issue_type` 返回时 `Command` 更新两个数据的对象(`warranty_status`, `issue_type`(AND号卫星) `current_step`。这就是状态机器的运作方式 — 工具控制工作流程进展。 ## 3. 定义步骤配置 定义每个步骤的提示和工具。首先,定义每个步骤的提示 : 查看完整的即时定义 ``` # Define prompts as constants for easy reference WARRANTY_COLLECTOR_PROMPT = """You are a customer support agent helping with device issues. CURRENT STAGE: Warranty verification At this step, you need to: 1. Greet the customer warmly 2. Ask if their device is under warranty 3. Use record_warranty_status to record their response and move to the next step Be conversational and friendly. Don't ask multiple questions at once.""" ISSUE_CLASSIFIER_PROMPT = """You are a customer support agent helping with device issues. CURRENT STAGE: Issue classification CUSTOMER INFO: Warranty status is {warranty_status} At this step, you need to: 1. Ask the customer to describe their issue 2. Determine if it's a hardware issue (physical damage, broken parts) or software issue (app crashes, performance) 3. Use record_issue_type to record the classification and move to the next step If unclear, ask clarifying questions before classifying.""" RESOLUTION_SPECIALIST_PROMPT = """You are a customer support agent helping with device issues. CURRENT STAGE: Resolution CUSTOMER INFO: Warranty status is {warranty_status}, issue type is {issue_type} At this step, you need to: 1. For SOFTWARE issues: provide troubleshooting steps using provide_solution 2. For HARDWARE issues: - If IN WARRANTY: explain warranty repair process using provide_solution - If OUT OF WARRANTY: escalate_to_human for paid repair options Be specific and helpful in your solutions.""" ``` 然后用词典将步骤名称映射到它们的配置中: ``` # Step configuration: maps step name to (prompt, tools, required_state) STEP_CONFIG = { "warranty_collector": { "prompt": WARRANTY_COLLECTOR_PROMPT, "tools": [record_warranty_status], "requires": [], }, "issue_classifier": { "prompt": ISSUE_CLASSIFIER_PROMPT, "tools": [record_issue_type], "requires": ["warranty_status"], }, "resolution_specialist": { "prompt": RESOLUTION_SPECIALIST_PROMPT, "tools": [provide_solution, escalate_to_human], "requires": ["warranty_status", "issue_type"], }, } ``` 这种基于词典的配置使得: - 看一看所有步骤 - 添加新步骤( 只要添加另一个条目) - 了解工作流程的依赖性( E)`requires` 字段) - 使用带有状态变量的快速模板(例如, `{warranty_status}`) ## 4. 创建基于步骤的中间软件 创建读取的中间软件 `current_step` 从状态并应用适当的配置。我们将使用 `@wrap_model_call` 清洁执行的装饰: ``` from langchain.agents.middleware import wrap_model_call, ModelRequest, ModelResponse from typing import Callable @wrap_model_call def apply_step_config( request: ModelRequest, handler: Callable[[ModelRequest], ModelResponse], ) -> ModelResponse: """Configure agent behavior based on the current step.""" # Get current step (defaults to warranty_collector for first interaction) current_step = request.state.get("current_step", "warranty_collector") # Look up step configuration stage_config = STEP_CONFIG[current_step] # Validate required state exists for key in stage_config["requires"]: if request.state.get(key) is None: raise ValueError(f"{key} must be set before reaching {current_step}") # Format prompt with state values (supports {warranty_status}, {issue_type}, etc.) system_prompt = stage_config["prompt"].format(**request.state) # Inject system prompt and step-specific tools request = request.override( system_prompt=system_prompt, tools=stage_config["tools"], ) return handler(request) ``` 这个中间器件: 1. **读取当前步骤**: 获取 `current_step` 从状态( 默认为“ warranty_collector ”) 。 2. **向上显示配置**: 查找匹配的条目 `STEP_CONFIG`. 3. **验证依赖关系**:确保有所需的州域。 4. **格式提示**: 将状态值输入快速模板。 5. **应用配置**: 覆盖系统即时和可用的工具. 那个... `request.override()` 方法是关键 - 它允许我们基于状态动态改变代理的行为而不创建单独的代理实例 。 ## 5. 创建代理 现在用基于步骤的中间器件创建代理, 并设置一个状态持续状态检查器 : ``` from langchain.agents import create_agent from langgraph.checkpoint.memory import InMemorySaver # Collect all tools from all step configurations all_tools = [ record_warranty_status, record_issue_type, provide_solution, escalate_to_human, ] # Create the agent with step-based configuration agent = create_agent( model, tools=all_tools, state_schema=SupportState, middleware=[apply_step_config], checkpointer=InMemorySaver(), ) ``` **为什么是检查站?** 检查人员在对话间保持状态,没有它, `current_step` 状态将在用户信件之间丢失, 中断工作流程 。 ## 6. 测试工作流程 测试整个工作流程 : ``` from langchain.messages import HumanMessage from langchain_core.utils.uuid import uuid7 # Configuration for this conversation thread thread_id = str(uuid7()) config = {"configurable": {"thread_id": thread_id}} # Turn 1: Initial message - starts with warranty_collector step print("=== Turn 1: Warranty Collection ===") result = agent.invoke( {"messages": [HumanMessage("Hi, my phone screen is cracked")]}, config ) for msg in result['messages']: msg.pretty_print() # Turn 2: User responds about warranty print("\n=== Turn 2: Warranty Response ===") result = agent.invoke( {"messages": [HumanMessage("Yes, it's still under warranty")]}, config ) for msg in result['messages']: msg.pretty_print() print(f"Current step: {result.get('current_step')}") # Turn 3: User describes the issue print("\n=== Turn 3: Issue Description ===") result = agent.invoke( {"messages": [HumanMessage("The screen is physically cracked from dropping it")]}, config ) for msg in result['messages']: msg.pretty_print() print(f"Current step: {result.get('current_step')}") # Turn 4: Resolution print("\n=== Turn 4: Resolution ===") result = agent.invoke( {"messages": [HumanMessage("What should I do?")]}, config ) for msg in result['messages']: msg.pretty_print() ``` 预期流量 : 1. **确定性核查步骤**: 询问保修状态 2. **问题分类步骤**:询问问题,决定问题在于硬件 3. **决议步骤**: 提供保修指令 ## 7. 理解状态过渡 让我们追踪每个转弯时会发生什么: ### 转动 1: 初始消息 ``` { "messages": [HumanMessage("Hi, my phone screen is cracked")], "current_step": "warranty_collector" # Default value } ``` 中间软件应用 : - 系统提示 : `WARRANTY_COLLECTOR_PROMPT` - 工具 : `[record_warranty_status]` ### 转动 2 : 已记录保修后 工具调用 : `record_warranty_status("in_warranty")` 返回 : ``` Command(update={ "warranty_status": "in_warranty", "current_step": "issue_classifier" # State transition! }) ``` 下一个回合, 中间软件应用 : - 系统提示 : `ISSUE_CLASSIFIER_PROMPT` (格式化为: `warranty_status="in_warranty"`) - 工具 : `[record_issue_type]` ### 转动 3 : 分类后 工具调用 : `record_issue_type("hardware")` 返回 : ``` Command(update={ "issue_type": "hardware", "current_step": "resolution_specialist" # State transition! }) ``` 下一个回合, 中间软件应用 : - 系统提示 : `RESOLUTION_SPECIALIST_PROMPT` (格式化为: `warranty_status` 财务报告和财务报告 `issue_type`) - 工具 : `[provide_solution, escalate_to_human]` 关键见解是: **工具驱动工作流程** 通过更新 `current_step`,以及 **中间软件响应** 在下一个回合应用适当的配置。 ## 8. 管理信件历史 随着代理程序通过步骤进行,消息历史不断增长。使用 [总结中间软件](<https://docs.langchain.com/oss/python/langchain/short-term-memory#summarize-messages>) 在保留对话上下文的同时压缩先前的消息 : ``` from langchain.agents import create_agent from langchain.agents.middleware import SummarizationMiddleware from langgraph.checkpoint.memory import InMemorySaver agent = create_agent( model, tools=all_tools, state_schema=SupportState, middleware=[ apply_step_config, SummarizationMiddleware( model="gpt-5.4-mini", trigger=("tokens", 4000), keep=("messages", 10) ) ], checkpointer=InMemorySaver(), ) ``` 见 [短期内存指南](<https://docs.langchain.com/oss/python/langchain/short-term-memory>) 其他记忆管理技术。 ## 9. 添加灵活性: 返回 某些工作流程需要允许用户回到先前的步骤来纠正信息(例如改变保修状态或发布分类 ) 。 但是,并非所有的过渡都有意义 — — 例如,一旦退款处理完毕,通常你就不能回去。 对于这一支持工作流程,我们将增加工具,以回到保修核实和发布分类步骤。 如果您的工作流程需要在大多数步骤之间任意转换, 请考虑您是否需要结构化的工作流程 。 当步骤遵循明确的顺序进程, 并偶尔向后转换以进行校正时, 这个模式最有效 。 在决议步骤中添加“返回”工具: ``` @tool def go_back_to_warranty() -> Command: """Go back to warranty verification step.""" return Command(update={"current_step": "warranty_collector"}) @tool def go_back_to_classification() -> Command: """Go back to issue classification step.""" return Command(update={"current_step": "issue_classifier"}) # Update the resolution_specialist configuration to include these tools STEP_CONFIG["resolution_specialist"]["tools"].extend([ go_back_to_warranty, go_back_to_classification ]) ``` 更新决议专家的提示,以提及这些工具: ``` RESOLUTION_SPECIALIST_PROMPT = """You are a customer support agent helping with device issues. CURRENT STAGE: Resolution CUSTOMER INFO: Warranty status is {warranty_status}, issue type is {issue_type} At this step, you need to: 1. For SOFTWARE issues: provide troubleshooting steps using provide_solution 2. For HARDWARE issues: - If IN WARRANTY: explain warranty repair process using provide_solution - If OUT OF WARRANTY: escalate_to_human for paid repair options If the customer indicates any information was wrong, use: - go_back_to_warranty to correct warranty status - go_back_to_classification to correct issue type Be specific and helpful in your solutions.""" ``` 现在,代理可以处理更正: ``` result = agent.invoke( {"messages": [HumanMessage("Actually, I made a mistake - my device is out of warranty")]}, config ) # Agent will call go_back_to_warranty and restart the warranty verification step ``` ## 完整实例 这些都用可操作的脚本来表达: 显示完整代码 ``` """ Customer Support State Machine Example This example demonstrates the state machine pattern. A single agent dynamically changes its behavior based on the current_step state, creating a state machine for sequential information collection. """ from langchain_core.utils.uuid import uuid7 from langgraph.checkpoint.memory import InMemorySaver from langgraph.types import Command from typing import Callable, Literal from typing_extensions import NotRequired from langchain.agents import AgentState, create_agent from langchain.agents.middleware import wrap_model_call, ModelRequest, ModelResponse, SummarizationMiddleware from langchain.chat_models import init_chat_model from langchain.messages import HumanMessage, ToolMessage from langchain.tools import tool, ToolRuntime model = init_chat_model("google_genai:gemini-4-hydrogen") # Define the possible workflow steps SupportStep = Literal["warranty_collector", "issue_classifier", "resolution_specialist"] class SupportState(AgentState): """State for customer support workflow.""" current_step: NotRequired[SupportStep] warranty_status: NotRequired[Literal["in_warranty", "out_of_warranty"]] issue_type: NotRequired[Literal["hardware", "software"]] @tool def record_warranty_status( status: Literal["in_warranty", "out_of_warranty"], runtime: ToolRuntime[None, SupportState], ) -> Command: """Record the customer's warranty status and transition to issue classification.""" return Command( update={ "messages": [ ToolMessage( content=f"Warranty status recorded as: {status}", tool_call_id=runtime.tool_call_id, ) ], "warranty_status": status, "current_step": "issue_classifier", } ) @tool def record_issue_type( issue_type: Literal["hardware", "software"], runtime: ToolRuntime[None, SupportState], ) -> Command: """Record the type of issue and transition to resolution specialist.""" return Command( update={ "messages": [ ToolMessage( content=f"Issue type recorded as: {issue_type}", tool_call_id=runtime.tool_call_id, ) ], "issue_type": issue_type, "current_step": "resolution_specialist", } ) @tool def escalate_to_human(reason: str) -> str: """Escalate the case to a human support specialist.""" # In a real system, this would create a ticket, notify staff, etc. return f"Escalating to human support. Reason: {reason}" @tool def provide_solution(solution: str) -> str: """Provide a solution to the customer's issue.""" return f"Solution provided: {solution}" # Define prompts as constants WARRANTY_COLLECTOR_PROMPT = """You are a customer support agent helping with device issues. CURRENT STEP: Warranty verification At this step, you need to: 1. Greet the customer warmly 2. Ask if their device is under warranty 3. Use record_warranty_status to record their response and move to the next step Be conversational and friendly. Don't ask multiple questions at once.""" ISSUE_CLASSIFIER_PROMPT = """You are a customer support agent helping with device issues. CURRENT STEP: Issue classification CUSTOMER INFO: Warranty status is {warranty_status} At this step, you need to: 1. Ask the customer to describe their issue 2. Determine if it's a hardware issue (physical damage, broken parts) or software issue (app crashes, performance) 3. Use record_issue_type to record the classification and move to the next step If unclear, ask clarifying questions before classifying.""" RESOLUTION_SPECIALIST_PROMPT = """You are a customer support agent helping with device issues. CURRENT STEP: Resolution CUSTOMER INFO: Warranty status is {warranty_status}, issue type is {issue_type} At this step, you need to: 1. For SOFTWARE issues: provide troubleshooting steps using provide_solution 2. For HARDWARE issues: - If IN WARRANTY: explain warranty repair process using provide_solution - If OUT OF WARRANTY: escalate_to_human for paid repair options Be specific and helpful in your solutions.""" # Step configuration: maps step name to (prompt, tools, required_state) STEP_CONFIG = { "warranty_collector": { "prompt": WARRANTY_COLLECTOR_PROMPT, "tools": [record_warranty_status], "requires": [], }, "issue_classifier": { "prompt": ISSUE_CLASSIFIER_PROMPT, "tools": [record_issue_type], "requires": ["warranty_status"], }, "resolution_specialist": { "prompt": RESOLUTION_SPECIALIST_PROMPT, "tools": [provide_solution, escalate_to_human], "requires": ["warranty_status", "issue_type"], }, } @wrap_model_call def apply_step_config( request: ModelRequest, handler: Callable[[ModelRequest], ModelResponse], ) -> ModelResponse: """Configure agent behavior based on the current step.""" # Get current step (defaults to warranty_collector for first interaction) current_step = request.state.get("current_step", "warranty_collector") # Look up step configuration step_config = STEP_CONFIG[current_step] # Validate required state exists for key in step_config["requires"]: if request.state.get(key) is None: raise ValueError(f"{key} must be set before reaching {current_step}") # Format prompt with state values system_prompt = step_config["prompt"].format(**request.state) # Inject system prompt and step-specific tools request = request.override( system_prompt=system_prompt, tools=step_config["tools"], ) return handler(request) # Collect all tools from all step configurations all_tools = [ record_warranty_status, record_issue_type, provide_solution, escalate_to_human, ] # Create the agent with step-based configuration and summarization agent = create_agent( model, tools=all_tools, state_schema=SupportState, middleware=[ apply_step_config, SummarizationMiddleware( model="gpt-5.4-mini", trigger=("tokens", 4000), keep=("messages", 10) ) ], checkpointer=InMemorySaver(), ) # ============================================================================ # Test the workflow # ============================================================================ if __name__ == "__main__": thread_id = str(uuid7()) config = {"configurable": {"thread_id": thread_id}} result = agent.invoke( {"messages": [HumanMessage("Hi, my phone screen is cracked")]}, config ) result = agent.invoke( {"messages": [HumanMessage("Yes, it's still under warranty")]}, config ) result = agent.invoke( {"messages": [HumanMessage("The screen is physically cracked from dropping it")]}, config ) result = agent.invoke( {"messages": [HumanMessage("What should I do?")]}, config ) for msg in result['messages']: msg.pretty_print() ``` ## 今后的步骤 - 学习关于 [子剂图案](<https://docs.langchain.com/oss/python/langchain/multi-agent/subagents-personal-assistant>) 用于集中管弦乐 - 探索 [中间软件](<https://docs.langchain.com/oss/python/langchain/middleware>) 用于更动态的行为 - 读读 [多代理概览](<https://docs.langchain.com/oss/python/langchain/multi-agent>) 比较图案 - 使用( U) [LangSmith](<https://smith.langchain.com/?utm_source=docs&utm_medium=cta&utm_campaign=langsmith-signup&utm_content=oss-langchain-multi-agent-handoffs-customer-support>) 调试并监视您的多代理系统 --- [连接这些文件](<https://docs.langchain.com/use-these-docs>) 通过 MCP 向您选择的代理提供实时答案。 [在 GitHub 上编辑此页面](<https://github.com/langchain-ai/docs/edit/main/src/oss/langchain/multi-agent/handoffs-customer-support.mdx>) 或 时 间 [提交一个问题](<https://github.com/langchain-ai/docs/issues/new/choose>). 这页有用吗?
查看原始来源