feat(shipping-notice): 新增发货通知自动上传功能与候选资格评估

- 在环境配置中新增 SHIPPING_NOTICE_AUTO_UPLOAD_ENABLED 选项,默认关闭,需显式开启以支持自动上传。
- 引入新的 pytest.ini 文件,增加测试标记以支持自动化测试。
- 删除不再使用的 seed_shipping_notice_agents.py 文件,简化代码库。
- 更新相关 API,增强发货通知与候选资格评估功能,支持多种筛选条件。
- 增强文档与代码注释,反映新的业务逻辑与功能要求。
This commit is contained in:
hugo committed 2026-08-02 19:26:35 +08:00
1 parent cef3d5b26a
commit 3a9fbac2fc
226 files changed
+25010 -2098

No files matched your search

@@ -2,8 +2,9 @@
services/shipping_notice/tool_response.py
用途:统一构建发货通知 Tool 的 JSON 响应结构。
依赖:state_machine 中的 checkpoint/human_options/action_buttons 解析能力。
逻辑:由 task_workflow、inventory_workflow、fulfillment_workflow 等 workflow 调用本文件,把状态机信息整理成一致的 Tool 响应。
依赖:state_machine 中的 checkpoint/human_options/action_buttons 解析能力;ShippingProcessExecution。
逻辑:由 task_workflow、inventory_workflow、fulfillment_workflow 等 workflow 调用本文件,把状态机信息整理成一致的 Tool 响应;
已绑定 ProcessExecution 的任务不再下发旧 action_buttons / next_required_action(恢复仅由 Gate 驱动)。
"""
from __future__ import annotations
@@ -14,6 +15,28 @@ if TYPE_CHECKING:
from app.models import ShippingTask
def _task_has_process_execution(task: ShippingTask | None) -> bool:
"""
判断任务是否已绑定 ProcessExecution(Gate 为恢复真相源)。
Args:
task: ShippingTask 或 None。
Returns:
存在任意关联 Execution 时为 True。
"""
if task is None or getattr(task, 'id', None) is None:
return False
from app.models import ShippingProcessExecution
return (
ShippingProcessExecution.query
.filter_by(task_id=int(task.id))
.first()
is not None
)
def _sanitize_user_facing_text(value: str) -> str:
"""
清理会被 Agent 复述给业务用户的内部项目名。
@@ -64,6 +87,7 @@ def tool_response(
核心逻辑:未显式传 checkpoint 时从 task DB 状态推导 checkpoint/human_options/action_buttons;
显式 checkpoint 优先(如 parse_ok、task_exists)。
若任务已有 ProcessExecution:不再填充 action_buttons / next_required_action,避免与 Gate 双真相。
Args:
stop_agent_turn: True 时要求 Agent 本回合停止,等待用户操作。
@@ -79,6 +103,7 @@ def tool_response(
if task is not None and not task_id:
task_id = task.task_no
gate_owns_recovery = _task_has_process_execution(task)
resolved_checkpoint = checkpoint
resolved_human_options = human_options
resolved_action_buttons = action_buttons
@@ -88,7 +113,8 @@ def tool_response(
resolved_checkpoint = ui.checkpoint
if human_options is None:
resolved_human_options = ui.human_options
if action_buttons is None and ui.action_buttons:
# [STEP] Gate 绑定任务:忽略状态机推导的旧动作按钮。
if not gate_owns_recovery and action_buttons is None and ui.action_buttons:
resolved_action_buttons = ui.action_buttons
payload: dict[str, Any] = {
@@ -100,7 +126,11 @@ def tool_response(
payload["task_id"] = task_id
if resolved_human_options is not None:
payload["human_options"] = resolved_human_options
if resolved_action_buttons is not None:
# [STEP] ProcessExecution 存在时业务调用清零旧动作字段(含调用方显式传入)。
if gate_owns_recovery:
payload["action_buttons"] = []
elif resolved_action_buttons is not None:
payload["action_buttons"] = resolved_action_buttons
elif resolved_human_options is not None:
payload["action_buttons"] = build_action_buttons(resolved_human_options)
@@ -110,7 +140,7 @@ def tool_response(
payload["action_buttons"] = buttons
if resolved_checkpoint:
payload["checkpoint"] = resolved_checkpoint
if next_required_action:
if next_required_action and not gate_owns_recovery:
payload["next_required_action"] = _sanitize_user_facing_text(next_required_action)
if forbidden_next_tools:
payload["forbidden_next_tools"] = forbidden_next_tools
@@ -118,4 +148,8 @@ def tool_response(
payload["stop_agent_turn"] = True
if extra:
payload.update(extra)
# [STEP] extra 不得绕过 Gate 绑定任务的旧动作清零。
if gate_owns_recovery:
payload["action_buttons"] = []
payload.pop("next_required_action", None)
return payload