refactor(agent-runtime, shipping-notice, frontend): 重构上下文体系,修复重试RPA无响应问题
- 替换原有的hxops_context模块为全新的代理运行时上下文平台协议,统一跨业务上下文注入逻辑 - 新增多语言操作繁忙提示文案(覆盖中、繁、英、泰四语),前端绑定页面繁忙状态实现操作阻断 - 调整RPA库存导出重试策略:移除可配置的最大自动重试次数,改为固定单次自动重试,手动重试需用户显式触发 - 优化任务用户态状态展示逻辑,优先展示具体的pending原因而非通用状态文案 - 重构任务焦点切换逻辑,统一事件日志与处理流程,复用switch_batch_focus工具函数 - 修复clearAllHistory函数残留UI问题,确保清空会话后完全复位发货通知相关视图 - 更新OpenAPI文档与静态快照,补充工具使用约束说明 - 新增调试打点日志与问题排查文档,完善全套单元测试与快照校验用例 - 更新RPA脚本的README文档,调整登录方式说明与浏览器 profile 路径配置 - 删除废弃的hxops_context模块,迁移所有相关调用到新的上下文体系
This commit is contained in:
1 parent
60dd0c0f58
commit
8846ce159f
102 files changed
+18289
-9072
No files matched your search
@@ -2,9 +2,9 @@
|
||||
services/shipping_notice/dify_inputs.py
|
||||
|
||||
用途:识别发货通知 Dify Chatflow Agent,并构建会话级 Dify inputs。
|
||||
依赖:agent_resolver、models.ShippingBatch/ShippingTask、chat.hxops_context。
|
||||
依赖:agent_runtime_context 平台协议、agent_resolver、models.ShippingBatch/ShippingTask、shipping_notice.runtime_context。
|
||||
逻辑:由 api/chat 在调用 DifyService.stream_chat 前引用;本模块按会话号解析当前批次/任务焦点,
|
||||
仅补充货代发货场景可识别的 refs,再委托平台级上下文构造器生成 hxops_context。
|
||||
仅输出 agent_runtime_context JSON 字符串,供 Dify 画布统一读取平台运行态快照。
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
@@ -12,8 +12,10 @@ from __future__ import annotations
|
||||
from typing import Any
|
||||
|
||||
from app.models import ShippingBatch, ShippingTask
|
||||
from app.services.chat.hxops_context import HXOPS_CONTEXT_INPUT, build_hxops_context, build_ref
|
||||
from app.services.agent_runtime_context.builder import serialize_for_dify
|
||||
from app.services.agent_runtime_context.schema import AGENT_RUNTIME_CONTEXT_INPUT
|
||||
from app.services.shipping_notice.agent_resolver import CHAT_AGENT_NAME
|
||||
from app.services.shipping_notice.runtime_context import build_shipping_runtime_context
|
||||
|
||||
|
||||
def is_shipping_notice_chat_agent(agent) -> bool:
|
||||
@@ -45,12 +47,26 @@ def _task_by_task_no(task_id: str) -> ShippingTask | None:
|
||||
return ShippingTask.query.filter_by(task_no=normalized).first()
|
||||
|
||||
|
||||
def _build_hxops_refs(*, task: str, batch: str) -> list[dict[str, str]]:
|
||||
"""构建货代发货 Agent 当前已知业务对象锚点。"""
|
||||
return [
|
||||
build_ref("task", task),
|
||||
build_ref("batch", batch),
|
||||
]
|
||||
def _focus_task_row(focus_task: str, explicit_task_row: ShippingTask | None) -> ShippingTask | None:
|
||||
"""
|
||||
解析当前显式焦点任务行。
|
||||
|
||||
核心逻辑:优先复用已查出的显式 task;若焦点来自 batch.current_focus_task_no,再按 task_no 查询,
|
||||
但不在无焦点时回退到最近任务,避免多票批次串单。
|
||||
|
||||
Args:
|
||||
focus_task: 已解析出的焦点任务号。
|
||||
explicit_task_row: task_id 显式传入时查询到的任务。
|
||||
|
||||
Returns:
|
||||
当前焦点任务;无法明确识别时返回 None。
|
||||
"""
|
||||
normalized = str(focus_task or "").strip().upper()
|
||||
if not normalized:
|
||||
return None
|
||||
if explicit_task_row and str(explicit_task_row.task_no or "").strip().upper() == normalized:
|
||||
return explicit_task_row
|
||||
return ShippingTask.query.filter_by(task_no=normalized).first()
|
||||
|
||||
|
||||
def build_dify_chat_inputs(
|
||||
@@ -66,7 +82,7 @@ def build_dify_chat_inputs(
|
||||
构建发货通知 Dify Chatflow inputs。
|
||||
|
||||
OpenAPI 工具已在 Dify 侧配置 Server URL 与 Authorization / X-Integration-Key,
|
||||
无需再注入 HXOPS_TOOLS_API_BASE;这里只补会话级上下文,供 Dify 画布通过 refs 稳定定位当前 task/batch。
|
||||
无需再注入 HXOPS_TOOLS_API_BASE;这里仅注入 agent_runtime_context,避免新旧上下文字段并存导致画布协议漂移。
|
||||
"""
|
||||
conv_id = str(conversation_id or "").strip()
|
||||
if not conv_id:
|
||||
@@ -93,13 +109,18 @@ def build_dify_chat_inputs(
|
||||
):
|
||||
focus_batch = str(explicit_task_row.batch.batch_no or "").strip().upper()
|
||||
|
||||
hxops_context = build_hxops_context(
|
||||
runtime_context = build_shipping_runtime_context(
|
||||
session_id=conv_id,
|
||||
request_id=request_id,
|
||||
task=_focus_task_row(focus_task, explicit_task_row),
|
||||
batch=batch or getattr(explicit_task_row, "batch", None),
|
||||
trigger_source=trigger_source,
|
||||
request_id=request_id,
|
||||
locale=locale,
|
||||
refs=_build_hxops_refs(task=focus_task, batch=focus_batch),
|
||||
scope="task_run" if trigger_source == "backend_orchestrator" else "chat_turn",
|
||||
run_purpose="parse_notice" if trigger_source == "backend_orchestrator" else "chat_turn",
|
||||
)
|
||||
if not hxops_context:
|
||||
if not runtime_context:
|
||||
return {}
|
||||
return {HXOPS_CONTEXT_INPUT: hxops_context}
|
||||
return {
|
||||
AGENT_RUNTIME_CONTEXT_INPUT: serialize_for_dify(runtime_context),
|
||||
}
|
||||
Reference in new issue
Block a user