F-08-call-orchestration.json 14 KB
{
  "id": "F-08",
  "title": "LLM 调用编排服务",
  "fileKey": "call-orchestration",
  "note": "核心业务编排服务。接收调用请求→匹配模型账号配置→加载提示词模板→组装请求参数→调用 T-03 适配引擎→记录调用日志。支持同步(直接返回)和异步(提交 Celery 任务)两种模式。支持 6 种模板类型:通用文本(templateId=1)、质检(2)、图像输入(3)、带参文本(4)、录音总结(5)、员工复盘(6)。<br><br>复用自 Java 项目:AgiService.launchLLM() / launchTask() / runSyncTask() / runQualityInspectionJob() 完整编排逻辑。",
  "op_count": 6,
  "scenarios": [
    {
      "title": "同步调用:接收请求→匹配配置→调用模型→返回结果(全程阻塞等待)",
      "required": true,
      "precondition": "系统已配置至少 1 个有效的模型账号和策略",
      "expect": "同步返回模型调用结果;call_records 表新增调用记录",
      "tab": "admin",
      "steps": [
        {
          "op": "OP-F-08.1.1",
          "status": "done",
          "tab": "admin",
          "changelog": {"id": "CHG-021", "date": "2026-06-17", "reason": "prompt 渲染后新增敏感词替换步骤"},
          "nav": [
            "管理后台",
            "LLM 调用编排服务",
            "sync"
          ],
          "actions": [
            "登录管理后台",
            "进入「LLM 调用编排服务」模块",
            "执行操作"
          ],
          "backend": [
            {
              "tag": "receive",
              "text": "接收 POST /api/v1/calls/sync 请求"
            },
            {
              "tag": "validate",
              "text": "验证请求参数"
            },
            {
              "tag": "query",
              "text": "从数据库表按条件查询记录"
            },
            {
              "tag": "write",
              "text": "向数据库表插入新记录"
            },
            {
              "tag": "write",
              "text": "向数据库表插入新记录"
            },
            {
              "tag": "receive",
              "text": "Prompt 渲染后调用敏感词替换:查询所有已启用敏感词(enabled=True),对 system_prompt 和 user_prompt 做替换处理"
            },
            {
              "tag": "return",
              "text": "返回操作结果"
            }
          ],
          "expected": [
            "同步返回模型调用结果",
            "call_records 表新增调用记录"
          ]
        }
      ]
    },
    {
      "title": "异步调用:接收请求→创建任务记录→提交 Celery→返回 taskId",
      "required": true,
      "precondition": "系统已配置至少 1 个有效的模型账号和策略",
      "expect": "返回 taskId;async_tasks 表新增任务记录",
      "tab": "admin",
      "steps": [
        {
          "op": "OP-F-08.2.1",
          "status": "done",
          "tab": "admin",
          "changelog": {"id": "CHG-021", "date": "2026-06-17", "reason": "prompt 渲染后新增敏感词替换步骤"},
          "nav": [
            "管理后台",
            "LLM 调用编排服务",
            "async"
          ],
          "actions": [
            "登录管理后台",
            "进入「LLM 调用编排服务」模块",
            "执行操作"
          ],
          "backend": [
            {
              "tag": "receive",
              "text": "接收 POST /api/v1/calls/async 请求"
            },
            {
              "tag": "validate",
              "text": "验证必填字段和参数格式"
            },
            {
              "tag": "write",
              "text": "向数据库表插入新记录"
            },
            {
              "tag": "write",
              "text": "向数据库表插入新记录"
            },
            {
              "tag": "receive",
              "text": "Prompt 渲染后调用敏感词替换:查询所有已启用敏感词(enabled=True),对 system_prompt 和 user_prompt 做替换处理"
            },
            {
              "tag": "return",
              "text": "返回操作结果"
            }
          ],
          "expected": [
            "返回 taskId",
            "async_tasks 表新增任务记录"
          ]
        }
      ]
    },
    {
      "title": "查询异步调用结果(轮询模式,适配现有系统的 queryTaskResult)",
      "required": true,
      "precondition": "系统存在至少 1 条异步调用记录",
      "expect": "返回异步任务的执行结果和状态",
      "tab": "admin",
      "steps": [
        {
          "op": "OP-F-08.3.1",
          "status": "notimpl",
          "tab": "admin",
          "nav": [
            "管理后台",
            "LLM 调用编排服务",
            "query"
          ],
          "actions": [
            "登录管理后台",
            "进入「LLM 调用编排服务」模块",
            "执行操作"
          ],
          "backend": [
            {
              "tag": "receive",
              "text": "接收 GET /api/v1/calls/async/:task_id 请求"
            },
            {
              "tag": "validate",
              "text": "验证请求参数"
            },
            {
              "tag": "query",
              "text": "从数据库表按条件查询记录"
            },
            {
              "tag": "return",
              "text": "返回操作结果"
            }
          ],
          "expected": [
            "返回异步任务的执行结果和状态"
          ]
        }
      ]
    },
    {
      "title": "批量查询多个异步调用结果",
      "required": true,
      "precondition": "系统存在至少 3 条异步调用记录",
      "expect": "返回多个异步任务的结果列表",
      "tab": "admin",
      "steps": [
        {
          "op": "OP-F-08.4.1",
          "status": "notimpl",
          "tab": "admin",
          "nav": [
            "管理后台",
            "LLM 调用编排服务",
            "batch"
          ],
          "actions": [
            "登录管理后台",
            "进入「LLM 调用编排服务」模块",
            "执行操作"
          ],
          "backend": [
            {
              "tag": "receive",
              "text": "接收 POST /api/v1/calls/async/batch 请求"
            },
            {
              "tag": "validate",
              "text": "验证请求参数"
            },
            {
              "tag": "query",
              "text": "从数据库表按条件查询记录"
            },
            {
              "tag": "return",
              "text": "返回操作结果"
            }
          ],
          "expected": [
            "返回多个异步任务的结果列表"
          ]
        }
      ]
    },
    {
      "title": "质检融合:将 LLM 质检结果与规则配置按维度融合计算总分",
      "required": true,
      "precondition": "系统已配置质检规则",
      "expect": "操作执行成功",
      "tab": "api",
      "steps": [
        {
          "op": "OP-F-08.5.1",
          "status": "done",
          "tab": "api",
          "nav": [
            "API 客户端",
            "质检融合:将 LLM 质检结果与规则配置按维度融合计算总分"
          ],
          "actions": [
            "准备 API Token",
            "构造请求",
            "发送请求"
          ],
          "backend": [
            {
              "tag": "receive",
              "text": "接收 GET 内部调用 请求"
            },
            {
              "tag": "validate",
              "text": "验证请求参数"
            },
            {
              "tag": "query",
              "text": "从数据库表按条件查询记录"
            },
            {
              "tag": "return",
              "text": "返回操作结果"
            }
          ],
          "expected": [
            "操作执行成功"
          ]
        }
      ]
    },
    {
      "title": "业务调用(by-template):提供 template_id(支持UUID/业务编码) + account_id(支持UUID/业务编码) + content + mode,系统自动完成编排",
      "required": true,
      "precondition": "系统存在至少 1 个已发布的提示词模板和 1 个有效账号",
      "expect": "sync 模式直接返回 LLM 响应结果;async 模式返回 task_id",
      "tab": "api",
      "steps": [
        {
          "op": "OP-F-08.6.1",
          "status": "done",
          "changelog": {"id": "CHG-021", "date": "2026-06-17", "reason": "prompt 渲染后新增敏感词替换步骤"},
          "tab": "api",
          "nav": [
            "API 客户端",
            "业务调用(by-template)",
            "sync"
          ],
          "actions": [
            "准备 API Token",
            "构造请求体:template_id(传入 UUID 或业务编码如 TEMPLATE-GENERAL-002)+ account_id(传入 UUID 或业务编码如 LEGACY-xxx)+ content + mode=\"sync\"",
            "发送 POST /api/v1/calls/by-template"
          ],
          "backend": [
            {"tag": "receive", "text": "接收 POST /api/v1/calls/by-template 请求"},
            {"tag": "validate", "text": "验证 content/mode 必填字段,校验 template_id 和 account_id 至少提供"},
            {"tag": "query", "text": "根据 template_id 查询:先尝试按 UUID 匹配 prompt_templates 表,未找到则按 code 匹配"},
            {"tag": "query", "text": "根据 account_id 查询:先尝试按 UUID 匹配 model_account_config 表,未找到则按 code 匹配"},
            {"tag": "write", "text": "构建消息:system_prompt 从模板加载,user message = content"},
            {"tag": "receive", "text": "敏感词替换:调用 word_bank_service.list_active_words() 获取所有已启用敏感词,对 system_prompt 和 user_prompt 做替换处理"},
            {"tag": "validate", "text": "mode=sync → 直接调用 adapter_invoke 同步调用模型。adapter_invoke 内部读取账号 extra_config.thinking_enabled,若开启则注入思考模式参数"},
            {"tag": "write", "text": "创建 CallRecord 调用记录(status=success/failed)"},
            {"tag": "return", "text": "返回 {status, model_name, call_record_id, account_id, response_content(大模型原始返回内容字符串)}"}
          ],
          "expected": [
            "同步返回模型调用结果,response_content 为 LLM 原始内容字符串",
            "如果账号开启了思考模式,模型响应中体现推理过程",
            "call_records 表新增调用记录"
          ]
        },
        {
          "op": "OP-F-08.6.2",
          "status": "done",
          "changelog": {"id": "CHG-021", "date": "2026-06-17", "reason": "prompt 渲染后新增敏感词替换步骤"},
          "tab": "api",
          "nav": [
            "API 客户端",
            "业务调用(by-template)",
            "async"
          ],
          "actions": [
            "准备 API Token",
            "构造请求体:template_id(传入 UUID 或业务编码)+ account_id(传入 UUID 或业务编码)+ content + mode=\"async\"",
            "发送 POST /api/v1/calls/by-template"
          ],
          "backend": [
            {"tag": "receive", "text": "接收 POST /api/v1/calls/by-template 请求(mode=async)"},
            {"tag": "validate", "text": "验证必填字段,校验 template_id 和 account_id 至少提供"},
            {"tag": "query", "text": "根据 template_id 查询:先 UUID 匹配,未找到则按 code 匹配。account_id 同理"},
            {"tag": "write", "text": "创建 AsyncTask 记录(status=pending),创建 CallRecord"},
            {"tag": "write", "text": "提交 Celery 任务 process_async_llm_call。Celery 任务内部执行:加载模板→渲染 prompt→敏感词替换→调用 LLM→更新 CallRecord"},
            {"tag": "return", "text": "返回 {status: \"accepted\", task_id, call_record_id}"}
          ],
          "expected": [
            "返回 task_id",
            "async_tasks 表新增任务记录(status=pending)"
          ]
        }
      ]
    }
  ],
  "changelogs": [
    {
      "date": "2026-06-11",
      "id": "IMPL-F-08",
      "type": "implement",
      "title": "F-08 LLM 调用编排服务首次实现",
      "desc": "实现编排服务:prompt 渲染引擎、账号优先级匹配、同步/异步调用 API、批量查询 API。85 个测试全部通过。",
      "done": true
    },
    {"date": "2026-06-16", "id": "CHG-011", "type": "add", "title": "新增业务侧直接调用接口", "desc": "新增 POST /api/v1/calls/by-template + 前端展示页面。OP-F-08.6.1 / OP-F-08.6.2。", "done": true},
    {"date": "2026-06-16", "id": "CHG-012", "type": "modify", "title": "by-template 支持 code 查找", "desc": "POST /api/v1/calls/by-template 新增 template_code 和 account_code 参数。OP-F-08.6.1 / OP-F-08.6.2 → notimpl。", "done": true},
    {"date": "2026-06-16", "id": "CHG-013", "type": "modify", "title": "template_id/account_id 统一接受 UUID 或业务编码", "desc": "template_id/account_id 同时支持 UUID 或业务编码,后端自动识别。移除 template_code/account_code 字段。OP-F-08.6.1 / OP-F-08.6.2 → notimpl。", "done": true},
    {"date": "2026-06-16", "id": "CHG-014", "type": "modify", "title": "by-template 同步响应字段 response_body 改为 response_content", "desc": "sync 模式响应中 response_body 重命名为 response_content,值改为大模型原始字符串。OP-F-08.6.1 → notimpl。", "done": true},
    {"date": "2026-06-16", "id": "CHG-015", "type": "modify", "title": "新增账号思考模式开关", "desc": "adapter_invoke 内部读取账号 extra_config.thinking_enabled 注入思考参数。OP-F-08.6.1 → notimpl。", "done": true},
    {"date": "2026-06-17", "id": "CHG-021", "type": "modify", "title": "提示词组装集成敏感词替换", "desc": "四个编排步骤(OP-F-08.1.1/2.1/6.1/6.2)在 prompt 渲染后新增敏感词替换,调用 word_bank_service.list_active_words() 对 system_prompt 和 user_prompt 做替换处理。", "done": true}
  ]
}