486fe2c78504eeccd99adfe5da8b7ed0ba5aa045 → 417ba9254b0352a43f8419c035b10ce5a95f10ddPOST /agent/run 增加「报告格式模板(report_format)」的可选覆盖能力,并贯穿到 Agent 构建层。| 文件 | 变更类型 | 说明 |
|---|---|---|
backend/src/shared/models.py | 新增字段 | AgentRunRequest 新增可选字段 report_format: Optional[str] = None |
backend/src/apis/agent_run_service.py | 透传参数 | run() 调用 create_crew 时传入 report_format=request.report_format |
backend/src/runtime/agent_factory.py | 签名 + 逻辑 | create_crew 新增 report_format 形参,并让其优先于 config 中的同名配置 |
整体是一次功能增强型改动,无删除逻辑、无破坏性接口变更,风险低。
backend/src/shared/models.pyclass AgentRunRequest(BaseModel):
...
override_llm: str = "" # 可选: 覆盖默认模型
report_format: Optional[str] = None # 可选: 覆盖报告格式模板
Optional 已在文件头部导入(from typing import Optional),字段类型合法,无导入缺失问题。None 保持了向后兼容,旧请求不受影响。backend/src/apis/agent_run_service.pycrew = factory.create_crew(
config=config,
commit_hash=commit_hash,
project=project,
branch=branch,
report_format=request.report_format, # 新增
)
run() 中透传,参数来源 request.report_format 与模型字段一致。backend/src/runtime/agent_factory.pydef create_crew(self, config: dict, commit_hash: str, project: str,
branch: str = "", report_format: str = None) -> Crew:
...
report_format = report_format if report_format else config.get("report_format", "")
report_format 为空串/None 时回退到 config,行为合理。if report_format: full_prompt_parts.append("\n## 报告格式\n\n" + report_format))未被破坏,空值时不会追加「报告格式」段落。结论:改动链路自洽,参数从 API → Service → Factory 全程贯通,覆盖优先级符合预期。
说明:本次 diff 未改动这两个问题所在的函数体,质检结果中的「修复 3 条 / 新增 3 条」实为同一批既有问题因行号位移而产生的镜像,并非真实修复或真实新增。
agent_run_service.py:500(base 行号)agent_run_service.py:500(base 行号)agent_factory.py:65(base 行号)agent_run_service.py:501 — cyclomatic complexity is high (count=11)agent_run_service.py:501 — 'batch_run' directly depends on 12 functions, exceeding the threshold of 10agent_factory.py:30 — source line exceeds 120 characters逐条核对结论:
agent_run_service.py:500 → 501:两处问题(复杂度、耦合)均落在 batch_run 上,本次 diff 未改动 batch_run 函数体,仅因单配置 run() 增加一行使行号 +1 而下移,属同一既有问题,非新增、也不存在真实修复。agent_factory.py:65 → 30:base 行 65 与 head 行 30 对应的是 create_crew 的签名行,本次改动将该行加长(新增 report_format: str = None 形参)后超长问题被重新定位。属同一既有问题的重新标注。净变化:真实「修复 bug」= 0 条;真实「新增 bug」= 0 条。
风险等级:低。无功能性回归风险,接口保持向后兼容。
[一致性] 覆盖能力仅覆盖单配置入口
AgentBatchRequest(POST /agent/batch)未提供 report_format 字段,batch_run._run_one() 调用 create_crew 时也未透传;run_code_wiki 同样未透传。若产品预期批处理/文档生成也支持自定义报告格式,则存在能力不一致。建议按需在 AgentBatchRequest 增加同名可选字段并在 _run_one 中透传。
[健壮性] report_format 缺少长度/内容约束
该参数最终被拼接进 full_prompt,作为 LLM 的后处理指令。Optional[str] 对传入长度和内容无上限,超长或异常内容可能挤占 prompt 预算。建议在模型层加 max_length 约束,或在 Factory 拼接时做长度截断。
[可读性] create_crew 签名行超长
agent_factory.py:30 已触发「行过长(> 120 字符)」告警。建议将形参换行书写,消除该告警:
def create_crew(
self,
config: dict,
commit_hash: str,
project: str,
branch: str = "",
report_format: str = None,
) -> Crew:
[既有技术债] batch_run 复杂度/耦合超阈值
虽然本次未引入,但 batch_run 圈复杂度 11、直接依赖 12 个函数,已超过阈值,建议后续迭代拆分(提取 _run_one 之外的响应组装/结果聚合逻辑)。
本次变更为一项小而聚拢的功能增强:新增 report_format 覆盖字段,并沿 AgentRunRequest → agent_run_service.run → AgentFactory.create_crew 正确贯通,覆盖优先级设计合理,无逻辑缺陷与回归风险。质检对比中的「修复/新增」条目实为同一既有问题的行号位移镜像,真实修复与真实新增均为 0。后续可关注批处理/文档生成入口的一致性补齐及入参长度约束。