亚马逊AWS官方博客

快时尚电商行业智能体设计思路与应用实践(一)借助超长上下文窗口分钟级构建智能客服系统

1. 序言

在数字经济蓬勃发展的今天,快时尚电商行业正经历着前所未有的智能化转型。随着消费者需求的日益多元化和个性化,传统模式在客户体验、运营效率和决策支持等方面,面临着巨大挑战。人工智能技术的迅猛发展,为行业提供了突破性的解决方案。从智能推荐系统到自动化客户服务,从供应链优化到精准营销,人工智能技术已经重塑了行业的运营模式和价值创造方式。

特别值得关注的是,随着大模型的飞速发展,企业获得了前所未有的能力,可以借助智能体,来理解和处理更为复杂的业务场景,而智能体也随着各类大模型此起彼伏的能力进化,不断迭代。然而,如何结合智能体设计模式合理的设计智能体架构,如何有效地将企业特定的知识和数据注入这些通用大模型当中,并选择适合企业自身实际情况的大模型的应用模式,成了快时尚电商行业智能化转型的关键挑战。

本文将从多个维度探讨智能体设计模式,解析智能体应用场景,并以智能客服系统为例,基于 Amazon Bedrock,借助当前大模型超强的代码生成的能力,利用多款大模型的超长上下文窗口的特性,展示如何分钟级快速构建一套基于企业知识库的智能客服解决方案,为企业在智能化转型的过程中,提供实用高效的技术路径和实施方法。

2. 智能体设计模式

首先,我们梳理一下从不同的分析维度,包括功能需求维度、拓扑结构维度、知识获取维度,有哪几种核心的智能体设计模式。

2.1 功能需求维度

这部分主要包括 Reflection Pattern、Tool Use Pattern、Planning Pattern、Multi-Agent Pattern​​,这类模式关注​​智能体在任务处理中的功能需求​​,例如:

  • Reflection Pattern​​:通过自我评估和迭代优化输出结果。
  • Tool Use Pattern​​:调用外部工具扩展能力边界,如代码执行、API 调用。
  • ​​Planning Pattern​​:任务分解与规划,将复杂目标拆解为可执行的子任务。
  • ​​Multi-Agent Pattern​​:多智能体协作框架,如角色分工、信息共享。
Reflection Pattern(反思模式) Tool Use Pattern(工具使用模式)
  • 智能体能够评估自己的输出质量
  • 通过自我批评和反馈循环不断改进
  • 适合需要高质量、准确性和持续优化的场景
  • 智能体能够调用外部工具和 API 完成特定任务
  • 扩展智能体的能力边界,实现更复杂的功能
  • 适合需要访问外部数据或执行特定操作的场景
Planning Pattern(规划模式) Multi-Agent Pattern(多智能体模式)
  • 智能体能够分解复杂任务,制定执行计划
  • 通过预测和评估不同路径选择最优方案
  • 适合需要多步骤决策的场景
  • 多个专业化智能体协作完成复杂任务
  • 通过角色分工和信息共享提高整体效能
  • 适合需要多领域专业知识或并行处理的场景

2.2 拓扑结构维度

这部分主要包括 Static Single-Agent、Dynamic Single-Agent、Centralized Multi-Agent、Distributed Multi-Agent​​,这类模式关注​​智能体在任务处理中的拓扑结构​​,例如:

  • Static Single-Agent:静态单智能体指的是仅有一个智能体,而且其环境在智能体感知、思考或执行行动时保持不变的系统。在此类环境中,智能体无需在行动过程中重复监测环境变化,可离线预先规划完整的行动序列。
  • Dynamic Single-Agent:动态单智能体依然只有一个智能体,但其所处环境会在智能体感知或执行动作的过程中发生变化,可能由外部事件或其他因素触发,因此智能体必须在执行期间持续监控环境状态,并根据新信息实时更新决策策略。
  • Centralized Multi-Agent:由一个中央控制器或主智能体负责所有决策。该控制器拥有整个系统的全局视图,指挥所有智能体的行为。
  • Distributed Multi-Agent:每个智能体根据自身的局部信息独立做出决策。系统中不存在单一的控制中心,智能体之间通过松耦合的方式通信协调。
Static Single-Agent(静态单代理) Dynamic Single-Agent(动态单代理)
  • 固定工作流:系统的任务执行顺序是预设的,无法改变。
  • 策划的智能体:智能体的行为和任务是精心设计的。
  • 可预测的结果:每次执行相同任务时,结果都是一致的。
  • 明确的­连接性:任务之间有清晰的依赖和交互关系。
  • 依赖性:任务的执行顺序和相互依赖决定了系统的整体运行。
  • 灵活工作流与任务分配:系统能够根据任务需求灵活调整工作流程,并通过规划器动态分配和调度任务。
  • 语义路由与意图驱动:语义路由器根据任务意图智能地决定任务的执行路径。
  • 实时动态选择:系统根据当前情况实时选择和调度合适的子任务。
  • 可扩展性:系统支持根据需要添加新的任务模块,增强其适应性和灵活性。

2.2.1 Centralized Multi-Agent(中心化多代理)

  • 中央控制系统主导:存在一个中央控制器负责全局任务分配、智能体协调和结果整合。
  • 统一的任务调度:中央控制器根据任务需求选择特定智能体执行子任务,确保任务逻辑连贯。
  • 单点故障风险:中央控制器的失效可能导致系统整体崩溃,可靠性依赖于中心节点的稳定性。
  • 通信效率高:智能体间无需直接通信,所有信息通过中央节点中转,减少冗余交互。
  • 适用于确定性场景:在环境相对稳定、任务逻辑清晰的场景中表现更优。
  • 开发复杂度:相对于分布式多代理模式,架构设计简单,协调逻辑集中,适合中小规模系统快速部署。

2.2.2 Distributed Multi-Agent(分布式多代理)

  • 去中心化架构:无单一控制节点,智能体通过本地决策和交互实现协作。
  • 高度自治性:每个智能体独立感知环境、制定策略并执行行动,仅共享必要信息。
  • 容错性强:局部节点故障不影响整体系统运行,可通过冗余设计自动恢复。
  • 支持复杂交互场景:适用于开放、动态环境。
  • 可扩展性高:新增智能体仅需遵循通用协议,易于实现横向扩展。
  • 开发复杂度高:需设计分布式协调机制,并解决冲突消解问题。
  • 涌现行为风险:局部决策可能引发不可预测的全局行为。
  • 冲突解决机制:如果不同的代理发布和认领不同的任务,则可以弱化冲突解决机制,如果不同的代理发布和认领相同的任务,则需要强化冲突解决机制。

2.3 知识获取维度

这部分主要对比分析大模型获取知识能力的三种模式的优势和劣势,包括模型调优、检索增强生成和超长上下文窗口。

2.3.1 Model Tuning(模型调优)

优势:

  • 响应高效稳定:经过微调的模型可快速生成答案,且延迟波动小,适合高并发场景。
  • 模式学习能力:能捕捉数据中的固定模式(如特定写作风格、行业术语),生成更符合需求的输出。
  • 定制化输出:适用于需严格遵循格式或规则的场景。
  • 减少幻觉:针对特定领域的精确调优可以减少模型在该领域的幻觉问题。
  • 适合固定知识体系:对于变化不频繁的知识领域(如科学原理、历史事实等)效果良好。

劣势:

  • 数据质量要求高:需大量标注数据且要求分布稳定,数据噪声会导致模型性能下降。
  • 迭代成本高:训练过程耗时耗力,调整超参数和架构需专业知识与计算资源。
  • 灵活性不足:难以适应数据分布变化(如政策更新后的知识库),需重新训练。
  • 过拟合风险:对缺乏明确模式的数据(如随机分布的时间表)易产生“幻觉”,输出错误结论。

2.3.2 Retrieval Augmented Generation(检索增强生成)

优势:

  • 高效检索:RAG 通过向量匹配快速筛选相关片段,适合需要实时响应的交互场景。
  • 动态数据适配:支持数据集的频繁更新(如实时更新的知识库)。
  • 精准性优化空间:通过重排序模型二次筛选,提升语义相关性,改善答案质量。
  • 扩展性强:可以处理大规模数据集,理论上知识库大小不受模型参数限制。
  • 减少幻觉:通过引用外部权威信息源,减少模型生成虚假信息的可能性。

劣势:

  • 分块破坏语义:简单分块(如固定字数切割)易截断关键信息,导致模型理解偏差。
  • 检索精度依赖:向量匹配可能返回表面相似但无关的结果,需额外优化。
  • 结构化查询局限:对统计、聚合类查询(如“最大值”“关联分析”)无能为力,需结合传统数据库。
  • 实现复杂度高:需协调分块策略、嵌入模型、数据库等多组件,系统设计复杂度高,构建和运维成本相对较高。
  • 缺乏全局理解:模型仅能访问检索片段,难以捕捉跨文本关联(如实体关系、事件逻辑)。虽然 GraphRAG 等图技术可以提升全局分析能力,但在实际应用中可能引入显著的工程复杂度和计算开销,需结合业务需求权衡取舍。
  • 检索生成分离:检索和生成是分离的两个步骤,可能导致信息传递损失。

2.3.3 Long-Context Windows(超长上下文窗口)

优势:

  • 全局理解能力:能够直接处理整本小说级别的大规模文本,保留完整的上下文信息,避免因分块导致的语义碎片化。
  • 简化流程:无需预处理或分块,直接将数据输入模型,无需复杂基础设施,适合快速构建应用系统。
  • 长对话支持:适合需要长期记忆的交互场景(如复杂客服对话),可保留完整对话历史供模型参考。

劣势:

  • Token 限制瓶颈:即使支持百万级 Token,仍无法应对超大规模数据(如全量业务日志)。
  • 成本高昂:长文本处理消耗大量计算资源,长期使用成本显著增加,需结合提示词缓存可以大幅度降低成本。

3. 智能体应用解析

在梳理了智能体的几类核心模式后,我们可以将其运用到快时尚电商领域。其中客户服务场景尤为典型,不仅对语言理解能力要求严苛,更需要广泛调用系统功能并处理复杂流程,这正是验证智能体设计模式价值的理想场景,虽然各个行业领域都会有智能客服的共性需求,但是在快时尚电商领域,由于其组织和架构的特点,也有其个性特性需求,大多数快时尚电商企业组织架构讲究极致敏捷,强调一专多能,针对一项新技术的应用,需要以最快的速度,在较少的人员参与的情况下达成较高的产出,所以相对来说,更为追求架构的简化,优先专注于业务的优化,业务目标非常明确,所以智能客服系统的升级改造项目,通常是以天为单位,快速迭代,简化运维,在各个环节降本增效,集中精力抓住业务问题的最核心部分。

综合考量,前期可以采用 Dynamic Single-Agent 模式保证智能体的简洁灵活,借助超长上下文窗口极简化知识获取能力,利用大模型不断加速进化的代码生成能力,装备一专多能的突击型工程师,快速构建系统运行框架,快速上线,简化运维,快速迭代,快速验证系统功能和业务目标。这样的思路也是权衡了目前各类智能体框架正在加速创新和频繁迭代,处于逐渐成熟的阶段,而随着工具和框架的不断成熟和完善,以及业务需求的不断增加,可以选择合适的时机,甄别更加成熟有效适合企业自身的框架,进一步推进其他业务系统的智能体升级改造。

接下来我们以智能客服系统为例,展开讨论智能体的设计思路和实现方法。

3.1 业务流程

3.1.1 流程图

3.1.2 流程说明与节点用途

3.1.2.1 核心节点及其用途

  • 用户输入节点:
    • 用途:与智能客服与人工客服的对话窗口
    • 功能:提交初始请求、提出后续问题、提供反馈
  • 上下文管理器:
    • 用途:存储整个对话的历史记录,维持对话的连贯性
    • 功能:记录用户的所有输入和系统的所有输出,使智能体能够理解当前问题的上下文,确保多轮对话中智能体能”记住”之前的交流内容,避免重复询问或给出矛盾回答
  • 服务协调环节:
    • 用途:作为整个系统的”大脑”,协调各个专业智能体的工作
    • 功能:基于大语言模型,具备理解复杂问题和决策能力,整合信息,理解用户意图,决定调用哪些专业应答环节
  • 专业应答环节:
    • 用途:处理特定领域的专业问题
    • 功能:包含多个专业智能体,如查询解答、退货退款、投诉处理等,每个环节都是 LLM 加上特定的专业能力增强
  • 知识共享平台(可选):
    • 用途:为专业任务环节提供所需的知识和信息
    • 功能:向量数据库结合检索增强生成技术,实现高效的语义搜索,找到与当前问题最相关的信息
  • SOP(标准操作程序,行业知识):
    • 用途:存储企业的操作流程
    • 功能:客户服务涉及售前、售中、售后等多方面问题等标准处理流程,是客服操作建议的主要来源
  • 业务系统:
    • 用途:存储客户的历史信息和相关记录
    • 功能:帮助智能体了解客户背景,提供个性化服务
  • 应答整合环节:
    • 用途:将各专业应答环节的输出整合成一致、连贯的回复
    • 功能:基于大语言模型的内容整合能力,消除冗余、解决冲突、统一语调
  • 反馈处理环节(可选):
    • 用途:处理对话结束时的用户反馈
    • 功能:分析对话效果,更新知识库,改进系统,形成闭环优化,持续提升服务质量

3.1.2.2 完整对话流程故事线示例

3.1.2.2.1 第一轮:初始请求处理
  1. 用户提交一个服务请求,例如:”我购买的衣服有问题,想申请退货”
  2. 请求首先进入上下文管理器,记录这个初始请求
  3. 客户服务协调环节接收请求,并从业务系统获取该客户的历史数据
  4. 服务协调环节分析请求内容,确定这是一个退货请求,需要调用专业应答环节
  5. 专业应答环节(可能是退货退款专业应答环节)从 SOP 中获取相关的退货退款政策和流程
  6. 专业应答环节处理完请求后,将结果传递给应答整合环节
  7. 应答整合环节生成一个结构化、友好的回复,例如:”了解您的衣服问题。根据我们的政策,您购买的衣服,可以申请退货。请您提供订单号。”
  8. 回复呈现给用户
3.1.2.2.2 第二轮:后续交互
  1. 用户看到回复后,提出后续问题:”但没有包装了,这样可以退吗?”
  2. 这个问题进入上下文管理器,与之前的对话历史一起存储
  3. 上下文管理器将完整对话传递给服务协调环节
  4. 服务协调环节理解这是对之前问题的跟进,继续调用专业应答环节
  5. 专业应答环节从知识共享平台获取关于退货要求的详细信息
  6. 专业应答环节处理后,将结果传递给应答整合环节生
  7. 应答整合环节生成后续回复:”只要衣服完好,包装不是必须的。请您提供订单号,我们会安排退货流程。”
  8. 回复呈现给用户
3.1.2.2.3 第三轮:对话结束
  1. 用户确认问题已解决:”好的,谢谢,我一会儿发订单号给你。”
  2. 确认信息进入上下文管理器
  3. 服务协调环节将对话引导至结束阶段
  4. 反馈处理环节分析整个对话过程
  5. 反馈处理环节更新客户数据,记录这次退货请求
  6. 反馈处理环节同时更新相关系统,优化未来类似问题的处理流程
  7. 系统生成最终响应:”很高兴能帮到您。收到您的订单号后,我们会立即处理您的退货申请。如有其他问题,随时咨询。祝您有愉快的一天!”
  8. 最终回复呈现给用户

3.1.2.3 系统优势

  • 专业分工:不同类型的问题由专门的基于大模型的任务环节处理,确保专业性
  • 上下文理解:整个对话过程中保持上下文连贯,避免用户重复描述问题
  • 知识共享:所有任务环节共享统一的行业知识,确保信息一致性
  • 灵活扩展:可以轻松添加新的专业的基于大模型的任务环节来处理新类型的问题

3.1.2.4 智能体设计模式分析

以上智能体设计思路主要体现了对以下几种设计模式的运用:

1. Dynamic Single-Agent(动态单代理)

  • 体现在针对性提示词调教大模型的专业化能力(查询解答、投诉处理、退货退款等)
  • 针对行业知识,每个大模型任务专注于自己的专业细分领域
  • 通过专业分工提高处理效率和质量,不同大模型调用可以协同工作

2. Reflection Pattern反思模式

  • 体现在反馈处理环节的功能中
  • 反馈处理环节分析对话效果,评估系统表现,并更新行业知识和客户数据
  • 这种自我评估和改进机制是反思模式的核心特征

3. Tool Use Pattern(工具使用模式)

  • 体现在智能体调用外部系统和资源的能力
  • 这些外部系统可以视为智能体使用的”工具”
  • 例如:服务协调环节调用业务系统获取客户数据,专业智能体调用接口获取行业知识

4. Planning Pattern(规划模式)

  • 体现在服务协调环节识别意图,协调专业应答环节,拆解任务,规划合理的处理路径
  • 例如:针对退货场景,系统可以根据退货原因(尺寸问题、质量问题、款式问题等)自动规划不同的处理路径
    • 质量问题退货→拍照证据收集→质检评估→全额退款+运费补偿
    • 尺寸问题退货→确认商品完好→安排退款或换货→推荐合适尺码

3.2 数据管道

梳理了智能体的设计模式和业务流程,需要进一步梳理数据管道的架构,数据管道的工程化落地是影响系统复杂度和综合成本的最关键因素。针对快时尚电商行业以快为要的行业性质,需构建适配业务节奏的数据中枢,其核心矛盾,在于​​如何在高速迭代的智能体系统中,实现多源异构数据的高效整合与有效传导​​,该行业的竞争本质要求技术架构必须贯彻几大原则,包括​​极简架构,快速实施,简化运维,降本增效。尤其在技术团队极致精干的敏捷模式下,需要将设计-开发-验证环节的协同损耗降到最低,同时又要尽可能控制基础计算资源用量的成本增加,从而有效降低综合成本。

值得注意的是,数据管道的复杂度对于方案落地的整体复杂度,具有非线性放大特征,会显著影响包括人员投入,架构设计,协同开发,部署落地,持续维护等各个层面的复杂度,所以对于技术团队极致精干的大多数快时尚电商企业,数据管道架构对于整个系统的综合成本,是决定性的。以智能客服系统的提示词工程为例,一个智能客服的提示词,可能包含以下几类信息。

  • 角色与任务定义
    • AI 定位:对话质量与流程优化专家。
    • 核心任务:
      • 分析模型输出(如对比模型 A/B 的优劣)。
      • 生成优化后的合并回复。
      • 提供改进建议与选择理由。
  • 规则与流程
    • SOP 依赖:
      • 客服流程决策树(如退款/物流问题的分支逻辑)。
    • 处理原则:
      • 信息完整性优先、用户确认优先、关键信息来源要求等。
    • 服务标准:
      • 问候、响应、解决方案、结束语等模板化流程。
    • 服务禁忌:
      • 禁止违背承诺、泄露隐私、损害公司形象等行为。
  • 业务场景覆盖
    • 用户需求识别(咨询、投诉、售后等)。
    • 订单处理(查询、修改、取消规则)。
    • 物流跟踪(状态查询、异常处理)。
    • 退货退款(政策、流程、时效)。
  • 内部支持工具
    • 系统操作指南(如订单 ID/退款 ID 的查询步骤)。
    • 常用页面链接库(自助服务入口)。
    • 公司信息(业务特点、政策依据)。
  • 输出与评估
    • 内容要求:
      • 明确优选模型、分析理由、优化回复、改进建议。
    • 质量标准:
      • 合规性(如隐私保护)、严谨性、用户满意度指标。
  • 扩展补充项
    • 动态场景:
      • 多语言/本地化支持、临时政策更新(如促销活动)。
    • 风险管控:
      • 情绪识别与危机升级(愤怒用户转人工)。
    • 技术容错:
      • 模型失效时的降级话术(如“系统繁忙,请稍候”)。

提示词包含 SOP,以及用户和商品相关的来自各个系统的数据。大多数业务系统数据,对于语义理解的需求较弱,可以通过 API 调用精准获取。但是 SOP 这类行业知识数据,对于语义理解的需求尤其显著,而完整的 SOP 数据大致会在几百 K 的规模,如何在模型调优,检索增强生成,超长上下文窗口,这几种知识获取路径当中,选择适合企业特点的数据处理路径,让大模型具备深入吸收行业知识的能力,成了大多数快时尚电商企业在设计构建智能客服系统过程中的关键考量。

3.3 SOP(标准操作程序)

客户服务涉及售前,售中,售后多方面问题,需要不同专业领域的知识和技能,典型场景包括:账号问题,订单问题,物流问题,产品问题,支付问题,促销问题,售后问题等。在快时尚电商行业,SOP 信息如果以文本的形式存放,其规模大致会在几百 K,而这样的规模,对于以往的大多数大模型而言,一次性注入会非常困难,而随着大模型的不断快速进化,一些大模型上下文窗口已经达到了百万级别,并且不会像早期大模型那样导致推理能力的大幅度衰减,所以 SOP 信息一次性全量或者分类注入大模型开始变成了可能。SOP 信息越来越适合绕开其他路径直接注入大模型的上下文窗口来辅助客服应答,核心原因在于其​​结构化语义特性​​与​​大模型长上下文窗口的技术优势​​高度适配,以下从技术价值与业务价值角度展开分析。

3.3.1 一、SOP 的语义结构适配大模型处理范式

3.3.1.1 强结构化与可解析性

SOP 通常包含明确的操作步骤、条件分支、责任归属等结构化信息(如审批流程、质检标准)。这种分层的规则体系可被大模型解析为“决策树逻辑”,例如:

  • 客户退货流程中的条件判断(是否超期、商品状态评估);
  • 投诉分级规则(普通问题升级到专员,重大纠纷触发法务介入)。

大模型通过长上下文窗口一次性加载完整 SOP,可避免传统分块检索导致的逻辑断层,例如 RAG 技术中因分块检索丢失关键条件分支的问题。

3.3.1.2 动态合规性保障

SOP 往往需要实时更新以符合法规变动(如电商退货政策调整)。将最新版 SOP 整体输入大模型,可确保客服回答​​始终基于最新规则​​,而无需等待繁琐的数据管道带来的异步更新过程。SOP 动态匹配能减少人工培训滞后风险。

3.3.2 二、长上下文窗口的技术红利

3.3.2.1 减少信息碎片化

大模型的长上下文能力,允许将 SOP 完整载入,避免传统检索增强生成(RAG)中因分块检索导致的语义割裂。例如:

  • 处理复杂客诉时,客服需同时参考投诉分级规则、补偿政策、历史案例,而长上下文窗口能保持多维度信息的​​关联推理​​;
  • 分块检索,可能遗漏跨段落的条件关联,而整体 SOP 输入可规避此问题。

3.3.2.2 降低幻觉风险

当 SOP 细节完整呈现时,大模型生成回答的可追溯性增强。例如:

  • 客户咨询退货流程,模型基于 SOP 原文生成分步骤指引,而非依赖参数记忆;
  • 长上下文通过扩大参考信息量,能有效抑制模型虚构回答。

3.3.3 三、业务场景的增效价值

3.3.3.1 降低客服培训成本

SOP 整体输入使大模型成为“实时教练”,例如:

  • 新员工无需记忆 SOP 细节,智能客服根据对话进度推送下一步操作建议;
  • 动态展示 SOP 关联表单模板(如工单补录字段),减少操作失误。

3.3.3.2 多模态协同增强

大模型可解析 SOP 中的非文本元素(如图表、流程图),并结合客户问题生成可视化指引。例如:

  • 客户询问尺码对照表,模型直接调用 SOP 中的图表生成解释;
  • 长窗口是多模态处理的技术基础,支持图文混合推理。

3.3.4 四、实施路径与优化方向

3.3.4.1 SOP 的语义增强预处理

  • 针对 SOP,明确步骤间的逻辑关系(如因果关系、并行任务);
  • 添加元数据标签(如“紧急补货流程”“海外客服条款”),提升大模型的分场景调用精度。

3.3.4.2 上下文窗口的效能优化

  • 采用“关键信息优先保留”策略,在长文本中聚焦核心条款;
  • 对大模型输出进行多轮校验,确保与 SOP 原文的一致性。

4. 智能体原型演示

接下来,以智能客服系统为例,基于 Amazon Bedrock 展示如何分钟级快速构建一套快时尚电商行业 SOP 指引下的智能客服解决方案。

4.1 环境准备

在构建代码生成任务之前,我们需要把以下环境准备就绪,然后利用 Cline,执行代码生成任务,详细的环境准备的步骤和相关配置,可以通过大模型快速获得,比如可以使用 Amazon Q。

  • AWS CLI
  • Visual Studio Code
  • Cline
  • Python
  • Boto3
  • Nova Premier
  • Palmyra X5
  • Nova Lite
  • DeepSeek-R1

4.2 任务构造

准备好相关开发环境之后,我们可以开始向 Cline 提交代码生成任务,需要考虑开发任务如何构造,例如:

  • 指定角色
  • 参考代码
  • 参考架构
  • 架构解析
  • 数据要求
  • 需求描述

4.3 代码生成任务示例

使用 Cline,借助当前大模型超强的代码生成能力,我们可以应用如下策略,详细描述技术需求和业务需求,分钟级快速生成完整的可运行代码,并快速调试迭代,以下是代码生成任务的提示词策略。

1. 你是一个解决方案架构师,你精通快时尚电商行业的智能客服的架构设计和代码实现,你对智能体涉及模式非常精通,十分清楚各种设计模式的应用场景。

2. 对于 us.writer.palmyra-x5-v1:0 的调用方法,请参考文章 https://cloudwatch-portal.com/blogs/aws/writer-palmyra-x5-and-x4-foundation-models-are-now-available-in-amazon-bedrock

3. 请参考以上代码,利用 us.writer.palmyra-x5-v1:0 模型,编写一个智能客服系统。

4. 当客户提出问题之后,SOP 和问题整合成提示词,注入到第一层大模型,负责识别意图。

5. 当第一层大模型完成意图识别之后,将 SOP 和意图整合成提示词,注入到第二层大模型,第二层大模型负责回答问题。

  • SOP 包含两个类型,一类是订单问题,一类是物流问题,两类问题分别让第二层的两个大模型分别进行处理。
  • 模拟 3 个订单,分别是 123、456、789,再分别模拟 3 个地址,西城区、海淀区、东城区,把订单和地址信息保存在 TXT 文件,智能客服可以根据客户要求修改地址。

6. 两类问题用决策树的方式描述,当意图识别之后,决策树和用户提问一起提交给第二层的符合意图的大模型处理,并给客户回复,要多轮对话,直到客户满意。

7. 请生成 Python 代码,用一个 Python 文件即可。

4.4 方案原型

执行代码生成任务示例,等待几分钟之后,可运行的智能客服原型系统搭建完成,通过原型系统,可以进行订单查询、物流查询、地址变更等常规问答。

4.4.1 代码示例

import json
import os
import re
import uuid
import boto3

# AWS Configuration
AWS_REGION = "us-west-2"
MODEL_ID = "us.amazon.nova-lite-v1:0"  
# us.amazon.nova-lite-v1:0 
# us.writer.palmyra-x5-v1:0
# us.amazon.nova-premier-v1:0
# us.deepseek.r1-v1:0

def create_bedrock_runtime_client(region: str = AWS_REGION):
    """Create and return a Bedrock client."""
    return boto3.client('bedrock-runtime', region_name=region)

# File to store order and address information
ORDER_DATA_FILE = "order_data.txt"

# Decision trees for different issue types
ORDER_DECISION_TREE = """
# Order Issues Decision Tree
1. Order Status
   1.1. Where is my order? -> Check order status using order ID
2. Order Modification
   2.1. Can I modify/delete my order? -> Check if order is still processing
   2.3. I want to add items to my order -> Check if order is still processing
"""

LOGISTICS_DECISION_TREE = """
# Logistics Issues Decision Tree
1. Package Location Inquiries
   1.2. Package exceeds estimated delivery time
      1.2.1. Check package tracking on carrier website
         1.2.1.1. Exceeds ETA by <7 days -> Suggest waiting 2-3 more days
         1.2.1.2. Exceeds ETA by >7 days with tracking updates -> Suggest waiting 2-3 days and contacting carrier
            1.2.1.2.1. Customer unwilling to wait -> Offer 100 points compensation
            1.2.1.2.2. Customer highly upset -> Offer 100% store credit (final offer: 100% cash refund)
         1.2.1.3. Exceeds ETA by >7 days with no tracking updates -> Offer 100% store credit or resend options
   1.3. Tracking shows no updates for 4+ days
      1.3.1. Still within ETA -> Escalate to logistics team for investigation
      1.3.2. Exceeds ETA -> Follow "Package exceeds estimated delivery time" process
   1.4. Failed delivery attempts
      1.4.1. Middle East regions -> Confirm delivery info, request GPS link, register for redelivery
      1.4.2. Other regions -> Confirm delivery info, suggest keeping phone available, provide carrier contact
   1.5. Package returned to sender
      1.5.1. Delivery address matches system -> Prioritize reshipment or offer 100% store credit
      1.5.2. Delivery address incorrect -> Offer 50-100% store credit or resend options

2. Delivery Address
   2.1. change delivery address -> Update address if order not shipped
   2.3. Address verification -> Confirm address details

3. Package Marked as Delivered but Not Received
   3.1. Check for whole package not received or missing items
      3.1.1. Share with customer and verify address
      3.3.1. First-time customer
         3.3.1.1. Address correct -> Offer resend or 100% cash refund
         3.3.1.2. Address incorrect -> Offer 50% store credit (final: resend or 100% cash refund)
      3.3.2. Returning customer
         3.3.2.1. Address correct & order <$200 -> Offer 100% store credit
         3.3.2.2. Address incorrect & order <$200 -> Offer 50% store credit
         3.3.2.3. Order >$200 -> Escalate to team lead

5. Package Awaiting Pickup
   5.1. Verify if customer received pickup notification
   5.2. Provide carrier contact info for pickup details

6. Combined Packages with Missing Items
   6.1. Offer options:
      6.1.1. Arrange reshipment
      6.1.2. Provide 100% store credit (6-month validity)
      6.1.3. If customer rejects both -> Offer 100% cash refund

Note: Special considerations
- Do not offer resend if customer already paid customs duty
- For BNPL payment methods (Klarna/Afterpay), emphasize store credit is not real money
- For orders >$200 with special circumstances, escalate to team lead
"""

# Sample order data
INITIAL_ORDER_DATA = [
    {"order_id": "123", "customer_name": "Alice Chen", "items": ["T-shirt", "Jeans"], "address": "Xicheng District, Beijing", "status": "Processing"},
    {"order_id": "456", "customer_name": "Bob Wang", "items": ["Dress", "Shoes"], "address": "Haidian District, Beijing", "status": "Shipped"},
    {"order_id": "789", "customer_name": "Charlie Liu", "items": ["Jacket", "Hat"], "address": "Dongcheng District, Beijing", "status": "Delivered"}
]

class CustomerServiceSystem:
    def __init__(self):
        """Initialize the customer service system."""
        self.bedrock_runtime = create_bedrock_runtime_client()  # Use actual Bedrock client
        self.conversation_history = {}
        self.initialize_order_data()
    
    def initialize_order_data(self):
        """Initialize order data file if it doesn't exist."""
        if not os.path.exists(ORDER_DATA_FILE):
            with open(ORDER_DATA_FILE, 'w') as file:
                json.dump(INITIAL_ORDER_DATA, file, indent=2)
            print(f"Initialized order data in {ORDER_DATA_FILE}")
    
    def get_order_data(self):
        """Read order data from file."""
        try:
            with open(ORDER_DATA_FILE, 'r') as file:
                return json.load(file)
        except Exception as e:
            print(f"Error reading order data: {str(e)}")
            return INITIAL_ORDER_DATA
    
    def save_order_data(self, order_data):
        """Save order data to file."""
        try:
            with open(ORDER_DATA_FILE, 'w') as file:
                json.dump(order_data, file, indent=2)
            print("Order data saved successfully")
        except Exception as e:
            print(f"Error saving order data: {str(e)}")
    
    def update_address(self, order_id, new_address):
        """Update the address for a specific order."""
        order_data = self.get_order_data()
        updated = False
        
        for order in order_data:
            if order["order_id"] == order_id:
                old_address = order["address"]
                order["address"] = new_address
                updated = True
                print(f"Updated address for order {order_id} from '{old_address}' to '{new_address}'")
                break
        
        if updated:
            self.save_order_data(order_data)
            return True
        return False
    
    def get_order_info(self, order_id):
        """Get information for a specific order."""
        order_data = self.get_order_data()
        
        for order in order_data:
            if order["order_id"] == order_id:
                return order
        return None
    
    def recognize_intent(self, user_question):
        """First layer: Recognize the intent of the user's question."""
        try:
            # Prepare the prompt for intent recognition
            prompt = f"""
            Intent recognition system for fashion e-commerce customer service.
            Analyze the following customer question and determine if it's related to:
            1. ORDER ISSUES (order status, modifications, problems, or payment)
            2. LOGISTICS ISSUES (delivery address, shipping method, delivery problems)
            
            Previous conversation:
            Customer Question: {user_question}
            ONLY RESPOND WITH THE INTENT KEYWORD: ORDER or LOGISTICS
            DO NOT RESPOND WITH A FULL SENTENCE.
            """
            
            # print(f"Intent recognition prompt: {prompt}")
            
            response = self.bedrock_runtime.converse(
                modelId=MODEL_ID,
                messages=[
                    {
                        "role": "user",
                        "content": [
                            {
                                "text": prompt
                            }
                        ]
                    }
                ]
            )
            
            intent_text = response['output']['message']['content'][0]['text'].strip().upper()
            print(f'Intent recognition response: {intent_text}')
            
            # Extract just the intent keyword
            if "ORDER" in intent_text:
                return "ORDER"
            elif "LOGISTICS" in intent_text:
                return "LOGISTICS"
            else:
                return "UNKNOWN"
                
        except Exception as e:
            print(f"Error in intent recognition: {str(e)}")
            return "UNKNOWN"
    
    def process_order_issue(self, user_question, conversation_id):
        """Second layer: Process order-related issues."""
        try:
            # Get conversation history
            history = self.conversation_history.get(conversation_id, [])
            history_text = "\n".join([f"{'Customer' if i%2==0 else 'Agent'}: {msg}" for i, msg in enumerate(history)])
            # print(f"Conversation history: {history_text}")
            
            # Extract order ID and check for address change request
            order_id_match = re.search(r'order\s+(?:id\s+)?(?:number\s+)?(?:#\s*)?(\d+)', user_question, re.IGNORECASE)
            address_change_match = re.search(r'change\s+(?:my\s+)?address', user_question, re.IGNORECASE)
            new_address_match = re.search(r'(?:to|new address|address to)\s+([^\.]+)(?:\.|\?|$)', user_question, re.IGNORECASE)
            order_info_text = ""
            
            if order_id_match:
                order_id = order_id_match.group(1)
                order_info = self.get_order_info(order_id)
                if order_info:
                    if new_address_match and (address_change_match or "change" in user_question.lower()):
                        if order_info["status"] == "Processing":
                            new_address = new_address_match.group(1).strip()
                            self.update_address(order_id, new_address)
                            order_info = self.get_order_info(order_id)  # Refresh order info after update
                            order_info_text = (
                                f"I found your order and updated the address. Here are the current details:\n"
                                f"- Order ID: {order_info['order_id']}\n"
                                f"- Customer: {order_info['customer_name']}\n"
                                f"- Items: {', '.join(order_info['items'])}\n"
                                f"- Status: {order_info['status']}\n"
                                f"- Delivery Address: {order_info['address']}\n\n"
                                f"The delivery address has been successfully updated since the order is still being processed.\n"
                            )
                            print(order_info_text)
                        else:
                            order_info_text = (
                                f"I found your order, but I cannot change the address as it has already been {order_info['status'].lower()}:\n"
                                f"- Order ID: {order_info['order_id']}\n"
                                f"- Customer: {order_info['customer_name']}\n"
                                f"- Items: {', '.join(order_info['items'])}\n"
                                f"- Status: {order_info['status']}\n"
                                f"- Delivery Address: {order_info['address']}\n\n"
                                f"Address changes are only possible for orders that are still being processed.\n"
                            )
                    elif address_change_match or "change" in user_question.lower():
                        if order_info["status"] == "Processing":
                            order_info_text = (
                                f"I found your order. Let me confirm the current details:\n"
                                f"- Order ID: {order_info['order_id']}\n"
                                f"- Customer: {order_info['customer_name']}\n"
                                f"- Items: {', '.join(order_info['items'])}\n"
                                f"- Status: {order_info['status']}\n"
                                f"- Delivery Address: {order_info['address']}\n\n"
                                f"Since your order is still being processed, I can help you change the address. "
                                f"Please provide the new address you'd like to use.\n"
                            )
                        else:
                            order_info_text = (
                                f"I found your order, but I cannot change the address as it has already been {order_info['status'].lower()}:\n"
                                f"- Order ID: {order_info['order_id']}\n"
                                f"- Customer: {order_info['customer_name']}\n"
                                f"- Items: {', '.join(order_info['items'])}\n"
                                f"- Status: {order_info['status']}\n"
                                f"- Delivery Address: {order_info['address']}\n\n"
                                f"Address changes are only possible for orders that are still being processed.\n"
                            )
                    else:
                        # Regular order info display
                        order_info_text = (
                            f"I found your order. Let me confirm the details:\n"
                            f"- Order ID: {order_info['order_id']}\n"
                            f"- Customer: {order_info['customer_name']}\n"
                            f"- Items: {', '.join(order_info['items'])}\n"
                            f"- Status: {order_info['status']}\n"
                            f"- Delivery Address: {order_info['address']}\n\n"
                        )
            
            # Check if the question contains item-related keywords
            items_mentioned = []
            order_data = self.get_order_data()
            for order in order_data:
                for item in order['items']:
                    if item.lower() in user_question.lower():
                        items_mentioned.append((order, item))

            # If items are mentioned but no order ID, confirm with the user
            if items_mentioned and not order_id_match:
                item_confirmations = []
                for order, item in items_mentioned:
                    item_confirmations.append(
                        f"I noticed you mentioned {item}. I found it in order #{order['order_id']}:\n"
                        f"- Customer: {order['customer_name']}\n"
                        f"- Status: {order['status']}\n"
                        f"- All items in this order: {', '.join(order['items'])}\n"
                    )
                order_info_text = "\n".join(item_confirmations) + "\n"

            # Prepare the prompt for the order issues model
            prompt = f"""
            Customer service agent for order issues.
            
            {order_info_text}
            
            Decision tree for handling order issues:
            {ORDER_DECISION_TREE}
            
            Previous conversation:
            {history_text}
            
            Customer's question: {user_question}

            PLEASE FOLLOW THE DECISION TREE AND DO NOT RESPOND RAMDOMLY.

            IF NOT SURE WITH OBJECT IN QUESTION, PLEASE ASK THE CUSTOMER FOR MORE DETAILS.

            THIS is INSTANT MESSAGING, PLEASE RESPOND AS SHORT AS POSSIBLE.

            DONT SAY BEST REGARDS.

            DONT RESPOND AS CUSTOMER

            """
            
            response = self.bedrock_runtime.converse(
                modelId=MODEL_ID,
                messages=[
                    {
                        "role": "user",
                        "content": [
                            {
                                "text": prompt
                            }
                        ]
                    }
                ]
            )
            
            return response['output']['message']['content'][0]['text']
            
        except Exception as e:
            print(f"Error processing order issue: {str(e)}")
            return "I'm sorry, I'm having trouble processing your order question. Could you please try again?"
    
    def process_logistics_issue(self, user_question, conversation_id):
        """Second layer: Process logistics-related issues."""
        try:
            # Get conversation history
            history = self.conversation_history.get(conversation_id, [])
            history_text = "\n".join([f"{'Customer' if i%2==0 else 'Agent'}: {msg}" for i, msg in enumerate(history)])
            
            # Extract order ID if present in the question
            order_id_match = re.search(r'order\s+(?:id\s+)?(?:number\s+)?(?:#\s*)?(\d+)', user_question, re.IGNORECASE)
            order_info_text = ""
            
            # Check for address change request
            address_change_match = re.search(r'change\s+(?:my\s+)?address', user_question, re.IGNORECASE)
            new_address_match = re.search(r'(?:to|new address|address to)\s+([^\.]+)(?:\.|\?|$)', user_question, re.IGNORECASE)
            
            if order_id_match:
                order_id = order_id_match.group(1)
                order_info = self.get_order_info(order_id)
                
                if order_info:
                    # Add confirmation of order details in the response
                    order_info_text = (
                        f"I found your order. Let me confirm the details:\n"
                        f"- Order ID: {order_info['order_id']}\n"
                        f"- Customer: {order_info['customer_name']}\n"
                        f"- Items: {', '.join(order_info['items'])}\n"
                        f"- Status: {order_info['status']}\n"
                        f"- Delivery Address: {order_info['address']}\n\n"
                    )
                    
                    # Process address change if requested
                    if address_change_match and new_address_match and order_info["status"] == "Processing":
                        new_address = new_address_match.group(1).strip()
                        self.update_address(order_id, new_address)
                        order_info_text += f"I've updated the delivery address to: {new_address}\n\n"

            # Check if the question contains item-related keywords
            items_mentioned = []
            order_data = self.get_order_data()
            for order in order_data:
                for item in order['items']:
                    if item.lower() in user_question.lower():
                        items_mentioned.append((order, item))

            # If items are mentioned but no order ID, confirm with the user
            if items_mentioned and not order_id_match:
                item_confirmations = []
                for order, item in items_mentioned:
                    item_confirmations.append(
                        f"I noticed you mentioned {item}. I found it in order #{order['order_id']}:\n"
                        f"- Customer: {order['customer_name']}\n"
                        f"- Status: {order['status']}\n"
                        f"- All items in this order: {', '.join(order['items'])}\n"
                    )
                order_info_text = "\n".join(item_confirmations) + "\n"
            
            # Prepare the prompt for the logistics issues model
            prompt = f"""
            Customer service agent for logistics issues.
            
            {order_info_text}
            
            Decision tree for handling logistics issues:
            {LOGISTICS_DECISION_TREE}
            
            Previous conversation:
            {history_text}
            
            Customer's question: {user_question}

            PLEASE FOLLOW THE DECISION TREE AND DO NOT RESPOND RAMDOMLY.

            IF NOT SURE WITH OBJECT IN QUESTION, PLEASE ASK THE CUSTOMER FOR MORE DETAILS.

            THIS is INSTANT MESSAGING, PLEASE RESPOND AS SHORT AS POSSIBLE.
            
            DONT SAY BEST REGARDS

            DONT RESPOND AS CUSTOMER
            """
            
            response = self.bedrock_runtime.converse(
                modelId=MODEL_ID,
                messages=[
                    {
                        "role": "user",
                        "content": [
                            {
                                "text": prompt
                            }
                        ]
                    }
                ]
            )
            
            return response['output']['message']['content'][0]['text']
            
        except Exception as e:
            print(f"Error processing logistics issue: {str(e)}")
            return "I'm sorry, I'm having trouble processing your logistics question. Could you please try again?"
    
    def process_question(self, user_question, conversation_id=None):
        """Process a customer question through the two-layer model system."""
        # Generate a conversation ID if not provided
        if not conversation_id:
            conversation_id = str(uuid.uuid4())
        
        # Store the user question in conversation history
        if conversation_id not in self.conversation_history:
            self.conversation_history[conversation_id] = []
        self.conversation_history[conversation_id].append(user_question)
        
        # First layer: Intent recognition
        intent = self.recognize_intent(user_question)
        # print(f"Recognized intent: {intent}")
        
        # Second layer: Process based on intent
        if intent == "ORDER":
            response = self.process_order_issue(user_question, conversation_id)
        elif intent == "LOGISTICS":
            response = self.process_logistics_issue(user_question, conversation_id)
        else:
            response = "I'm not sure if your question is about an order or logistics issue. Could you please provide more details?"
        
        # Store the response in conversation history
        self.conversation_history[conversation_id].append(response)
        
        return response, conversation_id

def interactive_session():
    """Run an interactive session with the customer service system."""
    system = CustomerServiceSystem()
    conversation_id = None
    
    print("Welcome to Fashion E-commerce Customer Service!")
    print("You can ask questions about your orders or logistics.")
    print("Type 'exit' to end the conversation.")
    print("\nAvailable test orders: 123, 456, 789")
    print("-" * 50)
    
    while True:
        user_input = input("\nCustomer: ")
        if user_input.lower() == 'exit':
            print("Thank you for using our customer service. Goodbye!")
            break
        
        response, conversation_id = system.process_question(user_input, conversation_id)
        print(f"\nAgent: {response}")

if __name__ == "__main__":
    # Create the order data file
    system = CustomerServiceSystem()
    
    print("\nStarting interactive customer service session:")
    interactive_session()

代码生成任务完成之后,我们可以通过 Cline 使用大模型,分析代码的详细调用架构,一目了然地掌握代码的整体逻辑,帮助快速检查代码是否符合提示词描述的业务需求。

4.4.2 输入输出示例

针对不同的大模型,通过提出相同的问题,我们可以观察到不同的大模型对于意图识别的能力和回答问题的风格,有哪些区别,不同的大模型在多轮对话中的表现有哪些差异。

4.4.2.1 Nova Premier

Available test orders: 123, 456, 789
--------------------------------------------------

Customer: What is status of order 123?
Intent recognition response: ORDER

Agent: Your order 123 is currently in Processing status.

Customer: Can I change order 123 address to Chao yang, beijing?
Intent recognition response: LOGISTICS

Agent: I can update the address if the order hasn't shipped yet. Let me check.

Customer: order 123 is currently in Processing status                                                     
Intent recognition response: ORDER

Agent: Address updated to Chao yang, Beijing.

Customer: and another order 456 showed delievered, but I didn't get it
Intent recognition response: LOGISTICS
Intent recognition response: LOGISTICS

Agent: I'm sorry to hear that. Let's verify if the entire package or items are missing. Can you confirm?

Customer: Intent recognition response: LOGISTICS

Agent: Is the delivery address correct for order 456?

Customer: Yes address is correct
Intent recognition response: LOGISTICS

Agent: Since the address is correct, I'll offer a resend or 100% cash refund.

Bob, since the address is correct, we can resend the order or issue a 100% cash refund. Which do you prefer? 

Customer: I prefer 100% cash refund
Intent recognition response: ORDER

Agent: Refund processed for order 456. Expect it in 3-5 business days.

Customer: OK, thanks
Intent recognition response: ORDER OR LOGISTICS

SINCE THE PROVIDED CUSTOMER QUESTION "OK, THANKS" DOES NOT GIVE ENOUGH CONTEXT TO DETERMINE IF IT IS RELATED TO ORDER ISSUES OR LOGISTICS ISSUES, WE CANNOT DEFINITIVELY CATEGORIZE IT BASED ON THE GIVEN INFORMATION. THE PHRASE COULD BE A RESPONSE TO EITHER TYPE OF ISSUE. THEREFORE, WITHOUT ADDITIONAL CONTEXT FROM THE CONVERSATION, IT IS NOT POSSIBLE TO ACCURATELY ASSIGN A SINGLE INTENT.

HOWEVER, IF FORCED TO CHOOSE BASED ON THE GIVEN INSTRUCTION AND THE LACK OF CONTEXT, I WOULD REFRAIN FROM MAKING AN ASSUMPTION. THE CORRECT APPROACH WOULD BE TO SEEK MORE INFORMATION BEFORE CLASSIFYING THE INTENT.

**ANSWER:**
NOT DETERMINABLE FROM THE GIVEN INFORMATION.

Agent: You're welcome! If you have more questions, feel free to ask.

4.4.2.2 Palmyra X5

Available test orders: 123, 456, 789
--------------------------------------------------
Customer: What is status of order 123?
Intent recognition response: ORDER

Agent: The status of your order 123 is "Processing". It is being prepared for shipment. Would you like to know the estimated delivery time or make any changes to your order?

Customer: Can I change order 123 address to Chao yang, beijing?
Intent recognition response: LOGISTICS

Agent: To change the delivery address, I need to check if the order has shipped. Currently, it's still "Processing". Let me check with our system.

Order 123 has not been shipped yet, so I can update the delivery address for you. The new address will be Chao yang, Beijing, right?

Customer: YES
Intent recognition response: SINCE THERE'S NO CUSTOMER QUESTION PROVIDED TO ANALYZE, I'LL ASSUME A HYPOTHETICAL SCENARIO BASED ON THE GIVEN CONTEXT.

TO FOLLOW THE INSTRUCTIONS, I'LL DIRECTLY RESPOND WITH THE INTENT KEYWORD BASED ON A GENERIC UNDERSTANDING.

IF THE CUSTOMER IS DISCUSSING ISSUES RELATED TO THEIR ORDER (E.G., STATUS, MODIFICATIONS, PROBLEMS, OR PAYMENT), THE RESPONSE SHOULD BE "ORDER". IF THE DISCUSSION REVOLVES AROUND LOGISTICS (E.G., DELIVERY ADDRESS, SHIPPING METHOD, OR DELIVERY ISSUES), IT SHOULD BE "LOGISTICS".

GIVEN THE LACK OF A SPECIFIC CUSTOMER QUESTION, LET'S HYPOTHETICALLY SAY THE CUSTOMER IS INQUIRING ABOUT SOMETHING RELATED TO THEIR "ORDER STATUS."

ORDER

Agent: The delivery address for order 123 has been updated to Chao yang, Beijing. Is there anything else I can help you with regarding this order?

Customer: and another order 456 showed delivered, but I didn't get it
Intent recognition response: LOGISTICS

Agent: For order 456, I'll check. You mentioned it shows as delivered but you didn't receive it. Can you confirm if the whole package is missing or just some items?

Customer: The whole package is missing.
Intent recognition response: LOGISTICS

Agent: Since order 456 is marked as delivered but not received, I'll follow the decision tree. You mentioned the whole package is missing. Can you confirm if the address on the order is correct?

Customer: Yes the address is correct
Intent recognition response: LOGISTICS

Agent: Since order #456 is marked as delivered but not received and the whole package is missing with a correct address, I'll follow the decision tree. The customer is Bob Wang, a returning customer, with an order value not specified.

To proceed, I'll need to check the order value. Can you tell me the total value of order #456?

Customer: $50.
Intent recognition response: ORDER

Agent: For order #456, value is $50, marked as delivered but not received, and the address is correct. I'll check with our system. Since the order value is less than $100, I'll likely initiate an investigation with the shipping carrier. I'll keep you updated on the status.

Customer: OK Thanks.

4.4.2.3 Nova Lite

Available test orders: 123, 456, 789
--------------------------------------------------

Customer: What is status of order 123?
Intent recognition response: ORDER

Agent: Hi Alice, your order 123 is currently processing. It includes a T-shirt and jeans, set to be delivered to Shanghai. If you have any other questions, feel free to ask!

Customer: Intent recognition response: ORDER

Agent: Alice, your order 123 is currently processing. If you need further assistance, feel free to ask!

Customer: Can I change order 123 address to Chao yang, beijing?
Intent recognition response: LOGISTICS

Agent: Agent: Alice, can you confirm if your order 123 has already been shipped? If not, we can update the address to Chao Yang, Beijing.

Customer: order 123 is currently processing
Intent recognition response: ORDER

Agent: Got it, Alice. Since your order 123 is still processing, we can update the address to Chao Yang, Beijing. I'll make the change for you.

Customer: and another order 456 showed delievered, but I didn't get it
Intent recognition response: LOGISTICS

Agent: Hi Bob, I see your order 456 is marked as delivered but you haven't received it. Let's check if the entire package was delivered or if any items are missing. Can you confirm if you received all items?

Customer: I didn't receive all items
Intent recognition response: LOGISTICS

Agent: Let's check if the entire package was delivered or if any items are missing. Can you confirm if you received any items from order 456?

Customer: No I didnt
Intent recognition response: ORDER

Agent: Got it, Bob. I'll escalate this issue to our delivery team to investigate why you didn't receive all items from order 456. We'll get back to you with an update as soon as possible.

Customer: OK Thanks.
Intent recognition response: ORDER

Agent: Agent: You're welcome, Bob. We're here to help. If you need further assistance, feel free to ask!

4.4.2.4 DeepSeek-R1

Available test orders: 123, 456, 789
--------------------------------------------------

Customer: What is status of order 123?
Intent recognition response: ORDER

Agent: 

Status: Processing.

Customer: Can I change order 123 address to Chao yang, beijing?
Intent recognition response: LOGISTICS

Agent: 

Checking shipping status...  
Order not shipped yet. Address updated to Chao Yang, Beijing.

Customer: and another order 456 showed delievered, but I didn't get it
Intent recognition response: LOGISTICS

Agent: 

"Confirming delivery to Haidian District, Beijing. Is address correct?"

Customer: Yes the address is correct
Intent recognition response: LOGISTICS

Agent: 

"Offer resend or 100% cash refund."

Customer: I want 100% cash
Intent recognition response: ORDER

Agent: 

"Processing 100% cash refund for order 456. Funds released within 3-5 business days."
  • Nova Premier
    • 风格:中性、流程驱动,强调规则遵循(如按决策树执行退款/补发)。严格按决策树执行,逻辑清晰。
    • 示例:在退款场景中明确说明“3-5 business days”。
    • 窗口:1M
  • Palmyra X5
    • 风格:交互式、信息收集导向,倾向于提问以完善决策(如询问订单价值)。分步骤验证,注重风险控制(如低价值订单需调查物流)。
    • 示例:“Can you tell me the total value of order #456?”
    • 窗口:1M
  • Nova Lite
    • 风格:能够应答用户的基本提问,包含客户姓名、订单细节(如商品内容、地址)。对于深层意图的理解有一定主观性。
    • 示例:“Alice, your order 123 includes a T-shirt and jeans.”
    • 窗口:300K
  • DeepSeek-R1
    • 风格:极简、自动化,省略冗余信息,仅提供关键操作结果。全自动化处理,跳过中间确认步骤(如自动更新地址无需客户二次确认),但应答时间较长。
    • 示例:“Processing 100% cash refund for order 456. Funds released within 3-5 business days.”
    • 窗口:128K

总体而言,几个大模型的应答过程中,会各有侧重,都能够自动化完成相关任务,但是根据模型的风格和特点,可以考虑其场景化应用,比如,如果对于合规场景和复杂流程的需求较强,可以考虑 Nova Premier 和 Palmyra X5,如果对于合规场景和复杂流程的需求适中,可以考虑 Nova Lite 和 DeepSeek-R1,另外,依据需要注入大模型的内容规模,选择具备相应的上下文窗口能力大模型,避免推理能力的衰减。根据企业的实际情况,对比各种大模型的应答特征,找到适合自身的应用模式。

5. 总结

本文探讨了快时尚电商行业智能客服系统的设计思路和实现方法,重点介绍了如何利用超长上下文能力快速构建智能客服。文章分析了智能体设计模式,包括功能需求维度、推理策略维度和知识获取维度,并详细阐述了智能客服系统的流程架构和数据管道设计。最后,通过基于 Amazon Bedrock 中的多个模型,展示了如何分钟级快速构建智能客服原型系统。

针对智能客服系统,使用了多个不同的大模型(Nova Premier、Palmyra、Nova Lite、DeepSeek-R1),通过具体对话示例,对应答效果进行了对比分析。

在未来的工作中,我们将进一步探讨如何运用不同类型的框架和工具构建智能客服系统,以应对不同类型的客户需求。同时,我们将进一步探讨 LangChain/LangGraph 框架和 MCP(Model Context Protocol)协议的应用场景,以及 Prompt Caching 带来的成本收益,从而提升开发效率,优化运营成本。


*前述特定亚马逊云科技生成式人工智能相关的服务仅在亚马逊云科技海外区域可用,亚马逊云科技中国仅为帮助您了解行业前沿技术和发展海外业务选择推介该服务。

本篇作者

张羽

亚马逊云科技解决方案架构师

赵安蓓

亚马逊云科技解决方案架构师,负责基于亚马逊云科技的解决方案咨询和设计,机器学习 TFC 成员。在数据处理与建模领域有着丰富的实践经验,特别关注医疗领域的机器学习工程化与运用。