一、传统对账的痛点与 AI 的切入点

在支付业务中,商户对账是一个高频且关键的操作。每天,平台需要将自身的交易记录与银行、第三方支付渠道的账单进行逐笔比对,找出金额不一致、遗漏、重复等异常记录。

传统的自动对账系统依赖预先定义的匹配规则,例如:

问题在于,真实业务场景中的异常类型远比上述规则复杂。例如:渠道侧汇率转换导致的金额差异、跨时区交易时间不匹配、渠道批量合并后拆分不清等。每当出现新的异常模式,都需要开发人员新增匹配规则,维护成本极高。

我们的思路是:让 AI Agent 具备对账领域知识,当规则引擎无法匹配时,将差异数据交给 Agent 进行根因分析和智能推荐

二、MCP Server 工具设计

MCP(Model Context Protocol)是 Anthropic 提出的一种标准化协议,用于让 AI 模型与外部工具和数据源进行交互。我们将对账系统中的核心能力封装为 MCP Server 暴露给 Agent:

{
  "server": "reconciliation-mcp-server",
  "tools": [
    {
      "name": "query_bill_records",
      "description": "查询指定商户在指定时间范围内的账单记录",
      "parameters": {
        "merchantId": { "type": "string", "required": true },
        "startDate": { "type": "string", "format": "date" },
        "endDate": { "type": "string", "format": "date" },
        "status": { "type": "string", "enum": ["matched", "unmatched", "pending"] }
      }
    },
    {
      "name": "query_channel_records",
      "description": "查询渠道侧的交易流水,支持按银行、支付机构过滤",
      "parameters": {
        "channelCode": { "type": "string", "required": true },
        "traceNo": { "type": "string" },
        "timeRange": { "type": "object" }
      }
    },
    {
      "name": "analyze_exchange_rate",
      "description": "分析指定日期和币种对的汇率转换差异",
      "parameters": {
        "fromCurrency": { "type": "string" },
        "toCurrency": { "type": "string" },
        "date": { "type": "string" }
      }
    },
    {
      "name": "generate_reconciliation_report",
      "description": "生成对账差异分析报告,包含根因分类和修复建议",
      "parameters": {
        "merchantId": { "type": "string", "required": true },
        "diffIds": { "type": "array", "items": { "type": "string" } }
      }
    }
  ]
}

MCP Server 的实现基于 Java + Spring Boot,通过 SSE(Server-Sent Events)与 Agent 客户端通信。每个 Tool 对应一个 Spring Bean,内部封装了实际的业务逻辑调用:

@Component
public class QueryBillRecordsTool implements McpTool {
    @Autowired
    private BillQueryService billQueryService;

    @Override
    public String getName() { return "query_bill_records"; }

    @Override
    public ToolResult execute(Map<String, Object> params) {
        String merchantId = (String) params.get("merchantId");
        String startDate = (String) params.get("startDate");
        String endDate = (String) params.get("endDate");

        List<BillRecord> records = billQueryService.query(
            merchantId, startDate, endDate);

        return ToolResult.success(JSON.toJSONString(
            records.stream()
                .map(BillRecord::toSummary)
                .collect(Collectors.toList())
        ));
    }
}

三、远端知识库与 Skill 封装

Agent 仅有工具调用能力是不够的,它还需要具备对账领域的专业知识。为此我们构建了一个远端知识库,包含:

知识库基于向量数据库(Milvus)存储,在 MCP Server 中封装为 search_knowledge_base 工具,当 Agent 分析异常时可以主动检索相关知识:

// Agent 的推理链路示例(简化描述)
// 1. Agent 发现商户 M001 有 5 笔未匹配记录
// 2. 调用 query_bill_records 获取平台侧数据
// 3. 调用 query_channel_records 获取渠道侧数据
// 4. 发现差异集中在跨币种交易
// 5. 调用 search_knowledge_base 检索"跨币种汇率差异"相关案例
// 6. 调用 analyze_exchange_rate 验证汇率差异
// 7. 输出根因分析:渠道侧使用的是当日开盘汇率,平台侧使用的是实时汇率
// 8. 调用 generate_reconciliation_report 生成报告

为了让 Agent 的行为更加可控和可复现,我们将常见的对账分析流程封装为 Skill(技能):

每个 Skill 本质上是一个 Prompt 模板 + 工具调用编排,由 Agent 运行时按需选择和组合。运营人员只需通过自然语言描述需求,Agent 就能自动选择合适的 Skill 来执行。

四、落地效果与思考

系统上线后的核心指标:

在实际落地过程中,我们也踩了一些坑:

总体而言,MCP + Agent 的组合在商户对账场景中展现出了明显的价值。它不是要替代传统的规则引擎,而是在规则引擎无法覆盖的"长尾异常"领域提供了一个智能的补充方案。对于 AI 与传统业务系统的融合,我们的经验是:让 AI 做推理和决策,让传统系统做执行和保障,两者各司其职,才能发挥最大的效能。