前端进阶之旅前端进阶之旅
基础篇
进阶篇
高频篇
精选篇
手写篇
面经篇
AI 篇
原理篇
每日一题
小程序题库
知识卡片
  • 场景篇按分类整理的大前端场景考点
  • 历年面经按年份追踪真实考点
  • 算法题库NEW在线编码即时判题
  • 专项自测100 题快速查漏
  • 前端基础
    • HTTP从报文一路讲到 HTTPS
    • 浏览器渲染、事件循环、进程
    • 计算机基础Linux、网络、操作系统
  • 进阶专项
    • 设计模式23 种模式怎么用
    • 前端系统进阶学习大型项目工程化
    • 前端综合文章长期沉淀的实践文
  • 工程与工具
    • Node学习指南从环境搭建到服务端
    • NPM工作流script、依赖与发布
    • Docker容器化部署上手
    • Canvas图形与动画实战
  • 路线与导图
    • 思维导图知识点全景图
    • 学习路线按图索骥不跑偏
  • 动态
    • 公众号动态公众号历史文章
    • 博客动态站长的技术博客
    • 开发者导航常用工具与文档站
  • AI 助手随时提问,即时解析
  • AI 模拟面试模拟真实面试 + 报告
  • AI 知识地图串起全站知识点
  • AI 定制路线按你的简历现排
AI 热点
旧版
基础篇
进阶篇
高频篇
精选篇
手写篇
面经篇
AI 篇
原理篇
每日一题
小程序题库
知识卡片
  • 场景篇按分类整理的大前端场景考点
  • 历年面经按年份追踪真实考点
  • 算法题库NEW在线编码即时判题
  • 专项自测100 题快速查漏
  • 前端基础
    • HTTP从报文一路讲到 HTTPS
    • 浏览器渲染、事件循环、进程
    • 计算机基础Linux、网络、操作系统
  • 进阶专项
    • 设计模式23 种模式怎么用
    • 前端系统进阶学习大型项目工程化
    • 前端综合文章长期沉淀的实践文
  • 工程与工具
    • Node学习指南从环境搭建到服务端
    • NPM工作流script、依赖与发布
    • Docker容器化部署上手
    • Canvas图形与动画实战
  • 路线与导图
    • 思维导图知识点全景图
    • 学习路线按图索骥不跑偏
  • 动态
    • 公众号动态公众号历史文章
    • 博客动态站长的技术博客
    • 开发者导航常用工具与文档站
  • AI 助手随时提问,即时解析
  • AI 模拟面试模拟真实面试 + 报告
  • AI 知识地图串起全站知识点
  • AI 定制路线按你的简历现排
AI 热点
旧版
返回 AI 情报前线
All News · 全部资讯9301
  • Linux 7.2 稳定版发布:I/O 性能优化、AMD/Intel 显卡驱动改进
  • 2026年8月AI基础设施与推理平台定价对比:18款工具每日更新
  • EU AI Act水印规定生效:AI生成内容标记可被伪造吗
  • Java 21 + Spring Boot + React 19 构建AI提示词管理平台
  • 30个AI API价格实测:价差高达350倍
  • 向量数据库深度解析与DataLoader实现
  • Pizza-Builder 法则:结构化提示词设计避免 AI 反复猜错
  • Anthropic API Prompt Cache深度分析:22%命中率才回本
  • AI Agent 自报完成不可信:两种独立验证方法
  • AI生成代码的隐性风险:我们正在交付看不见的假设
  • Python 内容审核:Schema 门控批量分类 + 人工复核队列
  • Anthropic Claude 大规模宕机,多项服务受影响
  • 生产环境 LLM 选型:别只看基准分,场景上下文才是关键
  • AI写的汇编不可信:三行命令验证真伪
  • 崩溃路由迷信 0.97 置信度:单点模型决策的风险
  • AI编程代理55种低层代码失败案例与124个修复技能
  • TTFT 与 TTFB 的区别:45 个 AI API 四区域实测数据
  • Gemini 3.7 Flash 发布:编程+Agent 能力大幅提升,价格腰斩
  • LLM Agent 重试机制的可观测性设计实践
  • Qwen 3.8 27B 发布:本地运行出色但默认过度思考
  • 客服AI智能体架构详解:从问答型到工作流执行型
  • Anthropic在Claude输出中嵌入水印引发写作伦理争议
  • 免费AI接口429错误被吞?用Relay转发元数据
  • 用AI高效写API文档的5个实战技巧
  • 我用Python写了个检测硬编码密钥的CLI工具
  • Stripe超70亿美元收购AI网关OpenRouter
  • AI Agent盘活多仓库遗留项目:OpenCode+SpecKit实战
  • AI Agent五层架构详解:Graph Engineering为何是缺失的那环
  • GhostSplice攻击:利用MCP协议碎片化提示窃取SSH密钥
  • 本地优先AI宣言:模型主权与隐私保护新思路
  • 紧急:SharePoint认证绕过漏洞CVE-2026-55040正被积极利用
  • Agent的State、Memory、Checkpointing不是一回事
  • 受监管行业LLM基础设施检查清单
  • 无限画布性能架构:视口虚拟化与空间索引
  • AI 编程 Agent 的 harness 才是决定因素:同一模型最大 23.8 分差距来自它
  • OpenCode 源码解读:MIT 开源 AI Agent Harness 内部机制全解析
  • AI Coding Agent 的 prompt 格式正在标准化:规则/流程/记忆如何引导代码修改
  • Same input, same receipt:让 AI 基准测试结果可验证、可复现
  • Claude Mythos + Project Glasswing 已发现超一万个高危漏洞
  • GraphQL N+1 排查新法:数 Resolver 调用次数而非响应延迟
  • Grok 4.6:后训练优化突破Scaling Law,成本不变性能跃升
  • 用免费模型从数据库迁移文件自动生成Seed数据,告别手写Fixture
  • AI生成服务的安全审计:systemd能力边界检查实战
  • Attention机制原理深度解析:逐行代码讲解Transformer核心
  • 2026年AI API成本实测:开源开发者的省钱指南
  • 9个多模态API实战对比:成本与效果实测
  • Kimi K3的2.8T参数不是最难部分:MoE推理系统工程分析
  • 做AI产品别先上RAG:汽车检测AI架构教训
  • 向量检索的精确匹配盲区:RAG检索架构补全方案
  • AI日报:DeepSeek调价、智谱发布最强代码模型、Anthropic隐藏模型
  • AI生成文本中的隐藏字符:零宽空格等陷阱
  • 已加载 51 / 9301
8.0
热点
AI SCORE
技术实践2026-08-17 05:59

客服AI智能体架构详解:从问答型到工作流执行型

dev.to · AI#AI Agent#工作流#架构设计
Editor brief · 编辑速览

解析生产级AI客服agent核心架构,区分intent分类、tool执行、response生成三阶段,提供完整Python异步循环代码示例,重点讲解tool-use层的工程实现细节。

文章思维导图
Knowledge map
拖拽缩放
Full translation

完整中文译文

大多数客服 AI 实现只回答问题。它们从知识库中检索相关信息,综合出一个回复,然后把对话交还客户。

这叫聊天机器人。2026 年的好聊天机器人,但仍然是聊天机器人。

一个能执行工作流的客服 Agent 做的不同。它处理退款。它更新账户。它触发退货标签。它在相关系统中完成客户要求的事情,并在完成后发送确认。区别不在于模型,而在于模型周围的架构,特别是工具调用层以及连接它的所有部分是如何设计的。

这是我们在生产环境中使用的客服 Agent 架构。这是大多数教程跳过的部分。

核心架构转变

问答 Agent 只有一个主要操作:检索上下文、生成回复。循环很简单。

工作流执行 Agent 有三个:分类意图、执行工具、生成回复。中间步骤是生产级复杂度的所在。

下面是管理一切的 Agent 循环:

from anthropic import AsyncAnthropic
from typing import Optional
import asyncio

client = AsyncAnthropic()

async def agent_loop(conversation: Conversation) -> AgentResponse:
    # Step 1: Classify customer intent
    intent = await classify_intent(
        message=conversation.latest_message,
        history=conversation.history
    )

    # Step 2: Retrieve customer context from backend systems
    context = await retrieve_context(
        customer_id=conversation.customer_id,
        intent=intent
    )

    # Step 3: Plan actions based on intent + context
    action_plan = await plan_actions(
        intent=intent,
        context=context,
        policy=load_policy(intent.type)
    )

    # Step 4: Execute tools if the intent requires action
    tool_results = {}
    if action_plan.requires_tools:
        tool_results = await execute_tools(action_plan.tools)

        # Check escalation conditions before proceeding
        if should_escalate(tool_results, intent, context):
            return await escalate_to_human(
                conversation=conversation,
                context=context,
                tool_results=tool_results,
                reason=determine_escalation_reason(intent, tool_results)
            )

    # Step 5: Generate grounded response from results
    response = await generate_response(
        intent=intent,
        context=context,
        tool_results=tool_results
    )

    # Step 6: Persist updated conversation state
    await persist_context(conversation, response, tool_results)

    return response

与纯检索 Agent 的关键区别:第 4 步对真实系统执行真实操作。Agent 不是在描述应该发生什么,而是在使其发生。

Intent Classification

在任何工具调用发生之前,Agent 需要知道它处理的是哪类请求。Intent 分类决定哪些工具会被考虑,以及哪些策略规则会适用。

INTENT_CATEGORIES = [
    "order_status",
    "return_request",
    "refund_request",
    "account_update",
    "billing_dispute",
    "product_question",
    "complaint",
    "explicit_escalation"
]

async def classify_intent(message: str, history: list) -> Intent:
    response = await client.messages.create(
        model="claude-sonnet-4-5",
        max_tokens=256,
        system="""Classify the customer message into exactly one intent category.
        Return JSON: {"type": <category>, "confidence": <0-1>, "entities": {}}
        Categories: order_status, return_request, refund_request, account_update,
        billing_dispute, product_question, complaint, explicit_escalation""",
        messages=[
            {"role": "user", "content": f"History: {history[-3:]}\nMessage: {message}"}
        ]
    )
    return Intent.from_json(response.content[0].text)

这里的置信度评分不只用于路由。当 intent 分类置信度低于 0.70 时,这是收紧工具权限范围和降低升级阈值的信号——Agent 对客户实际需求的不确定性更大。

这正是架构与纯检索设计分叉的地方。工具是 Agent 与后端系统、CRM、订单管理、支付处理、客服台之间的接口。

CUSTOMER_SERVICE_TOOLS = [
    {
        "name": "lookup_order",
        "description": "Retrieve current order status, tracking, and line items for a customer order",
        "input_schema": {
            "type": "object",
            "properties": {
                "order_id": {"type": "string"},
                "customer_id": {"type": "string"}
            },
            "required": ["order_id", "customer_id"]
        }
    },
    {
        "name": "process_refund",
        "description": "Initiate a refund for an eligible order within policy parameters",
        "input_schema": {
            "type": "object",
            "properties": {
                "order_id": {"type": "string"},
                "refund_amount": {"type": "number"},
                "reason": {"type": "string"},
                "policy_check_passed": {"type": "boolean"}
            },
            "required": ["order_id", "refund_amount", "reason", "policy_check_passed"]
        }
    },
    {
        "name": "create_return_label",
        "description": "Generate a prepaid return shipping label and initiate return workflow",
        "input_schema": {
            "type": "object",
            "properties": {
                "order_id": {"type": "string"},
                "return_reason": {"type": "string"}
            },
            "required": ["order_id", "return_reason"]
        }
    },
    {
        "name": "update_account_field",
        "description": "Update a customer account detail after identity verification",
        "input_schema": {
            "type": "object",
            "properties": {
                "customer_id": {"type": "string"},
                "field": {"type": "string", "enum": ["email", "address", "phone"]},
                "new_value": {"type": "string"},
                "verified": {"type": "boolean"}
            },
            "required": ["customer_id", "field", "new_value", "verified"]
        }
    }
]

注意 policy_check_passed 和 verified 在退款和账户更新工具中是必填字段。Agent 不能不明确确认策略资格已检查、身份已验证就调用这些工具。这是在工具签名级别强制执行,而不是在 prompt 级别——这是更难绕过的约束。

跨渠道上下文持久化

一个在网页聊天开始对话、通过邮件跟进、然后致电语音客服的客户,不应该在每次交接时重新解释情况。上下文持久化是多渠道支持感觉像一个对话而不是三个独立对话的原因。

from dataclasses import dataclass, field
from typing import Dict, List, Optional, Any

@dataclass
class ConversationContext:
    customer_id: str
    conversation_id: str
    channel: str  # "web_chat" | "email" | "voice" | "whatsapp"

    # Verified information (survives channel switches)
    verified_identity: bool = False
    verified_order_id: Optional[str] = None
    verified_fields: Dict[str, Any] = field(default_factory=dict)

    # Resolution tracking
    attempted_resolutions: List[Dict] = field(default_factory=list)
    current_intent: Optional[str] = None

    # Escalation state
    escalation_reason: Optional[str] = None
    escalation_priority: str = "standard"  # "standard" | "high" | "critical"

    # Cross-channel history
    prior_conversations: List[str] = field(default_factory=list)
    unresolved_issues: List[str] = field(default_factory=list)

async def load_or_create_context(customer_id: str, channel: str) -> ConversationContext:
    # Check for existing unresolved context across channels
    existing = await redis_client.get(f"context:{customer_id}:active")

    if existing:
        context = ConversationContext.from_json(existing)
        context.channel = channel  # Update current channel
        return context

    # Load customer history to pre-populate context
    customer = await crm.get_customer(customer_id)
    return ConversationContext(
        customer_id=customer_id,
        conversation_id=generate_id(),
        channel=channel,
        prior_conversations=customer.recent_conversation_ids,
        unresolved_issues=customer.open_tickets
    )

verified_fields 字典特别重要。当客户在网页聊天中验证了身份,该验证会持久化到语音会话中。新渠道的 Agent 知道哪些已经确认,不会要求客户重新验证。

Escalation 逻辑是生产级质量与 demo 质量区分的地方。错误升级的 Agent 会让客户沮丧。该升级而不升级的 Agent 会造成责任风险。

LEGAL_KEYWORDS = [
    "attorney", "lawyer", "lawsuit", "legal action",
    "sue", "court", "fraud", "chargeback dispute"
]

SECURITY_KEYWORDS = [
    "hacked", "unauthorized", "data breach",
    "identity theft", "fraud", "compromised"
]

def should_escalate(
    tool_results: Dict,
    intent: Intent,
    context: ConversationContext
) -> bool:

    # Hard rules, always escalate regardless of confidence
    if intent.type == "explicit_escalation":
        return True

    if contains_any(context.latest_message, LEGAL_KEYWORDS):
        return True

    if contains_any(context.latest_message, SECURITY_KEYWORDS):
        return True

    # VIP / high-value customer handling
    if context.customer_tier == "enterprise":
        if len(context.attempted_resolutions) >= 2:
            return True

    # Confidence-based escalation
    if intent.confidence < 0.65:
        return True

    if tool_results.get("resolution_confidence", 1.0) < 0.70:
        return True

    # Time and turn limits
    if context.turn_count > 8:
        return True

    if context.elapsed_seconds > 600:
        return True

    return False

企业客户分层升级阈值(>= 2 次尝试 vs 标准 > 8 轮)反映了一项业务决策:高价值客户获得更快的人工接入权限。那条策略写在代码里,而不是 prompt 里,这意味着它是可强制执行和可审计的。

Handoff payload 是大多数 Agent 架构中构建最薄弱的部分。如果接手升级的人类 Agent 必须重新阅读记录并从头重建上下文,那么升级体验比客户一开始就直接打电话给人工还差。

async def escalate_to_human(
    conversation: Conversation,
    context: ConversationContext,
    tool_results: Dict,
    reason: str
) -> AgentResponse:

    # Generate AI summary of conversation for the human agent
    summary = await generate_handoff_summary(conversation, context, tool_results)

    handoff_payload = {
        "conversation_id": conversation.id,
        "customer": {
            "id": context.customer_id,
            "name": context.customer_name,
            "tier": context.customer_tier,
            "lifetime_value": context.customer_ltv,
            "sentiment": context.sentiment_score
        },
        "summary": summary,
        "escalation_reason": reason,
        "escalation_priority": context.escalation_priority,
        "attempted_resolutions": context.attempted_resolutions,
        "verified_context": context.verified_fields,
        "recommended_action": await suggest_next_action(context, tool_results),
        "full_transcript": conversation.messages,
        "open_tickets": context.unresolved_issues
    }

    # Route to appropriate queue based on priority and type
    queue = determine_queue(reason, context.customer_tier)
    ticket_id = await helpdesk.create_escalation(queue, handoff_payload)

    # Inform the customer honest about what's happening
    return AgentResponse(
        message=f"I'm connecting you with a specialist who can help with this. "
                f"They'll have the full context of our conversation "
                f"you won't need to repeat anything. Reference: {ticket_id}",
        action="escalate",
        ticket_id=ticket_id
    )

Payload 中的 recommended_action 字段是显著改变平均处理时间的部分。当人工 Agent 打开案件时,他们得到的是结构化建议,而不是需要重建的记录。AI 没有转移问题,它转移的是一个可决策的包。

这个架构解决不了什么

正确构建这个架构能把 Agent 从问答提升到工作流执行。它解决不了的是工具下面的集成层——让 process_refund() 可靠地连接到你的实际支付处理器、你的实际权限模型、处理你的实际错误状态。

上面的工具签名是有意简化干净的。背后的实现才是生产级复杂度的所在:限流、重试逻辑、当下游 API 在对话中途失败时的熔断、每次写操作的审计日志。

在工具定义和工具在生产负载下正常工作之间的差距,是大多数企业级 Agent 项目要么正确投入、要么发现本应如此的分水岭。

聊天是简单的部分。工作流执行和后端集成才是生产 Agent 成败之所。我们写了完整的构建指南,涵盖完整的八层架构、可靠性模式、成本建模和在规模下摧毁 Agent 的失败模式。

How to Build a 24/7 AI Customer Service Agent, Enterprise Guide

Dextra Labs 为企业客服、金融和运营构建生产级 AI Agent 系统。如果你的 Agent 架构处于集成层且想要技术评审,请联系 hello@dextralabs.com

Original source

本文由 AI 翻译整理自 dev.to · AI,原文版权归原作者所有。

阅读英文原文
上一篇
Qwen 3.8 27B 发布:本地运行出色但默认过度思考
下一篇
Anthropic在Claude输出中嵌入水印引发写作伦理争议