掘金 人工智能 前天 08:53
快时尚电商行业智能体设计思路与应用实践(一)借助超长上下文窗口分钟级构建智能客服系统
index_new5.html
../../../zaker_core/zaker_tpl_static/wap/tpl_guoji1.html

 

本文探讨了快时尚电商行业如何通过智能化转型提升客户体验和运营效率。文章重点分析了智能体设计模式,特别是Dynamic Single-Agent模式,并以智能客服系统为例,展示了如何利用Amazon Bedrock和超长上下文窗口技术,快速构建基于企业知识库的智能客服解决方案。通过代码生成任务,实现分钟级部署,加速行业智能化进程。

💡在功能需求维度,智能体设计模式包括Reflection Pattern(自我评估)、Tool Use Pattern(调用外部工具)、Planning Pattern(任务分解)和Multi-Agent Pattern(多智能体协作)。

📡在拓扑结构维度,智能体设计模式分为Static Single-Agent(静态单智能体)、Dynamic Single-Agent(动态单智能体)、Centralized Multi-Agent(集中式多智能体)和Distributed Multi-Agent(分布式多智能体),它们在环境适应性、控制方式和扩展性上各有侧重。

🧠知识获取维度涵盖Model Tuning(模型调优)、Retrieval Augmented Generation(检索增强生成)和Long-Context Windows(超长上下文窗口)。超长上下文窗口技术在处理大规模文本时,能够保留完整的上下文信息,简化流程。

👩‍💻在快时尚电商的智能客服场景中,Dynamic Single-Agent模式结合超长上下文窗口,利用大模型代码生成能力,能够快速构建、迭代和验证系统,简化运维,并优先关注业务优化。

✅SOP(标准操作程序)的语义结构与大模型长上下文窗口技术高度适配,通过将SOP信息直接注入大模型的上下文窗口,能保障动态合规性,降低客服培训成本,并支持多模态协同。

1. 序言

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

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

📢限时插播:无需管理基础设施,利用亚马逊技术与生态,快速集成与部署生成式AI模型能力。

✨ 精心设计,旨在引导您深入探索Amazon Bedrock的模型选择与调用、模型自动化评估以及安全围栏(Guardrail)等重要功能。

⏩快快点击进入《多模一站通 —— Amazon Bedrock 上的基础模型初体验》实验

构建无限, 探索启程!

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

2. 智能体设计模式

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

2.1 功能需求维度

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

2.2 拓扑结构维度

这部分主要包括 Static Single-Agent、Dynamic Single-Agent、Centralized Multi-Agent、Distributed Multi-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(检索增强生成)

优势:

劣势:

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

优势:

劣势:

3. 智能体应用解析

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

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

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

3.1 业务流程

3.1.1 流程图

3.1.2 流程说明与节点用途

3.1.2.1 核心节点及其用途

用户输入节点:

上下文管理器:

服务协调环节:

专业应答环节:

知识共享平台(可选):

SOP(标准操作程序,行业知识):

业务系统:

应答整合环节:

反馈处理环节(可选):

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

3.1.2.2.1 第一轮:初始请求处理

    用户提交一个服务请求,例如:”我购买的衣服有问题,想申请退货”请求首先进入上下文管理器,记录这个初始请求客户服务协调环节接收请求,并从业务系统获取该客户的历史数据服务协调环节分析请求内容,确定这是一个退货请求,需要调用专业应答环节专业应答环节(可能是退货退款专业应答环节)从 SOP 中获取相关的退货退款政策和流程专业应答环节处理完请求后,将结果传递给应答整合环节应答整合环节生成一个结构化、友好的回复,例如:”了解您的衣服问题。根据我们的政策,您购买的衣服,可以申请退货。请您提供订单号。”回复呈现给用户

3.1.2.2.2 第二轮:后续交互

    用户看到回复后,提出后续问题:”但没有包装了,这样可以退吗?”这个问题进入上下文管理器,与之前的对话历史一起存储上下文管理器将完整对话传递给服务协调环节服务协调环节理解这是对之前问题的跟进,继续调用专业应答环节专业应答环节从知识共享平台获取关于退货要求的详细信息专业应答环节处理后,将结果传递给应答整合环节生应答整合环节生成后续回复:”只要衣服完好,包装不是必须的。请您提供订单号,我们会安排退货流程。”回复呈现给用户

3.1.2.2.3 第三轮:对话结束

    用户确认问题已解决:”好的,谢谢,我一会儿发订单号给你。”确认信息进入上下文管理器服务协调环节将对话引导至结束阶段反馈处理环节分析整个对话过程反馈处理环节更新客户数据,记录这次退货请求反馈处理环节同时更新相关系统,优化未来类似问题的处理流程系统生成最终响应:”很高兴能帮到您。收到您的订单号后,我们会立即处理您的退货申请。如有其他问题,随时咨询。祝您有愉快的一天!”最终回复呈现给用户

3.1.2.3 系统优势

3.1.2.4 智能体设计模式分析

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

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

2、Reflection Pattern(反思模式):

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

4、Planning Pattern(规划模式):

3.2 数据管道

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

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

角色与任务定义

规则与流程

业务场景覆盖

内部支持工具

输出与评估

扩展补充项

提示词包含 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)中因分块检索导致的语义割裂。例如:

3.3.2.2 降低幻觉风险

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

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

3.3.3.1 降低客服培训成本

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

3.3.3.2 多模态协同增强

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

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

3.3.4.1 SOP 的语义增强预处理

3.3.4.2 上下文窗口的效能优化

4. 智能体原型演示

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

4.1 环境准备

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

4.2 任务构造

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

4.3 代码生成任务示例

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

    你是一个解决方案架构师,你精通快时尚电商行业的智能客服的架构设计和代码实现,你对智能体涉及模式非常精通,十分清楚各种设计模式的应用场景。对于 us.writer.palmyra-x5-v1:0 的调用方法,请参考文章 aws.amazon.com/blogs/aws/w…。请参考以上代码,利用 us.writer.palmyra-x5-v1:0 模型,编写一个智能客服系统。当客户提出问题之后,SOP 和问题整合成提示词,注入到第一层大模型,负责识别意图。当第一层大模型完成意图识别之后,将 SOP 和意图整合成提示词,注入到第二层大模型,第二层大模型负责回答问题。
    两类问题用决策树的方式描述,当意图识别之后,决策树和用户提问一起提交给第二层的符合意图的大模型处理,并给客户回复,要多轮对话,直到客户满意。请生成 Python 代码,用一个 Python 文件即可。

4.4 方案原型

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

4.4.1 代码示例

import jsonimport osimport reimport uuidimport boto3# AWS ConfigurationAWS_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:0def 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 informationORDER_DATA_FILE = "order_data.txt"# Decision trees for different issue typesORDER_DECISION_TREE = """# Order Issues Decision Tree1. Order Status   1.1. Where is my order? -> Check order status using order ID2. 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 Tree1. 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 options2. Delivery Address   2.1. change delivery address -> Update address if order not shipped   2.3. Address verification -> Confirm address details3. 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 lead5. Package Awaiting Pickup   5.1. Verify if customer received pickup notification   5.2. Provide carrier contact info for pickup details6. 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 refundNote: 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 dataINITIAL_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_iddef 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: ORDERAgent: Your order 123 is currently in Processing status.Customer: Can I change order 123 address to Chao yang, beijing?Intent recognition response: LOGISTICSAgent: 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: ORDERAgent: Address updated to Chao yang, Beijing.Customer: and another order 456 showed delievered, but I didn't get itIntent recognition response: LOGISTICSIntent recognition response: LOGISTICSAgent: I'm sorry to hear that. Let's verify if the entire package or items are missing. Can you confirm?Customer: Intent recognition response: LOGISTICSAgent: Is the delivery address correct for order 456?Customer: Yes address is correctIntent recognition response: LOGISTICSAgent: 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 refundIntent recognition response: ORDERAgent: Refund processed for order 456. Expect it in 3-5 business days.Customer: OK, thanksIntent recognition response: ORDER OR LOGISTICSSINCE 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: ORDERAgent: 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: LOGISTICSAgent: 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: YESIntent 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."ORDERAgent: 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 itIntent recognition response: LOGISTICSAgent: 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: LOGISTICSAgent: 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 correctIntent recognition response: LOGISTICSAgent: 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: ORDERAgent: 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: ORDERAgent: 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: ORDERAgent: 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: LOGISTICSAgent: 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 processingIntent recognition response: ORDERAgent: 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 itIntent recognition response: LOGISTICSAgent: 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 itemsIntent recognition response: LOGISTICSAgent: 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 didntIntent recognition response: ORDERAgent: 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: ORDERAgent: 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: ORDERAgent: Status: Processing.Customer: Can I change order 123 address to Chao yang, beijing?Intent recognition response: LOGISTICSAgent: 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 itIntent recognition response: LOGISTICSAgent: "Confirming delivery to Haidian District, Beijing. Is address correct?"Customer: Yes the address is correctIntent recognition response: LOGISTICSAgent: "Offer resend or 100% cash refund."Customer: I want 100% cashIntent recognition response: ORDERAgent: "Processing 100% cash refund for order 456. Funds released within 3-5 business days."

Nova Premier

Palmyra X5

Nova Lite

DeepSeek-R1

总体而言,几个大模型的应答过程中,会各有侧重,都能够自动化完成相关任务,但是根据模型的风格和特点,可以考虑其场景化应用,比如,如果对于合规场景和复杂流程的需求较强,可以考虑 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 带来的成本收益,从而提升开发效率,优化运营成本。

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

本篇作者

本期最新实验《多模一站通 —— Amazon Bedrock 上的基础模型初体验

✨ 精心设计,旨在引导您深入探索Amazon Bedrock的模型选择与调用、模型自动化评估以及安全围栏(Guardrail)等重要功能。无需管理基础设施,利用亚马逊技术与生态,快速集成与部署生成式AI模型能力。

⏩️[点击进入实验] 即刻开启 AI 开发之旅

构建无限, 探索启程!

Fish AI Reader

Fish AI Reader

AI辅助创作,多种专业模板,深度分析,高质量内容生成。从观点提取到深度思考,FishAI为您提供全方位的创作支持。新版本引入自定义参数,让您的创作更加个性化和精准。

FishAI

FishAI

鱼阅,AI 时代的下一个智能信息助手,助你摆脱信息焦虑

联系邮箱 441953276@qq.com

相关标签

智能体 快时尚电商 智能客服 Amazon Bedrock 大模型
相关文章