2771 lines
129 KiB
Markdown
2771 lines
129 KiB
Markdown
# 货代发货通知 — 完整手册
|
||
|
||
> **唯一技术文档**:货代发货通知相关的部署、Dify 配置、OpenAPI、Agent 指令与运维说明 **仅维护本文件**(`docs/features/shipping-notice/technical.md`),请勿另建分散 md。\
|
||
> **业务操作说明**:[`business.md`](./business.md)(面向货代/跟单等业务人员,无程序与 Dify 内容)。\
|
||
> **同步维护**:流程、字段规则、人工确认节点等变更时,**须同时更新本文件与** **`business.md`**。\
|
||
> **Dify 文档维护原则**:Dify 编排仅在本文件维护,且以**节点级配置**为准;重点维护各节点的职责、输入、输出、条件、Tool 绑定与连线关系,不再额外维护独立 DSL 解读文档。\
|
||
> **当前目标口径**:本文件描述的是 **shipping notice 新方案的目标技术稿**;后端实现统一采用 **Flask**,不使用 FastAPI,但也不回退到旧单 task 现状口径。
|
||
|
||
Hxops **货代发货通知 Agent** 的部署、目标架构、Dify 配置、OpenAPI、多文件批次解析、自动上传与 Agent 指令合集。
|
||
|
||
> **实现策略(强制)**:根据行业最佳实践,优先在 Dify 中实现适合由 AI 编排层承接的能力,包括但不限于 Chatflow / Workflow、Agent、LLM 节点、Code 节点、Tool 节点、If-Else 分流,以及人工确认节点所需的解释、建议与交互编排。对于任务/批次持久化、主状态机、后台续跑、失败恢复、审计留痕、二进制文件处理、RPA/上传回执及外部系统集成等生产级业务职责,统一由 hxops 后端承担。本方案的判断标准不是“Dify 是否能实现”,而是“该能力是否适合由 AI 编排层承接,还是应由业务后端作为真相源与主调度层承接”。
|
||
|
||
**Tool API 基路径**:`/api/shipping-notice`\
|
||
**OpenAPI**:`GET /api/shipping-notice/tools/openapi.json`\
|
||
**鉴权 Header**:`Authorization: Bearer <token>` 或 `X-Integration-Key: <token>`
|
||
|
||
***
|
||
|
||
## 目录
|
||
|
||
1. [业务操作说明(另册)](#业务操作说明另册)
|
||
2. [部署 Runbook](#1-部署-runbook)
|
||
3. [Dify 配置(合集)](#2-dify-配置合集)
|
||
4. [当前与原型对齐状态](#3-当前与原型对齐状态)
|
||
5. [OpenAPI 变更说明](#4-openapi-变更说明)
|
||
6. [相关代码与文件](#5-相关代码与文件)
|
||
|
||
***
|
||
|
||
## 业务操作说明(另册)
|
||
|
||
面向业务人员的流程、字段、确认节点与 FAQ 见 **[`business.md`](./business.md)**。\
|
||
IT / 开发改流程时,请同步更新该文件,避免聊天助手行为与业务培训材料不一致。
|
||
|
||
***
|
||
|
||
## 1. 部署 Runbook
|
||
|
||
### 1.1 数据库迁移
|
||
|
||
```bash
|
||
cd backend
|
||
flask db upgrade
|
||
```
|
||
|
||
### 1.2 环境变量(`.env.dev` 示例)
|
||
|
||
```env
|
||
# hxops 侧 Tool API 根地址(OpenAPI 导出、RPA 回调等;Dify OpenAPI Credential 的 Server URL 应与此一致)
|
||
HXOPS_TOOLS_API_BASE=http://192.168.100.192:8890
|
||
|
||
# 货代 Tool API Key(Dify OpenAPI 工具 Credential、RPA 回调共用;不再注入 Dify Start 变量)
|
||
# 未配置时后端回退 INTEGRATION_API_KEY,建议新环境优先配置专用 key。
|
||
SHIPPING_NOTICE_TOOL_API_KEY=your-tool-key
|
||
# INTEGRATION_API_KEY=your-tool-key
|
||
|
||
# 文件存储
|
||
SHIPPING_NOTICE_STORAGE_ROOT=data/shipping_notice
|
||
|
||
# 库存文本上限(超过则必须 HTTP 上传)
|
||
SHIPPING_NOTICE_INVENTORY_TEXT_MAX_CHARS=80000
|
||
|
||
# RPA 目录
|
||
FREIGHT_INVENTORY_DROP_DIR=data/shipping_notice/freight_rpa/inventory_drop
|
||
FREIGHT_RPA_INVENTORY_TRIGGER_DIR=data/shipping_notice/freight_rpa/inventory_triggers
|
||
FREIGHT_UPLOAD_QUEUE_DIR=data/shipping_notice/freight_rpa/upload_queue
|
||
FREIGHT_RPA_UPLOAD_TRIGGER_DIR=data/shipping_notice/freight_rpa/upload_triggers
|
||
|
||
# 发货 Excel 模板
|
||
FREIGHT_SHIPMENT_TEMPLATE_PATH=templates/freight_shipment_upload.xlsx
|
||
|
||
# 字段对齐确认
|
||
# SHIPPING_NOTICE_INVENTORY_MAPPING_REVIEW=true
|
||
|
||
# 自动推进 / 自动上传
|
||
# SHIPPING_NOTICE_AUTO_PROGRESS_ENABLED=true
|
||
# SHIPPING_NOTICE_AUTO_RPA_INVENTORY_ENABLED=true
|
||
# SHIPPING_NOTICE_AUTO_MAPPING_ALLOW_LLM=true
|
||
# SHIPPING_NOTICE_AUTO_MATCH_ENABLED=true
|
||
# SHIPPING_NOTICE_AUTO_GENERATE_EXCEL_ENABLED=true
|
||
# 真实货代上传 RPA 尚未完成,默认 false;仅 mock 或已接入正式上传 Driver 后再开启。
|
||
# SHIPPING_NOTICE_AUTO_UPLOAD_ENABLED=false
|
||
# SHIPPING_NOTICE_AUTO_CHAIN_FALLBACK=true
|
||
# SHIPPING_NOTICE_EXPORT_FILENAME_PATTERN={task_no}-{date}.xlsx
|
||
|
||
# 建单后延后 parse_notice 到 Dify 画布(默认 true,符合 Dify 编排优先)
|
||
# SHIPPING_NOTICE_DEFER_PARSE_TO_DIFY=true
|
||
|
||
# 批次后台调度:每个批次最多同时派发几张票(默认 3)
|
||
# SHIPPING_NOTICE_BATCH_DISPATCH_CONCURRENCY=3
|
||
|
||
# 单票调用 Dify 解析的总超时(秒,默认 180)
|
||
# SHIPPING_NOTICE_DIFY_PARSE_TIMEOUT_SECONDS=180
|
||
|
||
# 发货后台任务执行模式:worker / sync / manual
|
||
# SHIPPING_NOTICE_TASK_EXECUTION_MODE=worker
|
||
|
||
# RPA 库存导出等待超时(秒,默认 900;DSV 实际链路建议至少 900)
|
||
# SHIPPING_NOTICE_RPA_INVENTORY_TIMEOUT_SECONDS=900
|
||
|
||
# 发货 worker 轮询间隔(秒)
|
||
# SHIPPING_NOTICE_WORKER_POLL_SECONDS=2
|
||
|
||
# 发货后台任务 running 超时回收(秒)
|
||
# SHIPPING_NOTICE_JOB_RUNNING_TIMEOUT_SECONDS=300
|
||
|
||
# 说明:发货通知后台任务写入通用 jobs 表;kb_jobs 仅保留知识库清洗/同步任务。
|
||
|
||
# Dify Chatflow(对话续办)
|
||
SHIPPING_NOTICE_CHAT_DIFY_APP_ID=
|
||
SHIPPING_NOTICE_CHAT_DIFY_API_KEY=
|
||
SHIPPING_NOTICE_CHAT_DIFY_BASE=http://192.168.100.192:8882/v1
|
||
```
|
||
|
||
### 1.3 注册 Agent 记录
|
||
|
||
```bash
|
||
cd backend
|
||
python seed_shipping_notice_agents.py
|
||
```
|
||
|
||
### 1.4 Mock RPA(开发)
|
||
|
||
```powershell
|
||
$env:HXOPS_API_BASE = "http://127.0.0.1:5052"
|
||
$env:SHIPPING_NOTICE_TOOL_API_KEY = "your-tool-key"
|
||
$env:FREIGHT_RPA_MOCK = "true"
|
||
python scripts/rpa/freight_rpa_worker.py
|
||
```
|
||
|
||
### 1.5 前端入口
|
||
|
||
- 聊天界面仍是**主上传入口**,通知附件、库存附件与对话续办都优先在 Chat 完成
|
||
- 聊天页右侧**轻量批次工作台**允许执行当前任务动作,但业务按钮必须直接消费后端 `ui_state.action_buttons`,禁止前端按 `process_status / pending_human_reason` 本地二次推导
|
||
- 独立工作台入口 **货代发货** 仍以只读查看、筛选排查与跳转聊天界面为主,不单独维护第二套业务动作口径
|
||
- **在 Chat 中继续** → `/chat/{agentId}?task_id=SN-...`
|
||
|
||
### 1.6 端到端验证
|
||
|
||
```bash
|
||
cd backend
|
||
pytest tests/test_shipping_notice_tools.py tests/test_shipping_notice_query_service.py tests/test_shipping_notice_batches.py -q
|
||
```
|
||
|
||
### 1.7 待业务提供
|
||
|
||
- 货代系统库存导出 SOP + 样例 Excel 列名
|
||
- 货代上传 SOP + 正式上传模板列映射
|
||
- 生产 Windows RPA 脚本
|
||
- 上传成功 / 失败回执样例
|
||
|
||
***
|
||
|
||
## 2. Dify 画布配置
|
||
|
||
> **维护颗粒度约定**:本章默认以“节点 + 输入/输出 + 条件 + Tool 绑定 + 连线关系”为维护颗粒度。除应用基础信息、OpenAPI 导入和 Agent 指令外,不再额外扩展独立的 DSL 镜像文档;后续变更直接在对应节点小节更新。
|
||
|
||
### 2.1 基本信息
|
||
|
||
| 项 | 值 |
|
||
| ----------- | ---------------------------------------------------------------------------- |
|
||
| Dify 版本 | `1.14.1` |
|
||
| 应用模式 | `advanced-chat` |
|
||
| DSL version | `0.6.0` |
|
||
| OpenAPI 地址 | `http://<host>/api/shipping-notice/tools/openapi.json` |
|
||
| 认证 | `Authorization: Bearer <token>` 或 `X-Integration-Key: <SHIPPING_NOTICE_TOOL_API_KEY>`;未配置专用 key 时回退 `INTEGRATION_API_KEY` |
|
||
|
||
### 2.2 导入后应看到的 Tool
|
||
|
||
#### Agent Runtime Context Tools
|
||
|
||
1. `parse_agent_runtime_context`
|
||
|
||
#### Hxops Shipping Notice Tools
|
||
|
||
1. `parse_notice`
|
||
2. `update_notice_fields`
|
||
3. `update_notice_line`
|
||
4. `add_notice_line`
|
||
5. `remove_notice_line`
|
||
6. `get_inventory_schema_preview`
|
||
7. `apply_inventory_mapping`
|
||
8. `submit_decision`
|
||
9. `get_task_status`
|
||
10. `get_batch_status`
|
||
|
||
当前 Dify 正式职责只包括:通知解析、字段修订、库存映射建议、人工决策提交、任务/批次状态查询与用户解释。
|
||
当前后端 worker 主职责包括:批次派发、自动续跑、库存准备、匹配、生成 Excel、上传货代与 RPA 回写。
|
||
|
||
### 2.2.1 编排职责边界
|
||
|
||
当前文档的主分层方向是合理的,符合行业里对“AI 编排层 + 业务后端真相源”模式的常见做法;但要落地稳定,仍需把下面这些职责边界写死,避免后续画布或前端联调时再次漂移。
|
||
|
||
| 能力 / 阶段 | 默认执行方 | 编排要求 |
|
||
| --- | --- | --- |
|
||
| 用户上传通知、建 batch / task、保存 `raw_text` | Hxops 后端 | Hxops 是任务真相源;Dify 不创建任务,只消费已落库任务 |
|
||
| 首轮通知理解与结构化抽取 | Dify LLM + `parse_notice` | 仅在 `should_parse_notice=true` 时进入;LLM 负责理解,最终落库由 Tool 完成 |
|
||
| 解析结果修订 | Dify 调 `update_notice_*` Tool | 用户用自然语言修单头 / 行项目时,必须落库,不允许只在回答里“口头修正” |
|
||
| 库存 schema 预览与列映射建议 | Dify | 由 Dify 读取本批库存快照预览、生成 `map_json` 建议;Agent 不得绕过固定链路自行脑补库存结构 |
|
||
| 应用库存映射、解析完整库存 | Hxops Tool | Dify 只提交 `map_json`;完整库存解析写入批次库存快照,字段对齐确认后本批各票独立匹配 |
|
||
| 主状态机、checkpoint、人审门 | Hxops 后端 | `checkpoint` / `human_options` / `forbidden_next_tools` 以状态机为准;Dify 只能读取并遵守 |
|
||
| 匹配、生成 Excel、上传货代、RPA 重试 | Hxops worker / RPA workflow | 属于长链路、有副作用、需幂等与重试的生产职责,不由 Dify 同轮串行主导 |
|
||
| 任务解释、下一步建议、人工确认收口 | Dify + `submit_decision` | Dify 负责把后端状态翻译成用户可执行动作;真正状态推进交给 `submit_decision` 与 worker |
|
||
| 批次摘要、聚焦任务、任务切换上下文 | Hxops 后端 + 前端 | `batch.current_focus_task_no` 是当前聚焦任务真相;Dify 只消费该上下文,不自行维护任务队列 |
|
||
|
||
### 2.2.2 回合级编排契约
|
||
|
||
本方案不是“用户一句话,Dify 自由发挥到流程结束”,而是“每轮先读状态,再按确定性分支或人工节点收口”。推荐把每轮都视为以下固定编排:
|
||
|
||
1. **识别上下文**:先从用户消息与 `agent_runtime_context.refs`、`reference_context` 识别 `task_id / batch_no / intent_hint`;模糊指代必须先调用 `parse_agent_runtime_context` 读取 `reference_context`。
|
||
2. **读取真相源**:凡属“继续处理 / 切换任务 / 询问当前状态 / 确认或驳回当前步骤”,优先调用 `get_task_status`;只有库存文件上传链走 `inventory_path`。
|
||
3. **优先直连确定性动作**:`confirm / reject / reparse / retry_rpa / confirm_inventory_mapping / correct_inventory_mapping / reparse_inventory / rematch` 必须先走直连 Tool,不先进入 Agent 自由推理。
|
||
4. **仅在固定窗口调用重工具**:`parse_notice` 仅允许出现在“通知待解析”链;`apply_inventory_mapping` 仅允许出现在“库存文件已上传并已拿到 schema preview”链。
|
||
5. **遇到人工门立即停下**:返回 `needs_human`、`stop_agent_turn=true` 或 `forbidden_next_tools` 时,本轮结束;Dify 只展示 `message / parse_msg / align_msg` 并等待用户。
|
||
6. **副作用长链路交回后端**:确认字段对齐后,后续匹配、Excel、上传由后端 worker 自动续跑;Dify 在下一轮通过 `get_task_status` 解释结果,而不是继续串调用多个 Tool。
|
||
|
||
#### 回合收口规则
|
||
|
||
| 返回信号 | Dify 必须行为 | 不允许的行为 |
|
||
| --- | --- | --- |
|
||
| `status=ok/running` 且无人工门 | 继续当前确定性链,或进入 Agent 做解释 | 擅自跳过状态检查直接推进下一大步 |
|
||
| `status=needs_human` | 原文展示 `message`,结合 `human_options` 引导用户选择 | 自作主张替用户确认 |
|
||
| `stop_agent_turn=true` | 立刻结束本轮 | 继续追调下一个 Tool |
|
||
| `forbidden_next_tools` 非空 | 视为硬门禁,禁止调用列出的 Tool | 忽略门禁继续匹配 / 生成 Excel / 上传 |
|
||
| `checkpoint=align_review` | 展示字段对齐结果,等待 `confirm_inventory_mapping / correct_inventory_mapping / reparse_inventory` | 直接进入匹配 |
|
||
| shortage / 匹配不全满足 | 停留在步骤 5,提示补库存 / 返回修订 / 重新匹配 / 驳回 | 生成 Excel、上传货代、暗示可带缺口继续发货 |
|
||
|
||
### 2.2.3 多任务与互斥规则
|
||
|
||
多任务是本方案最容易在联调时失真的部分,编排上必须显式约束:
|
||
|
||
1. 一个 Agent 会话代表一次业务委托;同一会话可包含多个 `batch`,前端通过 `GET /api/workspace/shipping-conversations/<conversation_id>/batch-workspace` 获取会话级执行工作台。
|
||
2. 会话级工作台只做汇总、切换与聚焦:共享用户委托、全局规则、批次摘要;不把某个批次的确认、失败或重试结果自动扩散到其他批次。
|
||
3. 同一 `batch` 任一时刻只允许一个**聚焦任务**,以 `current_focus_task_no` 为准。
|
||
4. Dify 每轮只推进一个 task;不得在同一轮里循环处理整批任务。
|
||
5. 库存文件按批次作为统一库存快照保存;单票也会创建 `file_count=1` 的批次,后续每票独立匹配同一快照。
|
||
6. 用户显式输入 `SN-...` 切换任务时,任务状态、确认、上传动作仍作用于该 task;库存上传/字段映射会作用于该 task 所属批次库存快照。
|
||
7. 批次级“其余票继续处理”由后端 worker / 队列负责,不由 Dify 在对话中批量调 Tool。
|
||
8. 任一 task 出现 `needs_human` 时,只阻断该 task;会话和批次摘要可继续展示其他票状态,但当前对话仍只围绕聚焦 task 引导。
|
||
9. 聊天 UI 的“重试”按钮必须标明作用域,例如“重试当前批次可恢复任务”;本期不提供跨批次强制发货、批量忽略缺口等高风险动作。
|
||
|
||
### 2.3 配置顺序
|
||
|
||
1. 导入 OpenAPI Tool
|
||
2. 配应用基础信息
|
||
3. 配会话变量
|
||
4. 建节点
|
||
5. 连线
|
||
6. 在节点逐项配置中配置 Agent 节点
|
||
7. 验收
|
||
|
||
### 2.4 画布配置
|
||
|
||
#### 2.4.1 完整画布总览
|
||
|
||
```text
|
||
开始
|
||
-> Tool 解析运行态上下文
|
||
-> 运行态上下文标准化
|
||
-> 用户意图预处理
|
||
-> 附件意图分类
|
||
-> 分支调度
|
||
-> 主路由分支节点
|
||
|
||
inventory_path:
|
||
库存任务检查
|
||
-> 是否已有库存绑定任务
|
||
-> Tool 读取库存 schema 预览
|
||
-> 库存 schema 标准化
|
||
-> 库存列映射 LLM
|
||
-> 列映射 JSON 标准化
|
||
-> Tool 应用库存列映射
|
||
-> 映射结果标准化
|
||
-> Agent 状态输入标准化
|
||
-> 货代续办 Agent
|
||
|
||
agent_path:
|
||
准备读取任务状态
|
||
-> Tool 读取任务状态
|
||
-> 工具结果标准化
|
||
-> 当前任务动作判断
|
||
-> 是否进入 Agent
|
||
-> (直连动作)Tool 提交当前任务决策
|
||
-> / 或者
|
||
-> 是否待解析通知
|
||
-> 提取通知原文
|
||
-> 订单需求解析 LLM
|
||
-> 结构化结果标准化
|
||
-> Tool 解析发货通知
|
||
-> 解析结果标准化
|
||
-> Agent 状态输入标准化
|
||
-> 货代续办 Agent
|
||
-> 直接回复
|
||
```
|
||
|
||
#### 2.4.2 应用级配置
|
||
|
||
##### 应用基础信息
|
||
|
||
| 项 | 值 |
|
||
| ----------- | ---------------------------------------- |
|
||
| 应用名称 | `货代发货通知 Agent` |
|
||
| 模式 | `advanced-chat` |
|
||
| DSL version | `0.6.0` |
|
||
| 描述 | `Hxops 货代发货通知生产 Agent(Hxops 建单,Dify 续办)` |
|
||
|
||
##### Opening Statement
|
||
|
||
```text
|
||
我是货代发货通知助手。请在 Hxops 聊天区上传发货通知 PDF/Word,或直接发送任务编号 SN-... 继续处理当前任务。
|
||
库存 Excel 也请在对话区上传;我会结合后端状态继续引导字段确认、库存映射建议、匹配结果解释,以及后续步骤确认。
|
||
```
|
||
|
||
##### Suggested Questions
|
||
|
||
```text
|
||
继续处理当前任务
|
||
查看当前任务状态
|
||
```
|
||
|
||
##### File Upload
|
||
|
||
| 配置项 | 值 |
|
||
| ------------------------------ | -------------------------------------------------------- |
|
||
| enabled | `true` |
|
||
| allowed\_file\_types | `document`, `image` |
|
||
| allowed\_file\_extensions | `.PDF`, `.DOC`, `.DOCX`, `.XLS`, `.XLSX`, `.CSV`, `.TXT` |
|
||
| allowed\_file\_upload\_methods | `local_file` |
|
||
| number\_limits | `10` |
|
||
|
||
说明:
|
||
|
||
- 当前保持 `enabled=true`,是为了让嵌入式聊天态把附件透传为 `sys.files`,供 `附件意图分类` 节点识别库存附件与通知附件。
|
||
- **通知附件即使进入 Dify,也不在 Dify 内直接建 task**;正式建批次、建任务、保存 `raw_text` 仍由 Hxops 负责,因此附件意图分类应走 `direct_answer` 回引提示。
|
||
- 若宿主前端已经完全接管附件上传,且不会向 Dify 透传 `sys.files`,则应关闭 Dify 原生 File Upload,并同步移除本文档中依赖 `sys.files` 的附件分流配置。
|
||
|
||
##### 其他 Features
|
||
|
||
| 配置项 | 值 |
|
||
| ------------------------------------------- | ------- |
|
||
| retriever\_resource.enabled | `false` |
|
||
| sensitive\_word\_avoidance.enabled | `false` |
|
||
| speech\_to\_text.enabled | `false` |
|
||
| suggested\_questions\_after\_answer.enabled | `false` |
|
||
| text\_to\_speech.enabled | `false` |
|
||
|
||
#### 2.4.3 统一上下文输入
|
||
|
||
平台传给 Dify 的业务上下文统一收敛为 `inputs.agent_runtime_context`,不再为货代 Agent 额外注入 `current_task_no / current_batch_no` 这类私有会话变量。
|
||
|
||
标准结构:
|
||
|
||
```json
|
||
{
|
||
"agent_runtime_context": {
|
||
"schema_version": "1",
|
||
"context_id": "ctx-xxx",
|
||
"agent_code": "shipping_notice",
|
||
"scope": "chat_turn",
|
||
"platform": {
|
||
"session_id": "conv-xxx",
|
||
"trigger_source": "frontend_chat"
|
||
},
|
||
"refs": {
|
||
"task_no": "SN-20260625-ABCDEFGH",
|
||
"batch_no": "SB-20260625-ABCDEFGH",
|
||
"run_purpose": "chat_turn"
|
||
},
|
||
"reference_context": {
|
||
"focus_object": {
|
||
"type": "task",
|
||
"id": "SN-20260625-ABCDEFGH"
|
||
}
|
||
}
|
||
}
|
||
}
|
||
```
|
||
|
||
约定:
|
||
|
||
- Dify 画布只读取 `agent_runtime_context`,不依赖 `conversation.current_*` 私有变量。
|
||
- Start 节点只保留 `agent_runtime_context`,不得再新增或保留 `hxops_context`。
|
||
- 业务对象锚点统一放在 `agent_runtime_context.refs`,字段名使用统一协议:`task_no`、`batch_no`、`run_purpose`。
|
||
- 模糊指代统一通过 `reference_context` 读取,不允许仅靠对话记忆猜测对象。
|
||
- `domain.state_hint` 和 `reference_context` 都只是现场提示,不是业务事实源;`checkpoint / human_options / forbidden_next_tools` 仍以 Tool 返回为准。
|
||
- 推荐给 `parse_agent_runtime_context` 的常用 paths:
|
||
- `reference_context.focus_object.id`
|
||
- `reference_context.last_action_target.action`
|
||
- `reference_context.last_failed_target.reason`
|
||
- `reference_context.candidates`
|
||
- `refs.task_no`
|
||
- `refs.batch_no`
|
||
- `domain.state_hint.status`
|
||
|
||
#### 2.4.4 OpenAPI Tool 导入
|
||
|
||
1. Dify → **工具** → **导入自定义 OpenAPI**
|
||
2. 推荐导入静态文件:
|
||
|
||
```text
|
||
docs/openapi/agent_runtime_context_tools.dify.json
|
||
docs/openapi/shipping_notice_tools.dify.json
|
||
```
|
||
|
||
3. 如需直接使用动态地址,也可以导入:
|
||
|
||
```text
|
||
http://<host>/api/agent-runtime-context/tools/openapi.json
|
||
http://<host>/api/shipping-notice/tools/openapi.json
|
||
```
|
||
|
||
4. 鉴权:
|
||
- `Authorization: Bearer <token>`,或
|
||
- `X-Integration-Key: <SHIPPING_NOTICE_TOOL_API_KEY>`(未配置专用 key 时可使用 `<INTEGRATION_API_KEY>`)
|
||
5. 手动创建画布后,在每个 Tool 节点中重新选择:
|
||
- `HXOPS Agent Runtime Context Tools`
|
||
- `Hxops Shipping Notice`
|
||
|
||
#### 2.4.5 总流程图
|
||
|
||
```mermaid
|
||
flowchart TD
|
||
A["开始"] --> B["Tool 解析运行态上下文"]
|
||
B --> B1["运行态上下文标准化"]
|
||
B1 --> C["用户意图预处理"]
|
||
C --> C1["附件意图分类"]
|
||
C1 --> D["分支调度"]
|
||
|
||
D --> E{"主路由分支节点"}
|
||
E -- "inventory_path" --> F["库存任务检查"]
|
||
F --> G{"has_task?"}
|
||
G -- "否" --> H["无TASK_ID提示"]
|
||
G -- "是" --> I["Tool 读取库存 schema 预览"]
|
||
I --> J["库存 schema 标准化"]
|
||
J --> K["库存列映射 LLM"]
|
||
K --> L["列映射 JSON 标准化"]
|
||
L --> M{"mapping_ok?"}
|
||
M -- "否" --> N["列映射失败回复"]
|
||
M -- "是" --> O["Tool 应用库存列映射"]
|
||
O --> P["映射结果标准化"]
|
||
P --> QA["Agent 状态输入标准化"]
|
||
|
||
E -- "direct_answer" --> S["直接回复(引导)"]
|
||
E -- "agent_path" --> W["准备读取任务状态"]
|
||
W --> X["Tool 读取任务状态"]
|
||
X --> Y["工具结果标准化"]
|
||
Y --> Y1["当前任务动作判断"]
|
||
Y1 --> Y2{"是否进入 Agent?"}
|
||
Y2 -- "否" --> Y3{"当前任务直连动作分支"}
|
||
Y3 -- "retry_rpa" --> Y4["Tool 重试库存导出"]
|
||
Y3 -- "confirm / reject / reparse / confirm_inventory_mapping / correct_inventory_mapping / reparse_inventory" --> Y5["Tool 提交当前任务决策"]
|
||
Y3 -- "rematch" --> Y6["Tool 重新匹配库存"]
|
||
Y4 --> Y8["直连动作结果标准化"]
|
||
Y5 --> Y8
|
||
Y6 --> Y8
|
||
Y8 --> Z["直接回复"]
|
||
Y2 -- "是" --> AA{"是否待解析通知?"}
|
||
AA -- "是" --> AB["提取通知原文"]
|
||
AB --> AC["订单需求解析 LLM"]
|
||
AC --> AD["结构化结果标准化"]
|
||
AD --> AE["Tool 解析发货通知"]
|
||
AE --> AF["解析结果标准化"]
|
||
AF --> QA
|
||
AA -- "否" --> QA
|
||
QA --> Q["货代续办 Agent"]
|
||
Q --> Z["直接回复"]
|
||
```
|
||
|
||
#### 2.4.6 节点总表
|
||
|
||
> **总表维护规则**:节点总表只保留汇总视角,每个节点统一维护 6 列:`节点名 / 节点标识 / 类型 / 主要职责 / 核心输入 / 核心输出`。这里不展开代码、条件细节与 Prompt,相关细节统一下沉到 `2.4.7 节点逐项配置`。
|
||
|
||
##### A. 入口与总路由节点
|
||
|
||
| 节点名 | 节点标识 | 类型 | 主要职责 | 核心输入 | 核心输出 |
|
||
| ------- | --------------- | ---------------- | ---------------------------------- | --------------------------------------------- | ----------------------------------------------------------------------- |
|
||
| 开始 | `开始` | Start | 接收消息、附件、会话号与平台上下文 | `sys.query`、`sys.files`、`sys.conversation_id`、`agent_runtime_context` | 无 |
|
||
| Tool 解析运行态上下文 | `Tool 解析运行态上下文` | Tool | 调 `parse_agent_runtime_context` 读取 shipping 画布需要的字段 | `agent_runtime_context` | Tool `text` |
|
||
| 运行态上下文标准化 | `运行态上下文标准化` | Code | 将 parse 结果转为后续节点可直接使用的 shipping 领域变量 | `Tool 解析运行态上下文.text` | `task_no`、`batch_no`、`trigger_source`、`focus_task_no`、`last_action`、`candidate_count` |
|
||
| 用户意图预处理 | `用户意图预处理` | Code | 结合用户消息与已标准化上下文识别任务锚点和短动作意图 | `sys.query`、`sys.conversation_id`、`运行态上下文标准化.*` | `task_no`、`batch_no`、`detected_task_no`、`detected_batch_no`、`intent_hint`、`trigger_source` |
|
||
| 附件意图分类 | `附件意图分类` | Code | 区分通知附件、库存附件、任务续办 | `用户意图预处理.normalized_query`、`sys.files` | `route_key`、`reason` |
|
||
| 分支调度 | `分支调度` | Code | 决定 direct / inventory / agent 三条路径 | `附件意图分类.route_key`、任务号 | `branch`、`final_reply`、`resolved_task_no` |
|
||
| 主路由分支节点 | `主路由分支节点` | If-Else / Branch | 按 `branch` 一次分流到库存链 / 任务续办链 / 引导回复 | `分支调度.branch` | `inventory_path / agent_path / direct_answer` |
|
||
|
||
##### B. `inventory_path` 分支节点
|
||
|
||
| 节点名 | 节点标识 | 类型 | 主要职责 | 核心输入 | 核心输出 |
|
||
| ------------------- | ----- | ------- | -------------------------------- | ------------------------------------ | --------------------------------------------------------- |
|
||
| 库存任务检查 | 自动生成 | Code | 判断库存文件当前是否有可绑定任务 | `resolved_task_no` | `task_id`、`has_task`、`final_reply` |
|
||
| 是否已有库存绑定任务 | 自动生成 | If-Else | 判断当前库存链是否已有 task\_id | `库存任务检查.has_task` | true / false |
|
||
| 无TASK\_ID提示 | 自动生成 | Answer | 没任务号时直接提示 | `库存任务检查.final_reply` | 最终回复 |
|
||
| Tool 读取库存 schema 预览 | 自动生成 | Tool | 调 `get_inventory_schema_preview` | `库存任务检查.task_id` | Tool `text` |
|
||
| 库存 schema 标准化 | 自动生成 | Code | 提取 headers / sample\_rows | `Tool 读取库存 schema 预览.text` | `headers_json`、`sample_rows_json`、`schema_preview_json` |
|
||
| 库存列映射 LLM | 自动生成 | LLM | 推断 `map_json` | `headers_json`、`sample_rows_json` | `text` |
|
||
| 列映射 JSON 标准化 | 自动生成 | Code | 把 LLM 输出转成合法 JSON | `库存列映射 LLM.text` | `map_json`、`mapping_ok`、`error_message` |
|
||
| 库存列映射是否成功 | 自动生成 | If-Else | 判断列映射 JSON 是否可用于 apply | `列映射 JSON 标准化.mapping_ok` | true / false |
|
||
| 列映射失败回复 | 自动生成 | Answer | 非法 JSON 时回复用户 | `列映射 JSON 标准化.error_message` | 最终回复 |
|
||
| Tool 应用库存列映射 | 自动生成 | Tool | 调 `apply_inventory_mapping` | `task_id`、`map_json` | Tool `text` |
|
||
| 映射结果标准化 | 自动生成 | Code | 标准化 apply 结果 JSON | `Tool 应用库存列映射.text` | `tool_status`、`tool_message`、`tool_checkpoint`、`raw_json` |
|
||
|
||
##### C. `direct_answer` 分支节点
|
||
|
||
| 节点名 | 节点标识 | 类型 | 主要职责 | 核心输入 | 核心输出 |
|
||
| -------- | --------------- | ------ | -------- | ------------------ | ---- |
|
||
| 直接回复(引导) | `直接回复(引导)` | Answer | 输出固定引导文案 | `分支调度.final_reply` | 最终回复 |
|
||
|
||
##### D. `agent_path` 公共前置节点
|
||
|
||
| 节点名 | 节点标识 | 类型 | 主要职责 | 核心输入 | 核心输出 |
|
||
| ----------- | --------------- | ------- | ------------------------------------------------ | -------------------------------- | ------------------------------------------------------------------------------------------------ |
|
||
| 准备读取任务状态 | `准备读取任务状态` | Code | 收口本轮最新 `task_id` 与 `conversation_id`;当前仅读取当前任务状态 | 上游任务号、会话号 | `task_id`、`conversation_id` |
|
||
| Tool 读取任务状态 | `Tool 读取任务状态` | Tool | 调 `get_task_status` | `task_id`、`conversation_id` | Tool `text` |
|
||
| 工具结果标准化 | `工具结果标准化` | Code | 标准化任务状态 JSON,并产出首轮通知解析判断布尔值 | `Tool 读取任务状态.text` | `tool_status`、`tool_message`、`tool_checkpoint`、`tool_data_json`、`raw_json`、`current_task_no`、`has_raw_text`、`should_parse_notice` |
|
||
| 当前任务动作判断 | 自动生成 | Code | 判断当前是否为可直连 Tool 的确定性动作 | `intent_hint`、`resolved_task_no` | `direct_action`、`need_agent` |
|
||
| 是否进入 Agent | 自动生成 | If-Else | 当 `need_agent=true` 时继续通知解析 / Agent 链,否则进入直连动作链 | `当前任务动作判断.need_agent` | true / false |
|
||
|
||
##### E. 当前任务直连动作分支节点
|
||
|
||
| 节点名 | 节点标识 | 类型 | 主要职责 | 核心输入 | 核心输出 |
|
||
| ------------- | ----- | ---------------- | -------------------------------------------------------------------------------- | ------------------------- | ----------------------------------------------------------------------- |
|
||
| 当前任务直连动作分支 | 自动生成 | If-Else / Branch | 按 Tool 分组分发确定性动作,减少重复 Tool 节点 | `当前任务动作判断.direct_action` | `retry_rpa / submit_decision_path / rematch` |
|
||
| Tool 重试库存导出 | 自动生成 | Tool | 调 `submit_decision(task_id, decision=retry_rpa)`,由后端 RPA 工作流继续处理库存准备链路 | `task_id` | Tool `text` |
|
||
| Tool 提交当前任务决策 | 自动生成 | Tool | 调 `submit_decision(task_id, decision={{direct_action}})`,统一承接确认、驳回、重解析、字段对齐确认等动作 | `task_id`、`direct_action` | Tool `text` |
|
||
| Tool 重新匹配库存 | 自动生成 | Tool | 提交重匹配相关决策,由后端 worker 续跑匹配链路 | `task_id` | Tool `text` |
|
||
| 直连动作结果标准化 | 自动生成 | Code | 统一解析直连 Tool 返回,并生成最终回复文本 | 各直连 Tool `text` | `tool_status`、`tool_message`、`tool_checkpoint`、`raw_json`、`answer_text` |
|
||
| 直接回复(动作结果) | 自动生成 | Answer | 输出直连动作 Tool 文本 | `直连动作结果标准化.answer_text` | 最终回复 |
|
||
|
||
##### F. 通知解析与 Agent 分支节点
|
||
|
||
| 节点名 | 节点标识 | 类型 | 主要职责 | 核心输入 | 核心输出 |
|
||
| -------------- | --------------- | ------- | ------------------------------------ | -------------------------------------------------------- | --------------------------------------------------------- |
|
||
| 是否待解析通知 | 自动生成 | If-Else | 判断当前是否应走订单需求解析链 | `工具结果标准化.should_parse_notice` | true / false |
|
||
| 提取通知原文 | 自动生成 | Code | 从状态 JSON 提取 `raw_text` / `parse_msg` | `工具结果标准化.raw_json` | `notice_raw_text`、`task_id` |
|
||
| 订单需求解析 LLM | 自动生成 | LLM | 将 `raw_text` 解析成 `structured` | `提取通知原文.notice_raw_text` | `text` |
|
||
| 结构化结果标准化 | 自动生成 | Code | 把 LLM 输出转成 `structured_json` | `订单需求解析 LLM.text` | `structured_json`、`parse_ok`、`error_message` |
|
||
| Tool 解析发货通知 | 自动生成 | Tool | 调 `parse_notice(structured=...)` | `task_id`、`structured_json` | Tool `text` |
|
||
| 解析结果标准化 | 自动生成 | Code | 标准化 parse\_notice 返回 | `Tool 解析发货通知.text` | `tool_status`、`tool_message`、`tool_checkpoint`、`raw_json`、`answer_text` |
|
||
| Agent 状态输入标准化 | 自动生成 | Code | 合并普通续办 / 通知解析 / 库存映射三条链的最新状态 | `工具结果标准化.raw_json`、`解析结果标准化.raw_json`、`映射结果标准化.raw_json` | `agent_raw_json`、`agent_task_id`、`agent_checkpoint` |
|
||
| 货代续办 Agent | `货代续办 Agent` | Agent | 仅处理模糊自由输入、解释性问题与复杂续办 | `normalized_query`、`agent_raw_json`、`agent_task_id` | `text` |
|
||
| Agent 指令(维护入口) | 自动生成 | 文档锚点 | 指向生产可粘贴的完整 Agent Instruction | 无 | 无 |
|
||
| 直接回复 | `直接回复` | Answer | 输出 Agent 文本 | `货代续办 Agent.text` | 最终回复 |
|
||
|
||
#### 2.4.7 节点逐项配置
|
||
|
||
> **配置顺序必须以流程图为准**:下面按 Dify 画布实际连线顺序维护节点;共享收口节点只配置一次,放在所有入边节点之后。所有变量引用均使用中文节点名,不使用 Dify 自动生成的内部节点编号。
|
||
|
||
##### 实际配置顺序清单
|
||
|
||
```text
|
||
入口与总路由:
|
||
1. 开始
|
||
2. Tool 解析运行态上下文
|
||
3. 运行态上下文标准化
|
||
4. 用户意图预处理
|
||
5. 附件意图分类
|
||
6. 分支调度
|
||
7. 主路由分支节点
|
||
|
||
inventory_path:
|
||
8. 库存任务检查
|
||
9. 是否已有库存绑定任务
|
||
10. 无TASK_ID提示
|
||
11. Tool 读取库存 schema 预览
|
||
12. 库存 schema 标准化
|
||
13. 库存列映射 LLM
|
||
14. 列映射 JSON 标准化
|
||
15. 库存列映射是否成功
|
||
16. 列映射失败回复
|
||
17. Tool 应用库存列映射
|
||
18. 映射结果标准化
|
||
|
||
direct_answer:
|
||
19. 直接回复(引导)
|
||
|
||
agent_path 公共前置:
|
||
20. 准备读取任务状态
|
||
21. Tool 读取任务状态
|
||
22. 工具结果标准化
|
||
23. 当前任务动作判断
|
||
24. 是否进入 Agent
|
||
|
||
agent_path / direct_action:
|
||
25. 当前任务直连动作分支
|
||
26. 当前任务直连 Tool 节点
|
||
27. 直连动作结果标准化
|
||
28. 直接回复(动作结果)
|
||
|
||
agent_path / need_agent:
|
||
29. 是否待解析通知
|
||
30. 提取通知原文
|
||
31. 订单需求解析 LLM
|
||
32. 结构化结果标准化
|
||
33. Tool 解析发货通知
|
||
34. 解析结果标准化
|
||
|
||
共享收口:
|
||
35. Agent 状态输入标准化
|
||
36. 货代续办 Agent
|
||
37. Agent 指令(维护入口)
|
||
38. 直接回复
|
||
```
|
||
|
||
说明:
|
||
|
||
- `Agent 状态输入标准化 / 货代续办 Agent / 直接回复` 是库存链与任务链复用的收口节点,配置一次即可,连线时从多个上游汇入。
|
||
- `当前任务动作判断` 必须紧跟 `工具结果标准化`,因为它依赖标准化后的当前任务状态与动作意图。
|
||
- `直接回复(引导)` 是 `direct_answer` 分支专用节点,不参与任务解析链。
|
||
|
||
> **逐项维护模板**:每个节点默认按以下顺序维护,除非该节点天然不适用某项,否则不要省略顺序或混排。
|
||
>
|
||
> 1. `节点标题(中文节点名)`
|
||
> 2. `类型`
|
||
> 3. `输入映射 / 系统输入`
|
||
> 4. `输出`
|
||
> 5. `条件配置 / Tool 绑定 / Query / Prompt`(按节点类型择一或多项)
|
||
> 6. `代码 / 内容`
|
||
> 7. `说明`
|
||
>
|
||
> **节点类型约定**:
|
||
>
|
||
> - `Start`:写系统输入即可,一般不写输出。
|
||
> - `Code`:必须写输入映射、输出、代码。
|
||
> - `If-Else / Branch`:必须写输入字段、条件配置、true/false 或各分支去向。
|
||
> - `Tool`:必须写 Tool 绑定、参数映射、输出、说明。
|
||
> - `LLM / Agent`:必须写基础配置、输入 / Query、Prompt 或 Instruction、可用 Tool 边界。
|
||
> - `Answer`:必须写内容模板;如有变量来源,在说明中注明上游节点。
|
||
|
||
##### 节点:开始
|
||
|
||
类型:`Start`
|
||
|
||
输入映射:
|
||
|
||
- `sys.query`
|
||
- `sys.files`
|
||
- `sys.conversation_id`
|
||
- `agent_runtime_context`
|
||
|
||
本节点无需自定义代码。
|
||
|
||
说明:
|
||
|
||
- 本节点只作为系统入口,不承载任何业务判断。
|
||
- 所有与附件、任务号、会话号相关的业务理解,都应下沉到后续 Code 节点处理。
|
||
- 本节点不得再配置 `hxops_context`;若 Dify 画布仍提示缺少该变量,说明画布未完成新协议切换。
|
||
|
||
##### 节点:Tool 解析运行态上下文
|
||
|
||
类型:`Tool`
|
||
|
||
Tool 绑定:
|
||
|
||
| 项 | 值 |
|
||
| --- | --- |
|
||
| provider_show_name | `HXOPS Agent Runtime Context Tools` |
|
||
| tool_name | `parse_agent_runtime_context` |
|
||
|
||
参数映射:
|
||
|
||
| 参数名 | 来源 | 是否必填 | 说明 |
|
||
| --- | --- | --- | --- |
|
||
| `agent_runtime_context` | `{{agent_runtime_context}}` | 是 | Start 节点注入的完整运行态上下文 JSON 字符串 |
|
||
| `paths` | 固定数组 | 是 | shipping 画布本轮需要读取的白名单字段 |
|
||
|
||
`paths` 固定配置:
|
||
|
||
```json
|
||
[
|
||
"refs.task_no",
|
||
"refs.batch_no",
|
||
"refs.run_purpose",
|
||
"platform.trigger_source",
|
||
"domain.state_hint.status",
|
||
"domain.state_hint.focus_task_no",
|
||
"reference_context.focus_object.id",
|
||
"reference_context.last_action_target.action",
|
||
"reference_context.last_action_target.id",
|
||
"reference_context.last_failed_target.reason",
|
||
"reference_context.last_failed_target.id",
|
||
"reference_context.candidates"
|
||
]
|
||
```
|
||
|
||
输出:
|
||
|
||
| 字段 | 说明 |
|
||
| --- | --- |
|
||
| `text` | Tool 原始返回 JSON 字符串,交给 `运行态上下文标准化` 处理 |
|
||
|
||
说明:
|
||
|
||
- 本节点是画布唯一的运行态上下文解析入口;禁止其他 Code 节点直接 `json.loads(agent_runtime_context)` 重复解析。
|
||
- `parse_agent_runtime_context` 只读,不推进任何业务状态。
|
||
- 解析不到的字段会进入 Tool 返回的 `missing`,下游应按空值处理,不应报错中断。
|
||
|
||
##### 节点:运行态上下文标准化
|
||
|
||
类型:`Code`
|
||
|
||
输入映射:
|
||
|
||
| 变量名 | 来源 |
|
||
| --- | --- |
|
||
| `text` | `Tool 解析运行态上下文.text` |
|
||
|
||
输出:
|
||
|
||
| 字段 | 说明 |
|
||
| --- | --- |
|
||
| `task_no` | shipping 当前任务号,来自 `refs.task_no` |
|
||
| `batch_no` | shipping 当前批次号,来自 `refs.batch_no` |
|
||
| `run_purpose` | 本轮运行目的,如 `chat_turn / parse_notice` |
|
||
| `trigger_source` | 触发来源,如 `frontend_chat / backend_orchestrator` |
|
||
| `focus_task_no` | 当前 focus task,来自 `domain.state_hint` 或 `reference_context.focus_object` |
|
||
| `last_action` | 最近动作,如 `confirm_parse / confirm_matched / switch_focus / auto_focus` |
|
||
| `last_action_task_no` | 最近动作目标任务号 |
|
||
| `last_failed_reason` | 最近失败原因,如 `shortage / rejected / upload_failed` |
|
||
| `last_failed_task_no` | 最近失败目标任务号 |
|
||
| `candidate_count` | `reference_context.candidates` 数量 |
|
||
| `candidates_json` | candidates JSON 字符串 |
|
||
| `runtime_context_json` | parse Tool 返回的完整 JSON 字符串,供排查使用 |
|
||
|
||
代码:
|
||
|
||
```python
|
||
import json
|
||
|
||
def _load_json(text: str):
|
||
raw = str(text or "").strip()
|
||
if not raw:
|
||
return {}
|
||
try:
|
||
data = json.loads(raw)
|
||
except json.JSONDecodeError:
|
||
return {}
|
||
return data if isinstance(data, dict) else {}
|
||
|
||
def _value(data: dict, path: str) -> str:
|
||
values = data.get("data") if isinstance(data.get("data"), dict) else {}
|
||
value = values.get(path)
|
||
return str(value or "").strip()
|
||
|
||
def _object_value(data: dict, path: str):
|
||
values = data.get("data") if isinstance(data.get("data"), dict) else {}
|
||
value = values.get(path)
|
||
return value if isinstance(value, (dict, list)) else None
|
||
|
||
def main(text: str = ""):
|
||
parsed = _load_json(text)
|
||
candidates = _object_value(parsed, "reference_context.candidates") or []
|
||
if not isinstance(candidates, list):
|
||
candidates = []
|
||
focus_task_no = (
|
||
_value(parsed, "domain.state_hint.focus_task_no")
|
||
or _value(parsed, "reference_context.focus_object.id")
|
||
).upper()
|
||
return {
|
||
"task_no": _value(parsed, "refs.task_no").upper(),
|
||
"batch_no": _value(parsed, "refs.batch_no").upper(),
|
||
"run_purpose": _value(parsed, "refs.run_purpose"),
|
||
"trigger_source": _value(parsed, "platform.trigger_source"),
|
||
"focus_task_no": focus_task_no,
|
||
"last_action": _value(parsed, "reference_context.last_action_target.action"),
|
||
"last_action_task_no": _value(parsed, "reference_context.last_action_target.id").upper(),
|
||
"last_failed_reason": _value(parsed, "reference_context.last_failed_target.reason"),
|
||
"last_failed_task_no": _value(parsed, "reference_context.last_failed_target.id").upper(),
|
||
"candidate_count": len(candidates),
|
||
"candidates_json": json.dumps(candidates, ensure_ascii=False),
|
||
"runtime_context_json": json.dumps(parsed, ensure_ascii=False),
|
||
}
|
||
```
|
||
|
||
说明:
|
||
|
||
- 本节点只把 parse Tool 的结果转成 Dify 后续节点方便引用的 shipping 领域变量。
|
||
- `task_no / batch_no` 允许为空;空值表示当前会话尚未有明确任务或批次锚点。
|
||
- `candidate_count > 1` 时,Agent 必须追问用户选择具体任务,不得自行猜测。
|
||
|
||
##### 节点:用户意图预处理
|
||
|
||
输入映射:
|
||
|
||
| 变量名 | 来源 |
|
||
| ------------------ | ------------------------------- |
|
||
| `query` | `sys.query` |
|
||
| `conversation_id` | `sys.conversation_id` |
|
||
| `task_no` | `运行态上下文标准化.task_no` |
|
||
| `batch_no` | `运行态上下文标准化.batch_no` |
|
||
| `trigger_source` | `运行态上下文标准化.trigger_source` |
|
||
| `focus_task_no` | `运行态上下文标准化.focus_task_no` |
|
||
|
||
输出:
|
||
|
||
| 字段 | 说明 |
|
||
| ------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||
| `task_no` | 本轮确定任务号;优先上下文 `task_no`,其次 `focus_task_no` |
|
||
| `batch_no` | 当前批次号 |
|
||
| `normalized_query` | 标准化后的用户消息 |
|
||
| `detected_batch_no` | 识别出的批次号 |
|
||
| `detected_task_no` | 识别出的任务号 |
|
||
| `intent_hint` | `message / parse_notice / batch_switch / task_switch / retry_rpa / rematch / confirm / reparse / reject / confirm_inventory_mapping / correct_inventory_mapping / reparse_inventory` |
|
||
| `trigger_source` | `运行态上下文标准化.trigger_source`,如 `frontend_chat / backend_orchestrator` |
|
||
| `conversation_id` | 透传会话号 |
|
||
| `error_message` | 预留错误文本 |
|
||
|
||
代码:
|
||
|
||
```python
|
||
import re
|
||
|
||
TASK_RE = re.compile(r"SN-\d{8}-[A-F0-9]{8}", re.I)
|
||
BATCH_RE = re.compile(r"SB-\d{8}-[A-F0-9]{8}", re.I)
|
||
|
||
def main(query: str = "", conversation_id: str = "", task_no: str = "", batch_no: str = "", trigger_source: str = "", focus_task_no: str = ""):
|
||
text = str(query or "").strip()
|
||
ctx_task = (str(task_no or "").strip() or str(focus_task_no or "").strip()).upper()
|
||
ctx_batch = str(batch_no or "").strip().upper()
|
||
task_match = TASK_RE.search(text)
|
||
batch_match = BATCH_RE.search(text)
|
||
normalized_query = " ".join(text.split())
|
||
intent_hint = "message"
|
||
lower_text = normalized_query.lower()
|
||
if trigger_source == "backend_orchestrator":
|
||
intent_hint = "parse_notice"
|
||
elif re.search(r"(重试|重新)\s*rpa|重试.*(导出|获取|拉取).*库存|rpa.*(导出|获取|拉取).*重试", normalized_query, re.I):
|
||
intent_hint = "retry_rpa"
|
||
elif re.search(r"重新匹配|重匹配|rematch", normalized_query, re.I):
|
||
intent_hint = "rematch"
|
||
elif normalized_query in {"确认", "confirm"}:
|
||
intent_hint = "confirm"
|
||
elif re.search(r"重新解析|重解析|reparse", normalized_query, re.I):
|
||
intent_hint = "reparse"
|
||
elif re.search(r"驳回|取消|reject", normalized_query, re.I):
|
||
intent_hint = "reject"
|
||
elif re.search(r"确认字段对齐|确认映射|confirm_inventory_mapping", normalized_query, re.I):
|
||
intent_hint = "confirm_inventory_mapping"
|
||
elif re.search(r"更正映射|更正列映射|correct_inventory_mapping", normalized_query, re.I):
|
||
intent_hint = "correct_inventory_mapping"
|
||
elif re.search(r"重新上传库存|重传库存|reparse_inventory", normalized_query, re.I):
|
||
intent_hint = "reparse_inventory"
|
||
elif re.search(r"切到|切换到|换到|处理\s*sn-|上一票|下一票|\bnext\b|\bprev\b|\bprevious\b", lower_text, re.I):
|
||
intent_hint = "task_switch"
|
||
elif re.search(r"切换批次|切到批次|处理批次|batch\s*switch", normalized_query, re.I):
|
||
intent_hint = "batch_switch"
|
||
return {
|
||
"task_no": ctx_task,
|
||
"batch_no": ctx_batch,
|
||
"normalized_query": normalized_query,
|
||
"detected_batch_no": (batch_match.group(0).upper() if batch_match else ctx_batch),
|
||
"detected_task_no": (task_match.group(0).upper() if task_match else ctx_task),
|
||
"intent_hint": intent_hint,
|
||
"trigger_source": str(trigger_source or "").strip(),
|
||
"conversation_id": str(conversation_id or "").strip(),
|
||
"error_message": "",
|
||
}
|
||
```
|
||
|
||
说明:
|
||
|
||
- 本节点只做轻量语义归类与上下文标准化,不直接决定是否调用 Tool。
|
||
- 本节点只做用户消息标准化与短动作分类,不直接解析 `agent_runtime_context` JSON。
|
||
- `task_no / batch_no / focus_task_no` 均来自上游 `运行态上下文标准化`;后续节点不得再直接依赖 `conversation.current_*`。
|
||
- 遇到“继续、刚才那个、上一个失败的、这个、那个”等模糊指代时,不在本节点猜测,交由后续 Agent 调用 `parse_agent_runtime_context` 读取 `reference_context`。
|
||
- 后台 worker 调用 Dify 时,`trigger_source=backend_orchestrator` 必须强制识别为 `parse_notice`,进入当前任务解析链。
|
||
- 禁止仅因消息中出现 `SB-...` 就设置 `batch_switch`;只有用户明确说“切换批次 / 切到批次 / 处理批次”时才允许 `batch_switch`。
|
||
- 若后续新增短动作口令,优先在本节点补充 `intent_hint` 识别,再同步更新下游直连动作判断。
|
||
|
||
##### 节点:附件意图分类
|
||
|
||
输入映射:
|
||
|
||
| 变量名 | 来源 |
|
||
| ------------------ | ---------------------------------------- |
|
||
| `normalized_query` | `用户意图预处理.normalized_query` |
|
||
| `intent_hint` | `用户意图预处理.intent_hint` |
|
||
| `sys_files` | `sys.files` |
|
||
|
||
输出:
|
||
|
||
| 字段 | 说明 |
|
||
| ----------- | ------------------------------------------------------------------------------------- |
|
||
| `route_key` | `inventory_path / agent_path / direct_answer` |
|
||
| `reason` | 路由原因 |
|
||
|
||
代码:
|
||
|
||
```python
|
||
def _file_name(item) -> str:
|
||
if isinstance(item, dict):
|
||
return str(item.get("name") or item.get("filename") or "").lower()
|
||
return str(getattr(item, "name", "") or getattr(item, "filename", "") or "").lower()
|
||
|
||
def main(normalized_query: str = "", intent_hint: str = "", sys_files=None):
|
||
files = sys_files if isinstance(sys_files, list) else []
|
||
text = str(normalized_query or "").strip()
|
||
if files:
|
||
lower_names = " ".join(_file_name(f) for f in files)
|
||
if any(ext in lower_names for ext in [".xlsx", ".xls", ".csv"]):
|
||
return {"route_key": "inventory_path", "reason": "inventory_file"}
|
||
return {"route_key": "direct_answer", "reason": "notice_files_managed_by_hxops"}
|
||
if intent_hint in {
|
||
"parse_notice",
|
||
"retry_rpa",
|
||
"rematch",
|
||
"confirm",
|
||
"reparse",
|
||
"reject",
|
||
"confirm_inventory_mapping",
|
||
"correct_inventory_mapping",
|
||
"reparse_inventory",
|
||
"task_switch",
|
||
"batch_switch",
|
||
}:
|
||
return {"route_key": "agent_path", "reason": "task_action"}
|
||
if text:
|
||
return {"route_key": "agent_path", "reason": "normal_message"}
|
||
return {"route_key": "direct_answer", "reason": "empty_input"}
|
||
```
|
||
|
||
说明:
|
||
|
||
- `parse_notice / retry_rpa / rematch / confirm / reparse / reject / confirm_inventory_mapping / correct_inventory_mapping / reparse_inventory` 都属于**当前任务动作**,必须落到 `agent_path`。
|
||
- 通知附件由 HXOPS 前端/后端接管上传、建批、建任务与文本抽取;Dify 收到通知附件时只走 `direct_answer` 回引,不在画布内建 task。
|
||
- 即使文本里带了 `SN-...`,也不应把这类动作改走其他分支。
|
||
|
||
##### 节点:分支调度
|
||
|
||
输入映射:
|
||
|
||
| 变量名 | 来源 |
|
||
| ------------------ | ---------------------------------------- |
|
||
| `route_key` | `附件意图分类.route_key` |
|
||
| `normalized_query` | `用户意图预处理.normalized_query` |
|
||
| `detected_task_no` | `用户意图预处理.detected_task_no` |
|
||
| `intent_hint` | `用户意图预处理.intent_hint` |
|
||
|
||
输出:
|
||
|
||
| 字段 | 说明 |
|
||
| ------------------ | --------------------------------------------- |
|
||
| `branch` | `direct_answer / inventory_path / agent_path` |
|
||
| `final_reply` | 引导回复 |
|
||
| `resolved_task_no` | 最终任务号 |
|
||
| `action_hint` | 当前任务动作提示;供续办链直接执行 |
|
||
|
||
代码:
|
||
|
||
```python
|
||
def main(route_key: str = "", normalized_query: str = "", detected_task_no: str = "", intent_hint: str = ""):
|
||
rk = str(route_key or "").strip()
|
||
hint = str(intent_hint or "").strip()
|
||
task = str(detected_task_no or "").strip().upper()
|
||
if rk == "inventory_path":
|
||
return {
|
||
"branch": "inventory_path",
|
||
"final_reply": "",
|
||
"resolved_task_no": task,
|
||
"action_hint": "",
|
||
}
|
||
if rk == "direct_answer":
|
||
return {
|
||
"branch": "direct_answer",
|
||
"final_reply": "请在 Hxops 聊天区上传发货通知文件,系统会创建任务并后台解析;完成后可发送“继续处理”或直接发送 SN- 任务号。",
|
||
"resolved_task_no": task,
|
||
"action_hint": "",
|
||
}
|
||
if rk == "agent_path" and not task:
|
||
return {
|
||
"branch": "direct_answer",
|
||
"final_reply": "尚未识别到任务编号。请先通过 Hxops 上传发货通知创建任务,或在消息中直接带上 SN- 任务号。",
|
||
"resolved_task_no": "",
|
||
"action_hint": "",
|
||
}
|
||
return {"branch": "agent_path", "final_reply": "", "resolved_task_no": task, "action_hint": hint}
|
||
```
|
||
|
||
说明:
|
||
|
||
- `分支调度` 不能仅因消息里出现 `SN-...` 就改写当前任务动作。
|
||
- 当 `intent_hint` 是 `parse_notice / retry_rpa / rematch / confirm / reparse / reject / confirm_inventory_mapping / correct_inventory_mapping / reparse_inventory` 时,应视为**当前任务上的动作执行**,进入统一续办链。
|
||
|
||
##### 节点:主路由分支节点
|
||
|
||
类型:`If-Else / Branch`
|
||
|
||
分支配置(直接照填):
|
||
|
||
```text
|
||
输入字段:分支调度.branch
|
||
|
||
分支 1:
|
||
条件值:inventory_path
|
||
去向:库存任务检查
|
||
|
||
分支 2:
|
||
条件值:agent_path
|
||
去向:准备读取任务状态
|
||
|
||
分支 3:
|
||
条件值:direct_answer
|
||
去向:直接回复(引导)
|
||
```
|
||
|
||
说明:
|
||
|
||
- 这里使用 Dify 的**多分支能力**
|
||
- 不再拆成“先判断库存,再判断是否任务续办”的两个菱形
|
||
- `branch` 的三个合法值必须和 `分支调度` 输出保持一致:
|
||
- `inventory_path`
|
||
- `agent_path`
|
||
- `direct_answer`
|
||
|
||
##### 节点:库存任务检查
|
||
|
||
输入映射:
|
||
|
||
| 变量名 | 来源 |
|
||
| ------------------ | -------------------------------------- |
|
||
| `resolved_task_no` | `分支调度.resolved_task_no` |
|
||
|
||
输出:
|
||
|
||
| 字段 | 说明 |
|
||
| ------------- | --------- |
|
||
| `task_id` | 库存要绑定的任务号 |
|
||
| `has_task` | 是否已有任务号 |
|
||
| `final_reply` | 缺少任务号时的提示 |
|
||
|
||
代码:
|
||
|
||
```python
|
||
def main(resolved_task_no: str = ""):
|
||
task_id = str(resolved_task_no or "").strip().upper()
|
||
return {
|
||
"task_id": task_id,
|
||
"has_task": bool(task_id),
|
||
"final_reply": "" if task_id else "检测到库存文件,但当前还没有可绑定的任务号。请先在 Hxops 上传发货通知生成 SN-任务,再重新上传库存文件。",
|
||
}
|
||
```
|
||
|
||
说明:
|
||
|
||
- 本节点只决定“库存文件当前能否绑定到某个 task”,不负责真正上传库存文件。
|
||
- 多任务场景下若没有明确 task,上游必须在这里被拦住,不能继续进入库存解析链。
|
||
|
||
##### 节点:是否已有库存绑定任务
|
||
|
||
类型:`If-Else`
|
||
|
||
条件配置(直接照填):
|
||
|
||
```text
|
||
左值:库存任务检查.has_task
|
||
运算符:is
|
||
右值:true
|
||
```
|
||
|
||
true:
|
||
|
||
- 进入 `Tool 读取库存 schema 预览`
|
||
|
||
false:
|
||
|
||
- 进入 `无TASK_ID提示`
|
||
|
||
说明:
|
||
|
||
- 这是库存链的硬门禁;`has_task=false` 时必须结束本轮。
|
||
- 不允许在这里兜底猜测任务号或默认绑定任意历史 task。
|
||
|
||
##### 节点:无TASK\_ID提示
|
||
|
||
类型:`Answer`
|
||
|
||
内容:
|
||
|
||
```text
|
||
{{#库存任务检查.final_reply#}}
|
||
```
|
||
|
||
说明:
|
||
|
||
- 本节点只输出缺少任务号时的固定引导,不做额外判断。
|
||
- 若库存上传前置规则调整,只改 `库存任务检查.final_reply` 的生成逻辑即可。
|
||
|
||
##### 节点:Tool 读取库存 schema 预览
|
||
|
||
Tool 绑定:
|
||
|
||
| 项 | 值 |
|
||
| -------------------- | ------------------------------ |
|
||
| provider\_show\_name | `Hxops Shipping Notice` |
|
||
| tool\_name | `get_inventory_schema_preview` |
|
||
|
||
参数映射:
|
||
|
||
| 参数名 | 来源 | 是否必填 | 说明 |
|
||
| --------- | ---------------------- | ---- | ------------- |
|
||
| `task_id` | `{{#库存任务检查.task_id#}}` | 是 | 当前库存文件要绑定的任务号 |
|
||
|
||
输出:
|
||
|
||
| 字段 | 说明 |
|
||
| ------ | --------------------------------------------------------------- |
|
||
| `text` | Tool 原始返回 JSON 字符串,交给 `库存 schema 标准化` 提取 headers / sample\_rows |
|
||
|
||
说明:
|
||
|
||
- 本节点只读取小 payload 的 schema preview,不在 Dify 侧处理完整库存文件。
|
||
- 真正的完整库存解析只允许发生在 `apply_inventory_mapping` 之后,由后端负责。
|
||
|
||
##### 节点:库存 schema 标准化
|
||
|
||
输入映射:
|
||
|
||
| 变量名 | 来源 |
|
||
| ------ | -------------------------- |
|
||
| `text` | `Tool 读取库存 schema 预览.text` |
|
||
|
||
输出:
|
||
|
||
| 字段 | 说明 |
|
||
| --------------------- | ------------------- |
|
||
| `headers_json` | 表头 JSON 字符串 |
|
||
| `sample_rows_json` | 样例行 JSON 字符串 |
|
||
| `schema_preview_json` | schema preview JSON |
|
||
| `raw_json` | 全量 JSON |
|
||
|
||
代码:
|
||
|
||
```python
|
||
import json
|
||
|
||
def main(text: str = ""):
|
||
raw = str(text or "").strip()
|
||
try:
|
||
data = json.loads(raw) if raw else {}
|
||
except json.JSONDecodeError:
|
||
data = {}
|
||
if not isinstance(data, dict):
|
||
data = {}
|
||
payload = data.get("data") or {}
|
||
schema_preview = payload.get("schema_preview") or {}
|
||
headers = schema_preview.get("headers") or []
|
||
sample_rows = schema_preview.get("sample_rows") or schema_preview.get("rows") or []
|
||
return {
|
||
"headers_json": json.dumps(headers, ensure_ascii=False),
|
||
"sample_rows_json": json.dumps(sample_rows, ensure_ascii=False),
|
||
"schema_preview_json": json.dumps(schema_preview, ensure_ascii=False),
|
||
"raw_json": json.dumps(data, ensure_ascii=False),
|
||
}
|
||
```
|
||
|
||
说明:
|
||
|
||
- 本节点只负责把 schema preview 拆成 LLM 可消费的轻量输入。
|
||
- 若后端 preview 结构调整,只改这里的提取逻辑,不改后续库存映射 Prompt 模板。
|
||
|
||
##### 节点:库存列映射 LLM
|
||
|
||
类型:`LLM`
|
||
|
||
模型建议:
|
||
|
||
| 项 | 值 |
|
||
| ----------- | ------------- |
|
||
| provider | `openai` |
|
||
| model | `gpt-4o-mini` |
|
||
| temperature | `0.1` |
|
||
|
||
System Prompt:
|
||
|
||
```text
|
||
你是库存 Excel 列映射助手。你的任务是根据表头和样例行,只输出合法 JSON,不要输出任何解释文字。
|
||
|
||
目标字段只允许包含:
|
||
- reservation_id
|
||
- sku
|
||
- available_qty
|
||
|
||
规则:
|
||
1. 返回 JSON object
|
||
2. value 必须来自提供的真实表头,禁止臆造
|
||
3. 如果无法判断 reservation_id,则返回空字符串
|
||
4. 不要输出 markdown,不要输出代码块
|
||
```
|
||
|
||
User Prompt:
|
||
|
||
```text
|
||
表头:
|
||
{{#库存 schema 标准化.headers_json#}}
|
||
|
||
样例行:
|
||
{{#库存 schema 标准化.sample_rows_json#}}
|
||
|
||
请输出 map_json。
|
||
```
|
||
|
||
期望输出:
|
||
|
||
```json
|
||
{"reservation_id":"Reservation Order","sku":"AWS Sku","available_qty":"Qty Available"}
|
||
```
|
||
|
||
说明:
|
||
|
||
- 本节点只负责“列名建议”,不负责决定库存是否可继续匹配。
|
||
- 若模型效果不稳定,应先调整 Prompt 与样例,不要把列映射容错逻辑堆到下游 If-Else 节点。
|
||
|
||
##### 节点:列映射 JSON 标准化
|
||
|
||
输入映射:
|
||
|
||
| 变量名 | 来源 |
|
||
| ------ | ---------------- |
|
||
| `text` | `库存列映射 LLM.text` |
|
||
|
||
输出:
|
||
|
||
| 字段 | 说明 |
|
||
| --------------------- | ----------- |
|
||
| `map_json` | 合法 JSON 字符串 |
|
||
| `mapping_ok` | 是否成功 |
|
||
| `error_message` | 错误提示 |
|
||
|
||
代码:
|
||
|
||
```python
|
||
import json
|
||
|
||
def main(text: str = ""):
|
||
raw = str(text or "").strip()
|
||
try:
|
||
mapping = json.loads(raw) if raw else {}
|
||
except json.JSONDecodeError:
|
||
mapping = None
|
||
if not isinstance(mapping, dict):
|
||
return {
|
||
"map_json": "{}",
|
||
"mapping_ok": False,
|
||
"error_message": "库存列映射生成失败:LLM 未返回合法 JSON。请检查表头是否清晰,或人工更正列名后重试。",
|
||
}
|
||
allowed_keys = {"reservation_id", "sku", "available_qty"}
|
||
normalized = {k: str(v or "").strip() for k, v in mapping.items() if k in allowed_keys}
|
||
if not normalized.get("reservation_id") or not normalized.get("sku"):
|
||
return {
|
||
"map_json": json.dumps(normalized, ensure_ascii=False),
|
||
"mapping_ok": False,
|
||
"error_message": "库存列映射不完整:至少需要识别“预订单号”和“料号”两列。请人工确认后重试。",
|
||
}
|
||
return {
|
||
"map_json": json.dumps(normalized, ensure_ascii=False),
|
||
"mapping_ok": True,
|
||
"error_message": "",
|
||
}
|
||
```
|
||
|
||
说明:
|
||
|
||
- 本节点只校验并规范化 LLM 返回的 `map_json`,不生成业务结论。
|
||
- 字段缺失、JSON 非法等失败都应在这里收口成统一错误文本,供后续 Answer 节点直接展示。
|
||
- Dify OpenAPI Tool 参数使用 `string` 才能稳定选择上游变量,因此本节点输出 JSON 字符串;后端仍兼容对象入参,仅供 Hxops 前端内部调用。
|
||
|
||
##### 节点:库存列映射是否成功
|
||
|
||
类型:`If-Else`
|
||
|
||
条件配置(直接照填):
|
||
|
||
```text
|
||
左值:列映射 JSON 标准化.mapping_ok
|
||
运算符:is
|
||
右值:true
|
||
```
|
||
|
||
true:
|
||
|
||
- 进入 `Tool 应用库存列映射`
|
||
|
||
false:
|
||
|
||
- 进入 `列映射失败回复`
|
||
|
||
说明:
|
||
|
||
- 这里的判断标准只看 `mapping_ok`,不在 If-Else 节点内重复解析 JSON。
|
||
- `false` 时必须直接回复用户,不允许带着非法 `map_json` 继续调 `apply_inventory_mapping`。
|
||
|
||
##### 节点:列映射失败回复
|
||
|
||
类型:`Answer`
|
||
|
||
内容:
|
||
|
||
```text
|
||
{{#列映射 JSON 标准化.error_message#}}
|
||
```
|
||
|
||
说明:
|
||
|
||
- 本节点只输出列映射失败原因。
|
||
- 若后续要支持“人工修改映射后重试”的更细引导,应在失败文案里补充,而不是在本节点再做分支。
|
||
|
||
##### 节点:Tool 应用库存列映射
|
||
|
||
Tool 绑定:
|
||
|
||
| 项 | 值 |
|
||
| -------------------- | ------------------------- |
|
||
| provider\_show\_name | `Hxops Shipping Notice` |
|
||
| tool\_name | `apply_inventory_mapping` |
|
||
|
||
参数映射:
|
||
|
||
| 参数名 | 来源 | 是否必填 | 说明 |
|
||
| --------------------- | ---------------------------------------- | ---- | ------------------------- |
|
||
| `task_id` | `{{#库存任务检查.task_id#}}` | 是 | 当前库存文件所属任务号 |
|
||
| `map_json` | `{{#列映射 JSON 标准化.map_json#}}` | 是 | 由库存列映射 LLM 产出的合法 JSON 字符串 |
|
||
|
||
输出:
|
||
|
||
| 字段 | 说明 |
|
||
| ------ | ------------------------------------ |
|
||
| `text` | Tool 原始返回 JSON 字符串,必须交给 `映射结果标准化` 处理 |
|
||
|
||
说明:
|
||
|
||
- 本节点提交的只是 `task_id + map_json`,不在画布层追加任何自动推进逻辑。
|
||
- `apply_inventory_mapping` 返回后是否进入人工确认、是否继续自动续跑,以后端返回为准。
|
||
|
||
##### 节点:映射结果标准化
|
||
|
||
输入映射:
|
||
|
||
| 变量名 | 来源 |
|
||
| ------ | ------------------- |
|
||
| `text` | `Tool 应用库存列映射.text` |
|
||
|
||
输出:
|
||
|
||
| 字段 | 说明 |
|
||
| ----------------- | --------------- |
|
||
| `tool_status` | Tool 状态 |
|
||
| `tool_message` | Tool message |
|
||
| `tool_checkpoint` | Tool checkpoint |
|
||
| `raw_json` | 全量 JSON |
|
||
|
||
代码:
|
||
|
||
```python
|
||
import json
|
||
|
||
def main(text: str = ""):
|
||
raw = str(text or "").strip()
|
||
try:
|
||
data = json.loads(raw) if raw else {}
|
||
except json.JSONDecodeError:
|
||
data = {}
|
||
if not isinstance(data, dict):
|
||
data = {}
|
||
return {
|
||
"tool_status": str(data.get("status") or "").strip(),
|
||
"tool_message": str(data.get("message") or "").strip(),
|
||
"tool_checkpoint": str(data.get("checkpoint") or "").strip(),
|
||
"raw_json": json.dumps(data, ensure_ascii=False),
|
||
}
|
||
```
|
||
|
||
说明:
|
||
|
||
- 本节点只做结果标准化,不做“是否继续匹配”的业务判断。
|
||
- 后续进入 Agent 时,应由 Agent 基于 `tool_status / tool_checkpoint / raw_json` 决定如何解释当前状态。
|
||
|
||
##### 节点:直接回复(引导)
|
||
|
||
类型:`Answer`
|
||
|
||
内容:
|
||
|
||
```text
|
||
{{#分支调度.final_reply#}}
|
||
```
|
||
|
||
说明:
|
||
|
||
- 本节点只负责输出固定引导文案,例如空输入、无任务号、通知附件需回引 Hxops 等场景。
|
||
- 若引导策略变化,应优先修改 `分支调度.final_reply` 的生成规则,本节点保持纯展示。
|
||
|
||
##### 节点:准备读取任务状态
|
||
|
||
输入映射:
|
||
|
||
| 变量名 | 来源 |
|
||
| ------------------ | --------------------------------------- |
|
||
| `resolved_task_no` | `分支调度.resolved_task_no` |
|
||
| `conversation_id` | `用户意图预处理.conversation_id` |
|
||
|
||
输出:
|
||
|
||
| 字段 | 说明 |
|
||
| ----------------- | --- |
|
||
| `task_id` | 任务号 |
|
||
| `conversation_id` | 会话号 |
|
||
|
||
代码:
|
||
|
||
```python
|
||
def main(resolved_task_no: str = "", conversation_id: str = ""):
|
||
task_id = str(resolved_task_no or "").strip().upper()
|
||
return {
|
||
"task_id": task_id,
|
||
"conversation_id": str(conversation_id or "").strip(),
|
||
}
|
||
```
|
||
|
||
说明:
|
||
|
||
- 本节点只做任务状态查询入参收口,不做业务判断。
|
||
- 若后续需要支持“仅凭 conversation_id 定位任务”,也只在本节点补充收口逻辑,不改后续 Tool 节点绑定方式。
|
||
|
||
##### 节点:Tool 读取任务状态
|
||
|
||
Tool 绑定:
|
||
|
||
| 项 | 值 |
|
||
| -------------------- | ----------------------- |
|
||
| provider\_show\_name | `Hxops Shipping Notice` |
|
||
| tool\_name | `get_task_status` |
|
||
|
||
参数映射:
|
||
|
||
| 参数名 | 来源 | 是否必填 | 说明 |
|
||
| ----------------- | ------------------------------------- | ---- | ---------------- |
|
||
| `task_id` | `{{#准备读取任务状态.task_id#}}` | 是 | 当前任务号,是任务续办链的主键 |
|
||
| `conversation_id` | `{{#准备读取任务状态.conversation_id#}}` | 否 | 用于辅助后端做会话关联与任务定位 |
|
||
|
||
输出:
|
||
|
||
| 字段 | 说明 |
|
||
| ------ | --------------------------------------------------- |
|
||
| `text` | Tool 原始返回 JSON 字符串,必须交给 `工具结果标准化` 处理 |
|
||
|
||
说明:
|
||
|
||
- 本节点是任务续办链的统一状态入口。
|
||
- 后续所有“是否待解析 / 是否可直连动作 / Agent 解释输入”都基于本节点返回结果,不应绕过本节点直接猜测任务状态。
|
||
|
||
##### 节点:工具结果标准化
|
||
|
||
输入映射:
|
||
|
||
| 变量名 | 来源 |
|
||
| ------ | --------------------------------- |
|
||
| `text` | `Tool 读取任务状态.text` |
|
||
|
||
输出:
|
||
|
||
| 字段 | 说明 |
|
||
| --------------------- | --------------- |
|
||
| `tool_status` | 后端 `status` |
|
||
| `tool_message` | 后端 `message` |
|
||
| `tool_checkpoint` | 后端 `checkpoint` |
|
||
| `tool_data_json` | `data` JSON 字符串 |
|
||
| `raw_json` | 全量 JSON 字符串 |
|
||
| `current_task_no` | 当前任务号 |
|
||
| `has_raw_text` | 是否拿到待解析原文 |
|
||
| `should_parse_notice` | 当前任务是否应进入首轮通知解析 |
|
||
|
||
代码:
|
||
|
||
```python
|
||
import json
|
||
|
||
def main(text: str = ""):
|
||
raw = str(text or "").strip()
|
||
try:
|
||
data = json.loads(raw) if raw else {}
|
||
except json.JSONDecodeError:
|
||
data = {}
|
||
if not isinstance(data, dict):
|
||
data = {}
|
||
payload = data.get("data") if isinstance(data.get("data"), dict) else {}
|
||
raw_text = str(payload.get("raw_text") or "").strip()
|
||
lines = payload.get("lines") if isinstance(payload.get("lines"), list) else []
|
||
has_lines = isinstance(lines, list) and len(lines) > 0
|
||
task_no = str(data.get("task_id") or payload.get("task_no") or "").strip().upper()
|
||
should_parse_notice = bool(raw_text and not has_lines)
|
||
return {
|
||
"tool_status": str(data.get("status") or "").strip(),
|
||
"tool_message": str(data.get("message") or "").strip(),
|
||
"tool_checkpoint": str(data.get("checkpoint") or "").strip(),
|
||
"tool_data_json": json.dumps(payload, ensure_ascii=False),
|
||
"raw_json": json.dumps(data, ensure_ascii=False),
|
||
"current_task_no": task_no,
|
||
"has_raw_text": bool(raw_text),
|
||
"should_parse_notice": should_parse_notice,
|
||
}
|
||
```
|
||
|
||
说明:
|
||
|
||
- 本节点只读取 `Tool 读取任务状态.text`
|
||
- 不要写 `body`
|
||
- **首轮通知解析时** **`tool_checkpoint`** **允许为空**,这是正常现象;不能把 `tool_checkpoint` 当成“是否进入订单解析”的唯一条件
|
||
- 正确口径优先判断:`raw_text` 是否存在且 `lines` 是否为空。Tool 投影可能裁剪内部状态码,不能强依赖 `process_status/current_step`。
|
||
|
||
##### 节点:当前任务动作判断
|
||
|
||
输入映射:
|
||
|
||
| 变量名 | 来源 |
|
||
| ------------------ | ---------------------------------------- |
|
||
| `intent_hint` | `用户意图预处理.intent_hint` |
|
||
| `resolved_task_no` | `分支调度.resolved_task_no` |
|
||
| `tool_checkpoint` | `工具结果标准化.tool_checkpoint` |
|
||
|
||
输出:
|
||
|
||
| 字段 | 说明 |
|
||
| --------------- | ------------------ |
|
||
| `direct_action` | 可绕开 Agent 直接执行的动作名 |
|
||
| `need_agent` | 布尔值 `true / false`,不能返回字符串 |
|
||
|
||
代码:
|
||
|
||
```python
|
||
def main(intent_hint: str = "", resolved_task_no: str = "", tool_checkpoint: str = ""):
|
||
hint = str(intent_hint or "").strip()
|
||
task_no = str(resolved_task_no or "").strip().upper()
|
||
checkpoint = str(tool_checkpoint or "").strip().lower()
|
||
|
||
direct_actions = {
|
||
"retry_rpa",
|
||
"confirm",
|
||
"reject",
|
||
"reparse",
|
||
"confirm_inventory_mapping",
|
||
"correct_inventory_mapping",
|
||
"reparse_inventory",
|
||
"rematch",
|
||
}
|
||
|
||
direct_action = ""
|
||
if hint == "confirm" and checkpoint == "align_review":
|
||
direct_action = "confirm_inventory_mapping"
|
||
elif hint in direct_actions:
|
||
direct_action = hint
|
||
|
||
if hint == "parse_notice" and task_no:
|
||
return {
|
||
"direct_action": "",
|
||
"need_agent": True,
|
||
}
|
||
|
||
if direct_action and task_no:
|
||
return {
|
||
"direct_action": direct_action,
|
||
"need_agent": False,
|
||
}
|
||
|
||
return {
|
||
"direct_action": "",
|
||
"need_agent": True,
|
||
}
|
||
```
|
||
|
||
说明:
|
||
|
||
- 本节点的目标是**减少 Agent 调用时间**。
|
||
- 对于已由上游代码节点明确识别的短动作,直接走 Tool 即可,不要再让 Agent 做第二轮判断。
|
||
- 当前生产优先绕开 Agent 的动作包括:`retry_rpa / confirm / reject / reparse / confirm_inventory_mapping / correct_inventory_mapping / reparse_inventory / rematch`。
|
||
- 当用户只输入 `确认` 且当前 `checkpoint=align_review` 时,应标准化为 `confirm_inventory_mapping`,优先进入库存字段对齐确认直连链,而不是误调普通 `confirm`。
|
||
- `need_agent` 必须返回布尔值 `True/False`,不要返回字符串 `"true" / "false"`;否则 Dify If-Else 可能把 `"false"` 当作 truthy,导致直连动作分支失效。
|
||
- `parse_notice` 是后台解析意图,应进入固定的 `是否待解析通知` 链,不作为直连 Tool 动作。
|
||
|
||
##### 节点:是否进入 Agent
|
||
|
||
类型:`If-Else`
|
||
|
||
条件配置(直接照填):
|
||
|
||
```text
|
||
左值:当前任务动作判断.need_agent
|
||
运算符:is
|
||
右值:true
|
||
```
|
||
|
||
true:
|
||
|
||
- 进入 `是否待解析通知`
|
||
|
||
false:
|
||
|
||
- 进入 `当前任务直连动作分支`
|
||
|
||
说明:
|
||
|
||
- 这个节点的目标是把**短动作**与**模糊自由输入**彻底分开。
|
||
- `继续处理 / 为什么卡住 / 第二行改成 12` 这类消息仍走通知解析 / Agent 链。
|
||
- `确认 / 驳回 / 重解析 / 重新匹配 / 重试 RPA` 这类确定性动作直接进入 Tool,不再经过 Agent。
|
||
|
||
##### 节点:当前任务直连动作分支
|
||
|
||
类型:`If-Else / Branch`
|
||
|
||
输入字段:
|
||
|
||
```text
|
||
当前任务动作判断.direct_action
|
||
```
|
||
|
||
分支配置(直接照填):
|
||
|
||
```text
|
||
retry_rpa ----------------------> Tool 重试库存导出
|
||
confirm ------------------------> Tool 提交当前任务决策
|
||
reject -------------------------> Tool 提交当前任务决策
|
||
reparse ------------------------> Tool 提交当前任务决策
|
||
confirm_inventory_mapping -----> Tool 提交当前任务决策
|
||
correct_inventory_mapping -----> Tool 提交当前任务决策
|
||
reparse_inventory -------------> Tool 提交当前任务决策
|
||
rematch -----------------------> Tool 重新匹配库存
|
||
其他 / 默认 --------------------> Agent 状态输入标准化
|
||
```
|
||
|
||
说明:
|
||
|
||
- 这里不要再把 `direct_action` 交给 Agent 解释。
|
||
- 只要分支命中,就直接执行对应 Tool,并统一汇入 `直连动作结果标准化`。
|
||
|
||
##### 节点:当前任务直连 Tool 节点
|
||
|
||
以下节点建议统一从 `准备读取任务状态.task_id` 取 `task_id`,并在执行后全部汇入 `直连动作结果标准化`。
|
||
|
||
| 节点名 | 绑定 Tool | 参数映射 | 说明 |
|
||
| ------------- | ------------------------- | ----------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------- |
|
||
| Tool 重试库存导出 | `submit_decision` | `task_id={{#准备读取任务状态.task_id#}}`;`decision=retry_rpa` | 用户触发重试 RPA 导出库存时使用,真正恢复由后端 RPA workflow 执行 |
|
||
| Tool 提交当前任务决策 | `submit_decision` | `task_id={{#准备读取任务状态.task_id#}}`;`decision={{#当前任务动作判断.direct_action#}}` | 用同一个 Tool 节点统一承接 `confirm / reject / reparse / confirm_inventory_mapping / correct_inventory_mapping / reparse_inventory` |
|
||
| Tool 重新匹配库存 | `submit_decision` 或等价恢复入口 | `task_id={{#准备读取任务状态.task_id#}}`;按当前实现映射为重匹配类 decision | 在库存已就绪的前提下请求后端重新执行匹配 |
|
||
|
||
说明:
|
||
|
||
- 这里故意**不**把 `confirm_inventory_mapping` 绑定成 `auto_progress`。
|
||
- 原因是“确认字段对齐”语义上属于**确认当前步骤**,更适合显式落到 `submit_decision(confirm_inventory_mapping)`;后续是否自动推进,交给后端状态机或后续 `继续` / Agent 决策处理。
|
||
- 这样可以避免用户只是点击“确认映射”,却在画布层面被直接解释成“立刻推进后续全部动作”。
|
||
|
||
##### 节点:直连动作结果标准化
|
||
|
||
输入映射:
|
||
|
||
| 变量名 | 来源 |
|
||
| ---------------------- | -------------------- |
|
||
| `retry_rpa_text` | `Tool 重试库存导出.text` |
|
||
| `submit_decision_text` | `Tool 提交当前任务决策.text` |
|
||
| `rematch_text` | `Tool 重新匹配库存.text` |
|
||
|
||
输出:
|
||
|
||
| 字段 | 说明 |
|
||
| ----------------- | ------------------ |
|
||
| `tool_status` | Tool 状态 |
|
||
| `tool_message` | Tool message |
|
||
| `tool_checkpoint` | Tool checkpoint |
|
||
| `raw_json` | 全量 JSON |
|
||
| `answer_text` | 给 Answer 节点直接回复的文本 |
|
||
|
||
代码:
|
||
|
||
```python
|
||
import json
|
||
|
||
def _pick_first(*values):
|
||
for value in values:
|
||
raw = str(value or "").strip()
|
||
if raw:
|
||
return raw
|
||
return ""
|
||
|
||
def main(
|
||
retry_rpa_text: str = "",
|
||
submit_decision_text: str = "",
|
||
rematch_text: str = "",
|
||
):
|
||
raw = _pick_first(
|
||
retry_rpa_text,
|
||
submit_decision_text,
|
||
rematch_text,
|
||
)
|
||
try:
|
||
data = json.loads(raw) if raw else {}
|
||
except json.JSONDecodeError:
|
||
data = {}
|
||
if not isinstance(data, dict):
|
||
data = {}
|
||
|
||
answer_text = str(data.get("message") or "").strip()
|
||
if not answer_text:
|
||
answer_text = "操作已提交,请继续根据当前任务提示处理。"
|
||
|
||
return {
|
||
"tool_status": str(data.get("status") or "").strip(),
|
||
"tool_message": str(data.get("message") or "").strip(),
|
||
"tool_checkpoint": str(data.get("checkpoint") or "").strip(),
|
||
"raw_json": json.dumps(data, ensure_ascii=False),
|
||
"answer_text": answer_text,
|
||
}
|
||
```
|
||
|
||
说明:
|
||
|
||
- 所有直连 Tool 都应汇入本节点,避免为每个短动作单独配一个 Answer 节点。
|
||
- 本节点只做**统一收口**,不负责下一步智能判断。
|
||
|
||
##### 节点:直接回复(动作结果)
|
||
|
||
类型:`Answer`
|
||
|
||
内容:
|
||
|
||
```text
|
||
{{#直连动作结果标准化.answer_text#}}
|
||
```
|
||
|
||
说明:
|
||
|
||
- 本节点只负责输出直连动作结果文本,不追加二次解释。
|
||
- 若需要更丰富的动作后提示,应先改 `直连动作结果标准化` 的收口文案,再由本节点原样输出。
|
||
|
||
##### 节点:是否待解析通知
|
||
|
||
类型:`If-Else`
|
||
|
||
推荐条件配置(直接照填):
|
||
|
||
```text
|
||
条件组 1(唯一生产条件):
|
||
左值:工具结果标准化.should_parse_notice
|
||
运算符:is
|
||
右值:true
|
||
```
|
||
|
||
说明:
|
||
|
||
- **不要**再按 `tool_checkpoint` 判断首轮通知解析,因为新任务在解析前很可能出现:
|
||
- `tool_checkpoint = ""`
|
||
- `process_status = created`
|
||
- `current_step = null`
|
||
- `raw_text` 有值
|
||
- `lines = []`
|
||
- 上述场景下,仍然**必须进入** `提取通知原文 -> 订单需求解析 LLM -> Tool 解析发货通知`
|
||
- 如果线上出现“系统说将开始解析,但没有进入订单需求解析 LLM”,优先检查这里是否仍错误绑定在 `tool_checkpoint`
|
||
|
||
true:
|
||
|
||
- 进入 `提取通知原文`
|
||
|
||
false:
|
||
|
||
- 直接进入 `Agent 状态输入标准化`
|
||
|
||
说明:
|
||
|
||
- 本节点是“首轮通知解析”唯一合法入口判断,不允许再复制第二套解析门槛。
|
||
- 一旦 `should_parse_notice=false`,后续只允许进入状态解释 / 续办链,不应再在 Agent 内补做首轮解析判断。
|
||
|
||
##### 节点:提取通知原文
|
||
|
||
输入映射:
|
||
|
||
| 变量名 | 来源 |
|
||
| ---------- | --------------------------------- |
|
||
| `raw_json` | `工具结果标准化.raw_json` |
|
||
|
||
输出:
|
||
|
||
| 字段 | 说明 |
|
||
| ----------------- | ----------------- |
|
||
| `task_id` | 当前任务号 |
|
||
| `notice_raw_text` | 通知正文文本 |
|
||
| `parse_msg` | 若已有后端 parse 提示则透传 |
|
||
|
||
代码:
|
||
|
||
```python
|
||
import json
|
||
|
||
def main(raw_json: str = ""):
|
||
try:
|
||
data = json.loads(str(raw_json or "").strip() or "{}")
|
||
except json.JSONDecodeError:
|
||
data = {}
|
||
payload = data.get("data") if isinstance(data.get("data"), dict) else {}
|
||
task_id = str(
|
||
payload.get("task_id")
|
||
or payload.get("task_no")
|
||
or data.get("task_id")
|
||
or ""
|
||
).strip().upper()
|
||
notice_raw_text = str(payload.get("raw_text") or "").strip()
|
||
parse_msg = str(data.get("message") or payload.get("parse_msg") or "").strip()
|
||
return {
|
||
"task_id": task_id,
|
||
"notice_raw_text": notice_raw_text,
|
||
"parse_msg": parse_msg,
|
||
}
|
||
```
|
||
|
||
说明:
|
||
|
||
- 当 `notice_raw_text` 非空、`task_id` 存在时,本链路应立即进入 `订单需求解析 LLM`
|
||
- 若这里已经拿到 `raw_text`,但画布仍直接跳去 Agent,说明 `是否待解析通知` 条件仍配错
|
||
|
||
##### 节点:订单需求解析 LLM
|
||
|
||
类型:`LLM`
|
||
|
||
模型建议:
|
||
|
||
| 项 | 值 |
|
||
| ----------- | ------------- |
|
||
| provider | `openai` |
|
||
| model | `gpt-4o-mini` |
|
||
| temperature | `0.1` |
|
||
|
||
System Prompt:
|
||
|
||
```text
|
||
你是发货通知订单需求解析助手。
|
||
|
||
当前前提已经成立:
|
||
- 用户已在 Hxops 上传发货通知
|
||
- Hxops 已完成建 task / 建 batch / raw_text 落库
|
||
- 当前节点的唯一职责,是立即把 `raw_text` 解析成结构化 JSON,供后续 `parse_notice(structured=...)` 调用
|
||
|
||
强制规则:
|
||
1. 你必须立即执行解析,禁止输出任何确认性话术。
|
||
2. 禁止询问“是否开始解析”“是否现在开始解析”“请确认是否开始解析”“是否需要我解析”等同义句。
|
||
3. 禁止输出解释、说明、寒暄、Markdown、代码块。
|
||
4. 只允许输出一个可被下游 Code 节点直接解析的 JSON 对象。
|
||
5. 若字段无法确定,可输出空字符串、空数组或 null,但仍必须返回合法 JSON。
|
||
|
||
请把发货通知正文解析成结构化 JSON,只输出 JSON,不要输出解释。
|
||
|
||
输出字段要求:
|
||
{
|
||
"customer_name": "",
|
||
"customer_code": "",
|
||
"ship_to": "",
|
||
"po_number": "",
|
||
"required_date": "",
|
||
"lines": [
|
||
{
|
||
"reservation_id": "",
|
||
"sku": "",
|
||
"qty": 0,
|
||
"uom": "",
|
||
"required_date": ""
|
||
}
|
||
]
|
||
}
|
||
|
||
规则:
|
||
1. 只输出合法 JSON object
|
||
2. lines 必须是数组
|
||
3. 若识别不到字段,返回空字符串或 0,不要臆造
|
||
4. reservation_id、sku、qty 尽量逐行抽取
|
||
5. 不要输出 markdown,不要输出代码块
|
||
```
|
||
|
||
User Prompt:
|
||
|
||
```text
|
||
请解析下面这份发货通知正文,输出 structured JSON:
|
||
|
||
{{#提取通知原文.notice_raw_text#}}
|
||
```
|
||
|
||
说明:
|
||
|
||
- 本节点的职责是“立即把 `raw_text` 转成结构化对象”,不是与用户对话。
|
||
- 若未来调整模型或字段抽取策略,只改 Prompt,不改下游 `parse_notice` 调用方式。
|
||
|
||
##### 节点:结构化结果标准化
|
||
|
||
输入映射:
|
||
|
||
| 变量名 | 来源 |
|
||
| ------ | ----------------- |
|
||
| `text` | `订单需求解析 LLM.text` |
|
||
|
||
输出:
|
||
|
||
| 字段 | 说明 |
|
||
| ----------------- | ------------------------------- |
|
||
| `structured_json` | 可直接传给 `parse_notice` 的 JSON 字符串 |
|
||
| `parse_ok` | 是否为合法 structured |
|
||
| `error_message` | 非法时的提示 |
|
||
|
||
代码:
|
||
|
||
```python
|
||
import json
|
||
|
||
def main(text: str = ""):
|
||
raw = str(text or "").strip()
|
||
try:
|
||
payload = json.loads(raw) if raw else {}
|
||
except json.JSONDecodeError:
|
||
payload = None
|
||
if not isinstance(payload, dict):
|
||
return {
|
||
"structured_json": "{}",
|
||
"parse_ok": False,
|
||
"error_message": "订单需求解析失败:LLM 未返回合法 JSON。",
|
||
}
|
||
lines = payload.get("lines")
|
||
if not isinstance(lines, list):
|
||
return {
|
||
"structured_json": json.dumps(payload, ensure_ascii=False),
|
||
"parse_ok": False,
|
||
"error_message": "订单需求解析失败:structured.lines 不是数组。",
|
||
}
|
||
return {
|
||
"structured_json": json.dumps(payload, ensure_ascii=False),
|
||
"parse_ok": True,
|
||
"error_message": "",
|
||
}
|
||
```
|
||
|
||
说明:
|
||
|
||
- 本节点只验证 LLM 输出是否可作为 `structured` 入参,不负责补字段或修正文意。
|
||
- `parse_ok=false` 时必须在当前链路终止并提示用户,不允许带着非法 structured 继续调用 `parse_notice`。
|
||
|
||
##### 节点:Tool 解析发货通知
|
||
|
||
Tool 绑定:
|
||
|
||
| 项 | 值 |
|
||
| -------------------- | ----------------------- |
|
||
| provider\_show\_name | `Hxops Shipping Notice` |
|
||
| tool\_name | `parse_notice` |
|
||
|
||
参数映射:
|
||
|
||
| 参数名 | 来源 | 是否必填 | 说明 |
|
||
| ------------ | -------------------------------- | ---- | ----------------------------------------- |
|
||
| `task_id` | `{{#提取通知原文.task_id#}}` | 是 | 当前通知任务号 |
|
||
| `structured` | `{{#结构化结果标准化.structured_json#}}` | 是 | Dify LLM 解析后的 structured 对象 |
|
||
| `raw_text` | 空字符串 `""` | 否 | 原始通知全文已保存在 HXOPS `ShippingTask.raw_content`,Dify 只提交 structured |
|
||
| `lang` | `zh` / `en` / `th` | 否 | 返回提示语语言;不传则后端按请求头或默认 `zh` |
|
||
|
||
输出:
|
||
|
||
| 字段 | 说明 |
|
||
| ------ | ------------------------------------ |
|
||
| `text` | Tool 原始返回 JSON 字符串,必须交给 `解析结果标准化` 处理 |
|
||
|
||
说明:
|
||
|
||
- 这里的目标就是 `parse_notice(structured=...)`
|
||
- 本节点之前的上游 LLM / Code 节点必须已经完成“立即解析”;
|
||
- 本节点不允许再回到“是否开始解析”的确认语义;
|
||
- 若线上仍出现“请确认是否开始解析”,说明问题不在本 Tool 节点,而在上游 LLM 节点或 Agent 指令仍残留旧提示词。
|
||
- 后端收到 `structured` 后应优先使用 structured
|
||
- 只有 structured 缺失或不完整时,后端才走 heuristic fallback
|
||
- `structured` 必须绑定为对象参数;`raw_text` 推荐留空,避免把已落库原文重复作为本轮用户输入传递。
|
||
- 若当前 Dify 版本把 `structured_json` 当纯文本传入,则需在 Tool 参数编辑器里将 `structured` 按 JSON / Object 方式映射,避免请求体把 structured 传成带引号字符串。
|
||
- **不要**把 `structured_json` 塞到 `raw_text`,否则后端会把整段 JSON 当普通文本兜底重解析,可能导致 `lines` 丢失并错误返回“未解析到订单明细行”
|
||
|
||
##### 节点:解析结果标准化
|
||
|
||
输入映射:
|
||
|
||
| 变量名 | 来源 |
|
||
| ------ | ------------------ |
|
||
| `text` | `Tool 解析发货通知.text` |
|
||
|
||
输出:
|
||
|
||
| 字段 | 说明 |
|
||
| ----------------- | --------------- |
|
||
| `tool_status` | Tool 状态 |
|
||
| `tool_message` | Tool message |
|
||
| `tool_checkpoint` | Tool checkpoint |
|
||
| `raw_json` | 全量 JSON |
|
||
| `answer_text` | 可直接展示给用户的解析结果文案 |
|
||
|
||
代码:
|
||
|
||
```python
|
||
import json
|
||
|
||
def main(text: str = ""):
|
||
raw = str(text or "").strip()
|
||
try:
|
||
data = json.loads(raw) if raw else {}
|
||
except json.JSONDecodeError:
|
||
data = {}
|
||
if not isinstance(data, dict):
|
||
data = {}
|
||
answer_text = str(data.get("message") or "").strip() or "发货通知已解析完成,请确认解析结果。"
|
||
return {
|
||
"tool_status": str(data.get("status") or "").strip(),
|
||
"tool_message": str(data.get("message") or "").strip(),
|
||
"tool_checkpoint": str(data.get("checkpoint") or "").strip(),
|
||
"raw_json": json.dumps(data, ensure_ascii=False),
|
||
"answer_text": answer_text,
|
||
}
|
||
```
|
||
|
||
说明:
|
||
|
||
- 本节点只做 `parse_notice` 返回结果的标准化,不在这里解释“是否应继续”。
|
||
- 后续是否进入 Agent、是否停在人工节点,以 `tool_status / tool_checkpoint / raw_json` 为准。
|
||
|
||
##### 节点:Agent 状态输入标准化
|
||
|
||
输入映射:
|
||
|
||
| 变量名 | 来源 |
|
||
| -------------------- | --------------------------------- |
|
||
| `status_raw_json` | `工具结果标准化.raw_json` |
|
||
| `parsed_raw_json` | `解析结果标准化.raw_json` |
|
||
| `inventory_raw_json` | `映射结果标准化.raw_json` |
|
||
| `fallback_task_id` | `准备读取任务状态.task_id` |
|
||
|
||
输出:
|
||
|
||
| 字段 | 说明 |
|
||
| ------------------ | ------------------------ |
|
||
| `agent_raw_json` | 当前应传给 Agent 的最新后端状态 JSON |
|
||
| `agent_task_id` | 当前任务号 |
|
||
| `agent_checkpoint` | 当前 checkpoint |
|
||
|
||
代码:
|
||
|
||
```python
|
||
import json
|
||
|
||
def _load_json(text: str):
|
||
raw = str(text or "").strip()
|
||
if not raw:
|
||
return {}
|
||
try:
|
||
data = json.loads(raw)
|
||
except json.JSONDecodeError:
|
||
return {}
|
||
return data if isinstance(data, dict) else {}
|
||
|
||
def _extract_task_id(payload: dict):
|
||
body = payload.get("data") if isinstance(payload.get("data"), dict) else {}
|
||
return str(
|
||
body.get("task_id")
|
||
or body.get("task_no")
|
||
or payload.get("task_id")
|
||
or payload.get("task_no")
|
||
or ""
|
||
).strip().upper()
|
||
|
||
def main(status_raw_json: str = "", parsed_raw_json: str = "", inventory_raw_json: str = "", fallback_task_id: str = ""):
|
||
status_payload = _load_json(status_raw_json)
|
||
parsed_payload = _load_json(parsed_raw_json)
|
||
inventory_payload = _load_json(inventory_raw_json)
|
||
|
||
selected = status_payload
|
||
if parsed_payload:
|
||
selected = parsed_payload
|
||
if inventory_payload:
|
||
selected = inventory_payload
|
||
|
||
return {
|
||
"agent_raw_json": json.dumps(selected, ensure_ascii=False),
|
||
"agent_task_id": _extract_task_id(selected) or str(fallback_task_id or "").strip().upper(),
|
||
"agent_checkpoint": str(selected.get("checkpoint") or "").strip(),
|
||
}
|
||
```
|
||
|
||
##### 节点:货代续办 Agent
|
||
|
||
类型:`Agent`
|
||
|
||
基础配置:
|
||
|
||
| 项 | 值 |
|
||
| ------------------ | ------------------ |
|
||
| Strategy | `Function Calling` |
|
||
| Maximum Iterations | `10` |
|
||
| Memory Window | `10` |
|
||
| Instruction | 使用本节下方的完整指令 |
|
||
| Query | 使用本节下方的 Query 模板 |
|
||
|
||
Query 模板:
|
||
|
||
```text
|
||
HXOPS 运行态上下文:
|
||
{{agent_runtime_context}}
|
||
|
||
当前 task_id:
|
||
{{#Agent 状态输入标准化.agent_task_id#}}
|
||
|
||
用户消息:
|
||
{{#用户意图预处理.normalized_query#}}
|
||
|
||
上一轮后端状态 JSON:
|
||
{{#Agent 状态输入标准化.agent_raw_json#}}
|
||
```
|
||
|
||
Agent 必开 Tool:
|
||
|
||
- `parse_agent_runtime_context`
|
||
- `get_task_status`
|
||
- `submit_decision`
|
||
- `update_notice_fields`
|
||
- `update_notice_line`
|
||
- `add_notice_line`
|
||
- `remove_notice_line`
|
||
- `get_batch_status`
|
||
|
||
Agent 禁用 Tool:
|
||
|
||
- `parse_notice`
|
||
- `apply_inventory_mapping`
|
||
|
||
前端动作,不配置为 Agent Tool:
|
||
|
||
- `upload_inventory_file`
|
||
- `paste_inventory_json`
|
||
- `edit_inventory_mapping`
|
||
- `match_inventory`
|
||
- `generate_excel`
|
||
- `download_excel`
|
||
- `retry_upload`
|
||
- `mark_manual_uploaded`
|
||
- `refresh`
|
||
- `replace_notice_file`
|
||
|
||
说明:
|
||
|
||
- 以上动作可能出现在后端返回的 `human_options / action_buttons` 中,但它们属于 **宿主系统按钮或宿主交互动作**,不是 Dify 可直接调用的 OpenAPI Tool。
|
||
- Agent 的职责是解释当前状态、业务原因和影响;可点击动作由宿主系统根据 `action_buttons` 统一渲染。Agent 不能把这些 action id 当作 Tool 名称去调用,也不要在自然语言正文中重复列出“推荐下一步”“请选择操作”“1. 刷新 / 2. 下载 Excel”之类的操作清单。
|
||
- 本节点负责模糊问题解释、自由输入收口与有限 Tool 调用,不负责首层路由或长链路编排。
|
||
- 若线上出现 Agent 越权调用 Tool,优先检查这里的 Tool 白名单、Instruction 与上游直连动作分支,而不是修改 Answer 节点。
|
||
|
||
##### 节点:Agent 指令(维护入口)
|
||
|
||
将以下内容直接粘贴到 `货代续办 Agent` 节点的 `Instruction`:
|
||
|
||
```text
|
||
#### 角色
|
||
你是 **货代发货通知助手**,通过发货通知 Tool API 处理客户发货指令。需要人工复核时暂停,等待用户明确选择后再继续。
|
||
发货通知已由 **当前对话上传并保存 raw_text**;随后由画布 LLM 节点解析订单需求,并调用 `parse_notice(structured=...)` 落库。你收到 `parse_msg`(或 `get_task_status.message`)后**原文展示**并引导确认。库存 Excel 由用户在当前对话上传后,由画布 **Tool 节点**完成列映射;Agent **禁止**自行推断 `map_json`,也不要脱离既定解析节点重复执行 `parse_notice`。
|
||
若用户用自然语言要求“改采购单号 / 改预订单号 / 改料号 / 改数量 / 新增一行 / 删除一行”,应优先调用 `update_notice_fields`、`update_notice_line`、`add_notice_line`、`remove_notice_line` 持久化修改,禁止只在回复里口头改写解析结果。
|
||
当 **当前对话** 已上传通知并自动发起首轮续办时,你**不得**再询问用户“是否开始解析”“是否现在开始解析”“请确认是否开始解析”。首轮续办的正确行为是:立即读取 `raw_text` → 由画布 LLM 节点抽取 structured → 调用 `parse_notice(structured=...)` → 再根据返回结果决定是否进入人工确认。只有当 `parse_notice` 或后端状态机明确返回 `needs_human` / `stop_agent_turn=true` 时,才允许进入确认语义。
|
||
首层附件分流由 Chatflow 的 Code 节点完成(通知/库存附件 → 引导回 **当前对话** 上传)。你负责第二层业务理解与 Tool 调用,**不要接管首层分流职责**。
|
||
#### 重新解析与重新上传边界
|
||
- `reparse` 只表示:基于当前任务已保存的 `raw_text` 重新执行 Dify 结构化抽取与 `parse_notice`,**不会重新读取原 PDF,也不会重跑 `loader_pdf`**。
|
||
- 当后端返回 `notice_text_extraction_failed`,说明当前任务没有可审核内容;用户应在宿主系统上传清晰版 PDF/文本,宿主系统调用 `/api/workspace/shipping-tasks/<task_no>/replace-notice` 覆盖当前任务通知文件。
|
||
- `replace-notice` 保留原 `task_no / batch_no / batch_index`,重新执行 `save_task_notice_upload → extract_notice_text(loader_pdf/OCR) → 覆盖 raw_content → 重置旧解析/匹配/导出状态 → 重新编排当前票`。
|
||
- 用户主动上传多份新通知时才新建批次;当前任务失败上下文里的单文件重新上传必须修复当前票,禁止误建新批次。
|
||
#### 主流程
|
||
【宿主系统已完成】建 task + raw_text 落库
|
||
→ Dify LLM 解析订单需求 + parse_notice(structured=...)
|
||
→ submit_decision(confirm)
|
||
→ Tool 库存上传(**当前对话** 前端)+ apply_inventory_mapping(Tool)
|
||
→ 【暂停】align_msg
|
||
→ submit_decision(confirm_inventory_mapping)
|
||
→ hxops worker 统一续跑匹配、Excel 生成与上传
|
||
#### Tool 响应字段
|
||
每轮 Tool 调用后必须读取:
|
||
| 字段 | 含义 |
|
||
|------|------|
|
||
| `status` | `ok` / `running` / `needs_human` / `failed` |
|
||
| `checkpoint` | 当前卡点(仅内部读,禁止对用户展示) |
|
||
| `stop_agent_turn` | `true` = 本轮立即停止,等待用户 |
|
||
| `forbidden_next_tools` | 禁止在本轮或下轮调用的 Tool |
|
||
| `human_options` | 须人工时的选项 |
|
||
| `action_buttons` | 宿主系统可渲染的按钮配置,Agent 只读取语义,不在正文重复列出 |
|
||
| `message` | 固定格式人类可读文案(须原文展示) |
|
||
| `data.schema_preview` | 表头 + 样例行 |
|
||
| `data.field_alignment` | 字段对齐详情 |
|
||
#### agent_runtime_context 使用规则
|
||
每轮可通过 Query 中的 `HXOPS 运行态上下文` 读取平台注入的 `agent_runtime_context`。该上下文只用于理解现场,不是业务事实源。
|
||
|
||
当用户使用以下模糊指代表达时,必须先调用 `parse_agent_runtime_context`:
|
||
- `继续`
|
||
- `继续处理`
|
||
- `这个`
|
||
- `那个`
|
||
- `刚才那个`
|
||
- `上一个失败的`
|
||
- `还是按之前的`
|
||
|
||
推荐读取 paths:
|
||
- `reference_context.focus_object.id`
|
||
- `reference_context.last_action_target.action`
|
||
- `reference_context.last_failed_target.reason`
|
||
- `reference_context.candidates`
|
||
- `refs.task_no`
|
||
- `refs.batch_no`
|
||
- `domain.state_hint.status`
|
||
|
||
规则:
|
||
1. 如果 `reference_context.candidates` 返回多个候选,必须追问用户选择具体任务,不得自行猜测。
|
||
2. 如果 `last_action_target.action=auto_focus`,只表示系统自动聚焦,不等同于用户主动要求处理该票。
|
||
3. 如果 `last_action_target.action=switch_focus`,可认为用户刚刚主动切换 focus,但推进前仍必须调用 HXOPS Tool 校验状态。
|
||
4. `confirm_parse` 与 `confirm_matched` 语义不同:前者表示确认解析结果,后者表示确认匹配/当前结果。
|
||
5. 任何确认、驳回、重匹配、重解析、状态推进,都必须调用 `submit_decision` 或其他 HXOPS Tool;禁止只根据上下文宣布“已完成”。
|
||
#### 回复格式契约
|
||
当 `action_buttons` 或 `human_options` 非空时,最终回复正文只能包含:
|
||
1. 一句当前状态。
|
||
2. 一句业务影响或原因。
|
||
3. 如确实需要用户操作,只写:`请使用下方按钮继续。`
|
||
禁止输出任何 Markdown / 文本操作清单,包括但不限于:
|
||
- `请选择以下方式`
|
||
- `请选择操作`
|
||
- `推荐下一步`
|
||
- `1. 选择库存文件`
|
||
- `2. 重试 RPA`
|
||
- `3. 粘贴库存`
|
||
- 任意把按钮文字重复写进正文的编号列表或项目符号列表
|
||
按钮、可点击动作、恢复入口只由宿主系统根据 `action_buttons` 渲染;Agent 正文不得复述。
|
||
#### 硬性规则
|
||
1. 后端是唯一真相源,Agent 不能脑补状态。
|
||
2. 每轮先看 `status`、`stop_agent_turn`、`forbidden_next_tools`、`human_options`;`message` / `parse_msg` / `align_msg` 须原文展示。
|
||
3. 工具返回 `needs_human` 或 `stop_agent_turn=true` 时,必须停下等待用户。
|
||
4. 工具返回 `forbidden_next_tools` 时,不能继续调用被禁止工具。
|
||
5. 未完成库存字段确认前,不能直接调 `match_inventory`。
|
||
6. `align_review` 首轮:原文展示 `align_msg` 后结束;用户确认后调用 `submit_decision(confirm_inventory_mapping)`。
|
||
7. 后续匹配、Excel、上传由后端 worker 统一续跑;Agent 不在同一轮主导长链路推进。
|
||
8. 若 `get_task_status` 返回 `needs_human` 或 `failed`,按返回结果停下并引导用户下一步。
|
||
9. 存在 shortage 时,不能默认继续发货。
|
||
10. 上传是否成功只能以后端 `get_task_status` 或上传回调结果为准。
|
||
11. 多文件场景下,库存快照按批次共享;字段映射确认一次后,本批各 task 可由后端 worker 分别推进匹配、生成与上传。
|
||
12. 解析修订:自然语言改 PO/料号/数量/增删行 → `update_notice_*`;禁止只在回复里口头改写。
|
||
13. 禁止 Agent 调用 `create_batch` / `create_task`。
|
||
14. 通知文件原始上传由 **当前对话** 完成;订单需求首轮解析由 Dify LLM 节点产出 structured,再由 `parse_notice(structured=...)` 落库。
|
||
15. 禁止自行推断 `map_json`。
|
||
16. 若 `human_options` 出现 `upload_inventory_file / paste_inventory_json / retry_upload / generate_excel / download_excel / mark_manual_uploaded / refresh` 等前端动作,只负责解释并引导,不得把它们当作 Tool 调用。
|
||
17. 若 Tool 返回 `action_buttons` / `human_options`,最终回复正文**禁止**生成任何操作菜单、编号选项、按钮清单或“推荐下一步”动作列表。不要输出类似“推荐下一步:”“请选择以下操作:”“请选择操作:”“1. 重新上传库存”“2. 更正映射”“3. 重新匹配”“4. 驳回”。正文只说明当前状态、业务原因和影响;如需要用户操作,只写“请使用下方按钮继续”。可点击按钮由宿主系统根据 `action_buttons` 渲染。
|
||
18. 禁止依赖 `hxops_context`;画布中所有上下文读取必须使用 `agent_runtime_context` 与 `parse_agent_runtime_context`。
|
||
#### 查询模板
|
||
HXOPS 运行态上下文:
|
||
{{agent_runtime_context}}
|
||
|
||
当前 task_id:
|
||
{{#Agent 状态输入标准化.agent_task_id#}}
|
||
用户消息:
|
||
{{#用户意图预处理.normalized_query#}}
|
||
上一轮后端状态 JSON:
|
||
{{#Agent 状态输入标准化.agent_raw_json#}}
|
||
```
|
||
|
||
说明:
|
||
|
||
- 本节是 Agent 节点的唯一维护入口;后续若更新 Agent 行为,直接改这里,不在别处重复维护指令副本。
|
||
- 如需调整 Agent 能力边界,应同时同步 `货代续办 Agent` 节点的 Tool 白名单与本指令内容。
|
||
|
||
##### 节点:直接回复
|
||
|
||
类型:`Answer`
|
||
|
||
内容:
|
||
|
||
```text
|
||
{{#货代续办 Agent.text#}}
|
||
```
|
||
|
||
说明:
|
||
|
||
- 本节点只原样输出 Agent 文本。
|
||
- 若回复内容不符合预期,应优先回查 Agent 指令、Query 模板或可用 Tool 边界,而不是修改本节点。
|
||
|
||
#### 2.4.8 节点连线清单
|
||
|
||
按下面顺序连线:
|
||
|
||
```text
|
||
开始 -> Tool 解析运行态上下文
|
||
Tool 解析运行态上下文 -> 运行态上下文标准化
|
||
运行态上下文标准化 -> 用户意图预处理
|
||
用户意图预处理 -> 附件意图分类
|
||
附件意图分类 -> 分支调度
|
||
分支调度 -> 主路由分支节点
|
||
|
||
主路由分支节点(inventory_path) -> 库存任务检查
|
||
库存任务检查 -> 是否已有库存绑定任务
|
||
是否已有库存绑定任务(false) -> 无TASK_ID提示
|
||
是否已有库存绑定任务(true) -> Tool 读取库存 schema 预览
|
||
Tool 读取库存 schema 预览 -> 库存 schema 标准化
|
||
库存 schema 标准化 -> 库存列映射 LLM
|
||
库存列映射 LLM -> 列映射 JSON 标准化
|
||
列映射 JSON 标准化 -> 库存列映射是否成功
|
||
库存列映射是否成功(false) -> 列映射失败回复
|
||
库存列映射是否成功(true) -> Tool 应用库存列映射
|
||
Tool 应用库存列映射 -> 映射结果标准化
|
||
映射结果标准化 -> Agent 状态输入标准化
|
||
|
||
主路由分支节点(direct_answer) -> 直接回复(引导)
|
||
|
||
主路由分支节点(agent_path) -> 准备读取任务状态
|
||
准备读取任务状态 -> Tool 读取任务状态
|
||
Tool 读取任务状态 -> 工具结果标准化
|
||
工具结果标准化 -> 当前任务动作判断
|
||
当前任务动作判断 -> 是否进入 Agent
|
||
|
||
是否进入 Agent(false) -> 当前任务直连动作分支
|
||
当前任务直连动作分支(retry_rpa) -> Tool 重试库存导出
|
||
当前任务直连动作分支(confirm) -> Tool 提交当前任务决策
|
||
当前任务直连动作分支(reject) -> Tool 提交当前任务决策
|
||
当前任务直连动作分支(reparse) -> Tool 提交当前任务决策
|
||
当前任务直连动作分支(confirm_inventory_mapping) -> Tool 提交当前任务决策
|
||
当前任务直连动作分支(correct_inventory_mapping) -> Tool 提交当前任务决策
|
||
当前任务直连动作分支(reparse_inventory) -> Tool 提交当前任务决策
|
||
当前任务直连动作分支(rematch) -> Tool 重新匹配库存
|
||
Tool 重试库存导出 -> 直连动作结果标准化
|
||
Tool 提交当前任务决策 -> 直连动作结果标准化
|
||
Tool 重新匹配库存 -> 直连动作结果标准化
|
||
直连动作结果标准化 -> 直接回复(动作结果)
|
||
|
||
是否进入 Agent(true) -> 是否待解析通知
|
||
是否待解析通知(false) -> Agent 状态输入标准化
|
||
是否待解析通知(true) -> 提取通知原文
|
||
提取通知原文 -> 订单需求解析 LLM
|
||
订单需求解析 LLM -> 结构化结果标准化
|
||
结构化结果标准化(parse_ok=false) -> 直接回复(引导)
|
||
结构化结果标准化(parse_ok=true) -> Tool 解析发货通知
|
||
Tool 解析发货通知 -> 解析结果标准化
|
||
解析结果标准化 -> Agent 状态输入标准化
|
||
|
||
Agent 状态输入标准化 -> 货代续办 Agent
|
||
货代续办 Agent -> 直接回复
|
||
```
|
||
#### 2.4.9 验收清单
|
||
|
||
##### 应用级
|
||
|
||
- [ ] 应用模式为 `advanced-chat`
|
||
- [ ] Opening Statement 已填
|
||
- [ ] Suggested Questions 已填
|
||
- [ ] 文件上传已启用
|
||
|
||
##### Tool 级
|
||
|
||
- [ ] 已导入 `HXOPS Agent Runtime Context Tools` OpenAPI
|
||
- [ ] 已导入 `Hxops Shipping Notice` OpenAPI
|
||
- [ ] `parse_agent_runtime_context` 可在 Agent 节点中调用
|
||
- [ ] Server URL 指向 Hxops `shipping-notice` API
|
||
- [ ] 鉴权头配置正确
|
||
|
||
##### 节点级
|
||
|
||
- [ ] Start 节点只配置 `agent_runtime_context`,未配置 `hxops_context`
|
||
- [ ] `Tool 解析运行态上下文` 已绑定 `parse_agent_runtime_context`
|
||
- [ ] `运行态上下文标准化` 代码正确
|
||
- [ ] `用户意图预处理` 代码正确
|
||
- [ ] `附件意图分类` 代码正确
|
||
- [ ] `分支调度` 代码正确
|
||
- [ ] `准备读取任务状态` 代码正确
|
||
- [ ] `工具结果标准化` 代码正确
|
||
- [ ] `当前任务动作判断` 代码正确
|
||
- [ ] `提取通知原文` 代码正确
|
||
- [ ] `订单需求解析 LLM` Prompt 正确
|
||
- [ ] `结构化结果标准化` 代码正确
|
||
- [ ] `Tool 解析发货通知` 已绑定 `parse_notice`
|
||
- [ ] `解析结果标准化` 代码正确
|
||
- [ ] `直连动作结果标准化` 代码正确
|
||
- [ ] `Agent 状态输入标准化` 代码正确
|
||
- [ ] `库存任务检查` 代码正确
|
||
- [ ] `库存 schema 标准化` 代码正确
|
||
- [ ] `库存列映射 LLM` Prompt 正确
|
||
- [ ] `列映射 JSON 标准化` 代码正确
|
||
- [ ] `映射结果标准化` 代码正确
|
||
- [ ] `是否进入 Agent` 与 `当前任务直连动作分支` 条件正确
|
||
- [ ] `Tool 提交当前任务决策` 已绑定 `decision={{direct_action}}`
|
||
- [ ] 直连动作分支仅绑定当前允许保留的确认/决策类 Tool
|
||
- [ ] Agent 已绑定必开 Tool(含 `parse_agent_runtime_context`)
|
||
- [ ] Agent 未绑定 `parse_notice / apply_inventory_mapping`
|
||
- [ ] Agent 未误绑定 `upload_inventory_file / paste_inventory_json / retry_upload / generate_excel / download_excel / mark_manual_uploaded / refresh`
|
||
|
||
##### 运行验收矩阵
|
||
|
||
> 运行级验收不再只看 checklist 勾选,必须记录“用户话术命中哪个入口、是否绕过 Agent、任务锚点、状态变化和实测结果”。P0 优先锁死 5 条关键链路,避免 Dify 编排或提示词漂移破坏业务契约。
|
||
|
||
| 关键链路 | 触发语句 | 命中入口 | 是否绕过 Agent | 任务锚点 | 预期状态变化 | 实测结果 |
|
||
| --- | --- | --- | --- | --- | --- | --- |
|
||
| 继续处理 | `继续处理` | `get_task_status` | 是,直连 Tool 读状态 | `agent_runtime_context.refs.task_no` 或 `reference_context.focus_object.id` | 不改写任务;返回当前阶段、检查点、可用动作 | 待实测 |
|
||
| SN-... 读状态 | `SN-20260617-ABCDEFGH` | `get_task_status` | 是,直连 Tool 读状态 | 文本中提取到的 `SN-...` | 不改写任务;返回该任务状态,不切换其他任务 | 通过:`PYTHONPATH=. pytest tests/test_shipping_notice_tools.py tests/test_shipping_notice_batches.py -q`;`test_contract_get_task_status_accepts_task_no_anchor` |
|
||
| 确认 / 驳回 / 重匹配直连 | `确认` / `驳回` / `重新匹配` / `rematch` | `submit_decision` | 是,直连决策 Tool | 当前任务或显式 `SN-...` | 按状态机推进;`rematch` 清理 shortage 并重新入队当前任务 | 通过:`PYTHONPATH=. pytest tests/test_shipping_notice_tools.py tests/test_shipping_notice_batches.py -q`;`test_contract_submit_decision_rematch_is_direct_recovery_entry` |
|
||
| shortage 阻断 | shortage review 后输入 `继续` 或自动续跑 | `match_inventory` / `submit_decision` 返回门禁 | 是,命中状态机门禁后停止 | 当前任务 | `status=needs_human`;禁止 `generate_shipment_excel` / `upload_to_freight`;不生成 Excel | 通过:`PYTHONPATH=. pytest tests/test_shipping_notice_tools.py tests/test_shipping_notice_batches.py -q`;`test_shipping_notice_match_shortage_needs_human` |
|
||
| 多任务只推进 focus task | 多票批次中输入 `继续处理` | `get_batch_status` + 当前 focus 的 `get_task_status` | 是,先读状态再决定 | `batch.current_focus_task_no` | 每轮只围绕一个 focus task;读批次状态不循环推进整批 | 通过:`PYTHONPATH=. pytest tests/test_shipping_notice_tools.py tests/test_shipping_notice_batches.py -q`;`test_contract_batch_status_keeps_single_focus_without_advancing_other_tasks` |
|
||
| 库存上传链路 | 上传 `.xlsx/.xls/.csv` | `get_inventory_schema_preview` → 映射 LLM → `apply_inventory_mapping` | 否,进入库存专用分支,不走自由 Agent | 当前任务 / 所属批次库存快照 | 生成 schema preview;应用映射后进入 `align_review` 或后端续跑 | 待实测 |
|
||
| 字段对齐人工门 | `apply_inventory_mapping` 返回 `align_review` 后输入 `确认` | `submit_decision(decision=confirm_inventory_mapping)` | 是,直连决策 Tool | 当前任务 | 停住等待确认;确认后交由 hxops worker 续跑匹配 / 导出 / 上传 | 待实测 |
|
||
| Tool 人工门收口 | 任一 Tool 返回 `needs_human` 或 `stop_agent_turn=true` | 工具结果标准化 | 是,硬停止本轮 | 当前任务 | 本轮不再继续调用后续 Tool | 待实测 |
|
||
| forbidden_next_tools 门禁 | Tool 返回 `forbidden_next_tools` | 工具结果标准化 | 是,硬门禁 | 当前任务 | 画布不调用被禁止 Tool | 待实测 |
|
||
| need_agent 布尔分流 | 直连动作判断节点输出 | `是否进入 Agent` | 视分支结果 | 当前任务 | `need_agent` 必须为布尔值,节点按布尔条件分流 | 待实测 |
|
||
|
||
##### 验收话术
|
||
|
||
1. `继续处理`
|
||
- 预期:若 `agent_runtime_context.refs.task_no` 或 `reference_context.focus_object.id` 已提供任务锚点,进入 `Tool 读取任务状态`
|
||
2. `SN-20260617-ABCDEFGH`
|
||
- 预期:按该任务号读取状态
|
||
3. 对一个尚未解析的通知任务发送 `继续处理`
|
||
- 预期:进入 `提取通知原文 -> 订单需求解析 LLM -> Tool 解析发货通知`
|
||
4. 上传一个库存 `.xlsx`
|
||
- 预期:进入 `get_inventory_schema_preview -> 库存列映射 LLM -> apply_inventory_mapping`
|
||
5. 在字段对齐确认状态下输入 `确认`
|
||
- 预期:不进入 Agent,直接走 `Tool 提交当前任务决策(decision=confirm_inventory_mapping)`
|
||
6. 在库存待匹配状态下输入 `开始匹配`
|
||
- 预期:Agent 先解释当前状态,并按当前后端契约提交对应决策或提示等待 worker 续跑
|
||
7. 在 shortage_review 状态下输入 `重新匹配`
|
||
- 预期:不进入 Agent,直接走 `Tool 重新匹配库存 -> submit_decision(decision=rematch)`
|
||
8. 在可上传货代状态下输入 `继续`
|
||
- 预期:Agent 根据后端状态解释当前进度或提示等待 worker / 上传执行器处理
|
||
|
||
### 2.5 目标状态机口径
|
||
|
||
目标模型采用 **Batch + Task**,但实现继续放在 Flask + SQLAlchemy 中。
|
||
|
||
#### Batch
|
||
|
||
建议字段:
|
||
|
||
| 字段 | 说明 |
|
||
| ----------------------- | ---------- |
|
||
| `batch_no` | 批次号 |
|
||
| `conversation_id` | Dify 会话 ID |
|
||
| `current_focus_task_no` | 当前聚焦任务号 |
|
||
| `file_count` | 本批文件数 |
|
||
| `process_summary` | 批次摘要 |
|
||
|
||
#### Task
|
||
|
||
建议字段:
|
||
|
||
| 字段 | 说明 |
|
||
| ---------------------- | -------------- |
|
||
| `task_no` | 任务号,如 `SN-...` |
|
||
| `batch_no` | 所属批次号 |
|
||
| `source_file_name` | 原始文件名 |
|
||
| `batch_index` | 当前任务在批次中的顺序 |
|
||
| `batch_total` | 当前批次总任务数 |
|
||
| `current_step` | 当前步骤 |
|
||
| `process_status` | 总流程状态 |
|
||
| `review_status` | 人工确认状态 |
|
||
| `pending_human_reason` | 当前等待人工原因 |
|
||
| `match_status` | 匹配结果状态 |
|
||
| `lines_json` | 发货通知行项目 |
|
||
| `inventory_lines_json` | 任务级库存投影缓存;批次库存真相源为 `shipping_inventory_files.inventory_lines_json` |
|
||
| `export_file_path` | 生成的 Excel 文件路径 |
|
||
| `freight_ref_no` | 货代上传回执号 |
|
||
| `upload_status` | 上传子状态 |
|
||
| `upload_mode` | 上传模式 |
|
||
| `upload_attempt` | 上传重试次数 |
|
||
| `idempotency_key` | 上传幂等键 |
|
||
|
||
常见 `process_status` / 子状态:
|
||
|
||
- `created`
|
||
- `parsed`
|
||
- `waiting_inventory`
|
||
- `inventory_ready`
|
||
- `matched`
|
||
- `excel_ready`
|
||
- `upload_running`
|
||
- `upload_failed`
|
||
- `uploaded`
|
||
- `completed`
|
||
- `rejected`
|
||
|
||
典型人工节点由 `checkpoint` 表示(以当前 `constants.py` / `state_machine.py` 为准),常见值包括:
|
||
|
||
- `parse_review`
|
||
- `upload_req` / `inventory_pending`
|
||
- `map_infer`
|
||
- `align_review`
|
||
- `ready_to_match`
|
||
- `ready_to_export` / `export_ready`
|
||
- `waiting_upload`
|
||
- `upload_failed`
|
||
|
||
shortage 规则:
|
||
|
||
- shortage 存在时,系统绝不自动放行存在缺口的单据
|
||
- 自动推进遇到 shortage 必须停在人工节点
|
||
- 自动上传失败后,仅允许:重试自动上传 / 改为手工上传 / 确认已手工上传完成
|
||
|
||
### 2.6 自动推进与 RPA
|
||
|
||
目标方案中以下能力继续保留,且由 Flask 后端配置控制:
|
||
|
||
- `SHIPPING_NOTICE_AUTO_PROGRESS_ENABLED`
|
||
- `SHIPPING_NOTICE_AUTO_RPA_INVENTORY_ENABLED`
|
||
- `SHIPPING_NOTICE_AUTO_MATCH_ENABLED`
|
||
- `SHIPPING_NOTICE_AUTO_GENERATE_EXCEL_ENABLED`
|
||
- `SHIPPING_NOTICE_AUTO_UPLOAD_ENABLED`
|
||
|
||
说明:
|
||
|
||
- `auto_progress` 是后端 worker 串联入口,会在满足条件时继续执行库存获取、字段确认后续步骤、匹配、生成 Excel、上传
|
||
- 遇到人工节点时,仍会返回 `needs_human`
|
||
- 库存 RPA 与上传 RPA 的回调均通过 Flask `/rpa/*` 路由回写
|
||
- 当前 `scripts/rpa/freight_rpa_worker.py` 的真实货代上传 Driver 尚未完成;生产环境应保持 `SHIPPING_NOTICE_AUTO_UPLOAD_ENABLED=false`,由用户下载 Excel 后手工上传并在系统中确认,除非已接入并验收正式上传 RPA。
|
||
|
||
### 2.7 步骤内层细粒度进度(当前实现)
|
||
|
||
当前实现已开始把“步骤内层”进度统一落到 `ShippingTask.step_payload_json.current_step_progress`,并通过任务查询接口返回给聊天页与工作台。
|
||
|
||
字段结构:
|
||
|
||
```json
|
||
{
|
||
"current_step_progress": {
|
||
"step_key": "step3_inventory_prepare",
|
||
"step_title": "获取库存",
|
||
"status": "running",
|
||
"message": "已触发 RPA 库存导出,等待结果",
|
||
"progress_percent": 60,
|
||
"current": 1,
|
||
"total": 3,
|
||
"detail": "第 1/3 次尝试",
|
||
"extra": {}
|
||
}
|
||
}
|
||
```
|
||
|
||
当前已接入的关键阶段:
|
||
|
||
- `step1_notice_submit` / `step2_parse_confirm`:发货通知解析中、解析完成
|
||
- `step3_inventory_prepare`:库存文件上传、RPA 库存导出等待、库存快照读取完成
|
||
- `step4_align_confirm`:字段对齐待确认
|
||
- `step5_match_inventory`:库存匹配中、匹配完成、缺口待人工处理
|
||
- `step6_generate_file`:发货 Excel 生成中、生成完成
|
||
- `step7_upload_freight`:RPA 上传中、手工上传确认完成、上传失败待人工处理
|
||
|
||
当前展示范围:
|
||
|
||
- 聊天页顶部任务 Stepper 下方
|
||
- 工作台任务详情页 Stepper 下方
|
||
- 聊天页批次摘要区可展示当前处理票次、待处理票数与完成汇总
|
||
|
||
当前限制:
|
||
|
||
- 解析阶段暂未做到“第 `i/n` 个文件解析中”的批次级实时进度,仅支持单任务级步骤内状态
|
||
- 匹配阶段已在后端匹配循环内写入 `current/total`,最终可展示 `x/y` 行匹配结果;但前端当前仍主要在请求完成后看到该结果,尚未做到真正流式逐行刷新
|
||
- 上传阶段百分比目前是业务估算值,不是货代系统真实回执百分比
|
||
- Dify / Tool 侧仍以任务状态和 message 为主;步骤内层进度主要服务 Hxops 前端展示
|
||
|
||
批次层当前补充协议:
|
||
|
||
- `process_summary.pending`:待处理票数
|
||
- `process_summary.current_index`:当前建议聚焦处理的票次序号
|
||
- `process_summary.current_task_no`:当前建议聚焦处理的任务号
|
||
|
||
说明:
|
||
|
||
- 以上字段基于当前批次任务状态推导,用于让聊天页更接近原型中的“第 `i/n` 票”体验
|
||
- 当前仍不是严格意义上的后台异步批处理实时队列,只是批次运行态摘要增强
|
||
|
||
***
|
||
|
||
## 3. 当前与原型对齐状态
|
||
|
||
> 对齐基线:[`docs/prototype/shipping_notice_agent_prototype.md`](../../prototype/shipping_notice_agent_prototype.md)\
|
||
> 评估日期:**2026-06-18**
|
||
|
||
### 3.1 已实现或基本落地
|
||
|
||
- **多文件建批次、多任务切换**:后端已支持 `batch + task`,前端聊天态也支持 focus task 切换。
|
||
- **聊天主路径骨架**:聊天页已展示当前批次 / 当前任务 / 七步 Stepper,并提供与对话协同的轻量批次监督入口。
|
||
- **发货通知人工修订**:已支持改单头、改订单行、增行、删行。
|
||
- **库存匹配与缺口阻断主规则**:存在 shortage 时会停留在人工节点,前端 Stepper 也会展示阻断状态。
|
||
- **Excel 生成与上传闭环**:已具备后端匹配、自动推进、生成 Excel、人工上传确认等主流程接口。
|
||
|
||
### 3.2 部分实现,和原型仍有差距
|
||
|
||
- **三层进度展示**:当前已具备批次层摘要、任务层七步 Stepper,以及统一的 `step_payload_json.current_step_progress` 步骤内进度协议;但“第 `i/n` 个文件解析中”“匹配严格逐行 `x/y`”这类更细运行态仍未完全达到原型描述粒度。
|
||
- **工作台职责收敛**:正式口径应收敛为“**对话主路径 + 轻量批次工作台**”;聊天页右侧轻量工作台允许执行动作,但只负责渲染后端 `ui_state.action_buttons` 与查看类辅助入口,不能本地二次推导“继续处理 / 重试 RPA / 查看详情”等业务按钮;独立详情页仍主要承担只读排查与管理视角。
|
||
- **任务列表筛选口径**:工作台已支持按部分 `process_status` 过滤,但尚未完全覆盖原型验收视角下的全部用户态状态。
|
||
- **解析复核状态命名**:前端个别展示逻辑仍存在旧状态名 / 特殊判断,和当前状态机中的 `parse_review`、`rsv_required` 等口径有进一步统一空间。
|
||
|
||
### 3.3 尚不能判定为已完全落地的项
|
||
|
||
- **四语言验收**:原型要求 `zh-CN / zh-TW / en-US / th-TH` 全量覆盖;本次对齐主要核了流程与接口,尚未逐条完成文案完整性复核。
|
||
- **库存自动抓取业务闭环**:代码层已具备后端库存准备、RPA 回调与自动推进入口,但是否达到真实业务可用,还依赖货代库存导出 SOP、正式 RPA 脚本和运行环境联调。
|
||
- **正式方案 P0 验收项**:从代码结构看已接近“对话主路径 + 轻量批次工作台”的目标要求,但像“不中断续办”“多票并行下的细粒度进度提示”“轻量工作台与对话聚焦任务的一致性”等,仍需要按原型测试用例逐项实测,而不能仅凭仓库代码直接视为全部完成。
|
||
|
||
***
|
||
|
||
## 4. OpenAPI 变更说明
|
||
|
||
### 3.1 目标 OpenAPI 范围
|
||
|
||
目标版公开给 Dify 的 OpenAPI 仅包含 Agent 编排所需接口,不包含 RPA 回调接口;这些接口仍由 **Flask Blueprint** 暴露。
|
||
|
||
主要请求特点:
|
||
|
||
- 所有 Tool 接口均为 `POST`
|
||
- 需要同时支持 `batch_id/batch_no` 与 `task_id/task_no`
|
||
- `submit_decision`、`get_task_status` 允许用 `conversation_id` 辅助定位任务
|
||
- 统一返回 `status/message/data`,可能附带 `checkpoint`、`human_options`、`action_buttons`
|
||
|
||
当前 Dify 目标导出接口:
|
||
|
||
- `parse_notice`
|
||
- `update_notice_fields`
|
||
- `update_notice_line`
|
||
- `add_notice_line`
|
||
- `remove_notice_line`
|
||
- `get_inventory_schema_preview`
|
||
- `apply_inventory_mapping`
|
||
- `submit_decision`
|
||
- `get_task_status`
|
||
- `get_batch_status`
|
||
|
||
说明:
|
||
|
||
- RPA 回调、主推进工具、批量文件上传接口也不在 Dify 导出范围内
|
||
|
||
### 3.2 大库存 Excel 特殊处理
|
||
|
||
`upload_inventory_file` 为 multipart 接口,适合:
|
||
|
||
- 聊天前端直接上传
|
||
- Dify HTTP 节点上传
|
||
|
||
不适合:
|
||
|
||
- 作为 Agent OpenAPI tool 让 LLM 直接携带 Excel 内容
|
||
|
||
目标推荐链路:
|
||
|
||
1. 上传库存文件
|
||
2. `get_inventory_schema_preview`
|
||
3. LLM 推断字段映射
|
||
4. `apply_inventory_mapping`
|
||
5. 用户确认字段映射
|
||
6. hxops worker 统一续跑匹配
|
||
|
||
### 3.3 后端模块分层(已落地)
|
||
|
||
写路径按阶段拆分,读路径统一投影,避免 Tool 与工作台结果漂移:
|
||
|
||
```text
|
||
API 层
|
||
├── shipping_notice_tools.py → Dify Tool + RPA 回调(薄路由)
|
||
└── workspace_shipping_notice.py → 工作台批次/任务(JWT 鉴权)
|
||
|
||
门面
|
||
└── tools.py → re-export 公开符号,无编排实现
|
||
|
||
写路径 / 阶段编排
|
||
├── task_workflow.py → 任务/批次、解析、决策、auto_progress
|
||
├── inventory_workflow.py → 库存解析、上传、字段映射
|
||
├── inventory_rpa_workflow.py → RPA 库存导出触发/超时/回调
|
||
├── fulfillment_workflow.py → 匹配、Excel 生成、货代上传
|
||
└── tool_common.py → 配置开关、payload 合并、事件日志
|
||
|
||
读路径 / 投影
|
||
└── query_service.py → TaskProjection / BatchProjection 序列化
|
||
```
|
||
|
||
**调用约定**
|
||
|
||
- API 写操作只 import `tools.*`;读操作优先 import `query_service.*`
|
||
- `query_service` 提供 `TOOL` / `SUMMARY` / `DETAIL` 投影;Tool `data` 经 `user_facing_status.strip_internal_task_fields` 剔除 `process_status` 等内部码
|
||
- checkpoint 使用 `constants.py` 短名(如 `align_review`、`upload_req`、`map_infer`),与 `state_machine.CHECKPOINT_REGISTRY` 对齐
|
||
|
||
**批次能力(Tool API 已补齐)**
|
||
|
||
- `create_batch` / `create_batch_tasks`
|
||
- `get_batch_status`
|
||
|
||
***
|
||
|
||
### 3.4 联调验收重点
|
||
|
||
- 多文件上传创建 1 个 batch、多个 task
|
||
- 当前聚焦 task 切换后,确认/上传仍作用于该 task;库存文件上传和列映射作用于该 task 所属批次库存快照
|
||
- 全流程可在无侧边栏前提下于对话内闭环
|
||
- 自动上传成功、失败、人工接管三条路径可验证
|
||
- Dify 在 `needs_human` 与 `forbidden_next_tools` 返回时会正确停下
|
||
|
||
***
|
||
|
||
## 5. 相关代码与文件
|
||
|
||
### 4.1 后端
|
||
|
||
| 文件 | 说明 |
|
||
| ---------------------------------------------------------------- | ------------------------------------------------------ |
|
||
| `backend/app/models.py` | `ShippingBatch`、`ShippingTask`、`ShippingTaskEvent` 模型 |
|
||
| `backend/app/api/shipping_notice_tools.py` | Flask Tool API 与 RPA 回调路由(写→`tools`、读→`query_service`) |
|
||
| `backend/app/api/workspace_shipping_notice.py` | 工作台批次/任务接口 |
|
||
| `backend/app/services/shipping_notice/tools.py` | Agent Tool 统一门面(re-export,无编排) |
|
||
| `backend/app/services/shipping_notice/task_workflow.py` | 任务/批次生命周期、解析、决策、auto\_progress |
|
||
| `backend/app/services/shipping_notice/inventory_workflow.py` | 库存解析、上传、字段映射 |
|
||
| `backend/app/services/shipping_notice/inventory_rpa_workflow.py` | RPA 库存导出触发、等待/超时、回调落盘 |
|
||
| `backend/app/services/shipping_notice/fulfillment_workflow.py` | 匹配、Excel 生成、货代上传 |
|
||
| `backend/app/services/shipping_notice/tool_common.py` | 配置开关、payload 合并、事件日志 |
|
||
| `backend/app/services/shipping_notice/query_service.py` | 批次/任务查询、排序、多投影序列化 |
|
||
| `backend/app/services/shipping_notice/state_machine.py` | checkpoint / action\_buttons / 人工节点规则 |
|
||
| `backend/app/services/shipping_notice/user_facing_status.py` | Tool 投影字段裁剪、用户可见阶段文案 |
|
||
| `backend/app/services/shipping_notice/openapi_spec.py` | Dify 使用的 OpenAPI 生成 |
|
||
| `backend/app/services/shipping_notice/inventory_upload.py` | 库存文件上传与读取 |
|
||
| `backend/app/services/shipping_notice/export.py` | 发货 Excel 生成 |
|
||
| `backend/app/services/shipping_notice/rpa.py` | RPA 触发文件写入(低层 I/O) |
|
||
|
||
### 4.2 前端与脚本
|
||
|
||
- `frontend/src/features/chat/shipping/*` — 聊天主路径与轻量批次工作台 UI 逻辑
|
||
- `backend/seed_shipping_notice_agents.py` — Agent 注册
|
||
- `backend/scripts/export_shipping_notice_openapi.py` — OpenAPI 导出
|
||
- `docs/features/shipping-notice/technical.md` — 手动配置主文档
|
||
|
||
| 文件 | 说明 |
|
||
| -------------------------------------------------------------- | -------------------------------------------------------- |
|
||
| `frontend/src/features/workspace/views/ShippingNoticeView.vue` | 工作台批次/任务入口 |
|
||
| `frontend/src/features/chat/composables/useChatShipping.ts` | 聊天态任务续办与切换 |
|
||
| `frontend/src/features/chat/api/shipping.api.ts` | chat/workspace shipping API |
|
||
| `backend/tests/test_shipping_notice_tools.py` | Tool 主流程测试(默认关闭 auto 链;`@pytest.mark.auto_rpa` 测 RPA 分支) |
|
||
| `backend/tests/test_shipping_notice_query_service.py` | 读模型投影与批次汇总单测 |
|
||
| `backend/tests/test_shipping_notice_batches.py` | 批次建单 / focus 切换测试 |
|
||
| `backend/tests/test_shipping_notice_inventory_rpa_workflow.py` | RPA 库存触发与回调单测 |
|
||
| `backend/tests/test_shipping_notice_inventory_sources_config.py` | 库存源 JSON 配置加载与校验单测 |
|
||
| `backend/tests/test_shipping_notice_inventory_snapshot_reuse.py` | 库存快照 TTL 复用与 link 审计单测 |
|
||
| `backend/tests/test_shipping_notice_inventory_schedule.py` | 定时批量库存 RPA 排程 executor 单测 |
|
||
| `backend/tests/test_shipping_notice_match_summary.py` | 匹配摘要相关测试 |
|
||
| `scripts/rpa/freight_rpa_worker.py` | 开发态 RPA worker(支持单条/批量 inventory_export) |
|
||
| `backend/config/shipping_inventory_sources.json` | 库存 RPA 源配置(新增 Warehouse 只改此 JSON) |
|
||
| `seed_shipping_notice_agents.py` | Agent 注册脚本 |
|
||
|
||
---
|
||
|
||
## 5. 库存 RPA 独立化与快照复用(2026-07)
|
||
|
||
### 5.1 配置文件
|
||
|
||
- 路径:`backend/config/shipping_inventory_sources.json`(环境变量 `SHIPPING_NOTICE_INVENTORY_SOURCES_CONFIG`)
|
||
- **新增 Warehouse 只改 JSON**,不改 Python;字段含 `source_code`、`site`(`dsv360` / `crane_footprint`)、`warehouse_id`、`navigation`、`parameters`、`match_aliases`
|
||
- 环境变量:
|
||
- `SHIPPING_NOTICE_INVENTORY_SNAPSHOT_TTL_HOURS`(默认 24)
|
||
- `SHIPPING_NOTICE_INVENTORY_RPA_BATCH_ENABLED`(默认 true)
|
||
|
||
### 5.2 快照复用规则
|
||
|
||
1. `ensure_inventory(mode=auto)` 在解析库存源后,优先 `find_latest_ready_snapshot(source_code, warehouse_id)`
|
||
2. 未过期快照 → `link_snapshot_to_task(reason=reuse_latest)` → 映射/匹配
|
||
3. 过期或缺失 → 触发 RPA(单 task trigger 或定时 batch trigger)
|
||
4. `retry_rpa` **强制跳过**快照缓存
|
||
5. 人工上传仍可覆盖;终态任务不可 relink
|
||
|
||
### 5.3 批量 RPA(一次登录多 Warehouse)
|
||
|
||
- Trigger action:`inventory_export_batch`;按 `source_type` 分组,DSV/Crane 各登录一次
|
||
- **每个 source 导出前**:DSV 调用 `_reset_dsv_export_entry`(goto entry + session 检测,不重复登录);Crane 调用 `_reset_crane_export_entry`
|
||
- **按需单票**:`write_inventory_export_trigger_for_task`;batch 开启时包装为单源 batch trigger(与定时共用 worker 路径)
|
||
- **单票 legacy 路径**:`_download_dsv360_inventory` / `_download_crane_inventory` 已委托 `_export_*_inventory_source`,与批量共用 `parameters` 填充
|
||
- **multi_select**:worker `_fill_dsv_multi_select` 支持多选控件(非仅取第一个值)
|
||
- Worker:`scripts/rpa/freight_rpa_worker.py` → `_handle_inventory_batch_trigger`
|
||
- 回调:`POST /api/shipping-notice/rpa/inventory-batch-ready`
|
||
- 定时排程:`schedule_type=platform_job`,`platform_api_path=shipping-inventory-rpa`,`data_source_type=null`;建议 cron `0 3 * * *`(Asia/Shanghai)
|
||
- 排程语义:`data_source_type` 仅用于 `schedule_type=data_pipeline`(`database` | `external_api`);平台任务通过 Job Registry 注册,由 `platform_api_path` 引用 job key
|
||
|
||
### 5.4 审计字段
|
||
|
||
- `shipping_inventory_files`:`warehouse_id`、`source_code`、`exported_at`、`expires_at`、`rpa_run_no`、`schedule_run_id`
|
||
- `shipping_task_inventory_links`:`link_reason`、`matched_warehouse_id`、`snapshot_age_seconds`、`audit_payload_json`
|