一键导入
add-workflow
在 app/agents/workflows/ 新增一条 LangGraph 风格工作流(WorkflowDefinition + WorkflowEdge + 条件边 + build_xxx_orchestrator 工厂),仅组合现有业务 Agent,不写业务逻辑。
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
菜单
在 app/agents/workflows/ 新增一条 LangGraph 风格工作流(WorkflowDefinition + WorkflowEdge + 条件边 + build_xxx_orchestrator 工厂),仅组合现有业务 Agent,不写业务逻辑。
用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
基于 SOC 职业分类
在 app/agents/business/ 新增一个业务 Agent(继承 BaseAgent,含 name / output_schema / async _process / mock 模式),并在 business/__init__.py 导出,遵循双词命名 + from __future__ annotations + ModelRouter 路由约定。
在 ATP 后端新增一个 ORM 模型(继承 BaseModel,含 id/created_at/updated_at),并写一次性 migration 脚本到 app/migrations/,更新 README 数据库表清单。
在 ATP 后端新增一个 RESTful 接口(flask-smorest MethodView + Marshmallow Schema + login_required + check_project_permission + service 分层),自动按项目目录约定落位并在 flask_app.py 注册蓝图。
在 client/src/views/ 新增一个 Vue 3 + Element Plus 页面,配套 client/src/api/ 接口模块,并在 client/src/router/index.js 注册路由(含 requiresAuth 守卫)。
按 ATP 项目约定对一组改动做 code review(命名 / 分层 / 装饰器顺序 / 响应格式 / from __future__ / token 经济性 / 安全),输出按文件聚合 + 必修 / 建议 / 可忽略三档分级的报告。
给 ATP 后端的 service / engine / agent / route 模块补 pytest 测试,按"正常 / 边界 / 异常"三类组织 TestXxx 类,必要时用 unittest.mock + Flask app context + sqlite in-memory,落位到 app/tests/。
| name | add-workflow |
| description | 在 app/agents/workflows/ 新增一条 LangGraph 风格工作流(WorkflowDefinition + WorkflowEdge + 条件边 + build_xxx_orchestrator 工厂),仅组合现有业务 Agent,不写业务逻辑。 |
用户说要"新增 / 加 / 编一条 workflow / 工作流 / DAG / 流程图",串联多个业务 Agent。 典型触发词:「加一个 xx 测试工作流」「编一条 DAG 把 a/b/c 串起来」「再加一个流程跑 xxx」。
确认(缺哪个问哪个):
regression_workflow / perf_testing)app/agents/business/ 注册过)(state) -> boolskip_result 用法:state.input_data["skip_xxx"] = True 时跳过末端节点)from __future__ import annotations,与 agent 层一致。<name>_workflow: WorkflowDefinition —— 顶层定义build_<name>_orchestrator() -> LangGraphOrchestrator —— 注册 Agent + workflow 的工厂__all__ 列表_xxx(下划线前缀,模块私有),签名 (state: AgentState) -> bool,只读 state,不副作用。LangGraphOrchestrator 检测到环会停下报警告,但不要依赖兜底,自己保证。api_testing_workflow.py 的"Token 经济性"段落。强制读:
app/agents/workflows/testcase_generation_workflow.py —— 5 节点(intent → testcase → review_gate → persistence → result)app/agents/workflows/api_testing_workflow.py —— 6 节点 + 多重条件边app/agents/orchestration/orchestrator.py —— WorkflowDefinition / WorkflowEdge 字段新建 app/agents/workflows/<name>_workflow.py:
"""
<工作流中文名>定义。
DAG
---
::
a ─► b ─► c ─► d
- ``a`` <职责>
- ``b`` <职责>
- ...
输入契约
--------
::
state.input_data 必填字段
--------------------------
requirement str <说明>
project_id int <说明>
可选字段
--------
mock bool 全链路 mock,零 token
skip_<node> bool 跳过末端节点
Token 经济性
------------
| 节点 | tier | 单次 token | 备注 |
|------|-------|-----------|------|
| a | small | 200–500 | 分类 |
| b | medium| 1k–2k | 生成 |
| ...
总成本估算:约 X–Y token / 次。
作者: yandc
"""
from __future__ import annotations
from app.agents.business import (
AAgent,
BAgent,
CAgent,
DAgent,
)
from app.agents.orchestration import (
AgentState,
LangGraphOrchestrator,
WorkflowDefinition,
WorkflowEdge,
)
# ---------------------------------------------------------------------------
# 条件边
# ---------------------------------------------------------------------------
def _is_target_intent(state: AgentState) -> bool:
"""只有意图为 <xxx> 时才继续(节流:其他类型直接停下)。"""
return state.output_data.get("test_type") == "<xxx>"
def _approved(state: AgentState) -> bool:
return state.output_data.get("review_decision") == "approved"
def _should_run_d(state: AgentState) -> bool:
"""``skip_d`` 开关;默认走完。"""
return not state.input_data.get("skip_d", False)
# ---------------------------------------------------------------------------
# 工作流定义
# ---------------------------------------------------------------------------
<name>_workflow = WorkflowDefinition(
name="<name>",
entry_point="a",
edges={
"a": [WorkflowEdge(target="b", condition=_is_target_intent)],
"b": [WorkflowEdge(target="c", condition=_approved)],
"c": [WorkflowEdge(target="d", condition=_should_run_d)],
},
)
# ---------------------------------------------------------------------------
# 工厂
# ---------------------------------------------------------------------------
def build_<name>_orchestrator() -> LangGraphOrchestrator:
"""构造一个已经注册好 N 个 Agent + <工作流中文名>的编排器。"""
orch = LangGraphOrchestrator()
orch.register_agent("a", AAgent())
orch.register_agent("b", BAgent())
orch.register_agent("c", CAgent())
orch.register_agent("d", DAgent())
orch.register_workflow(<name>_workflow)
return orch
__all__ = [
"<name>_workflow",
"build_<name>_orchestrator",
]
__init__.py 导出修改 app/agents/workflows/__init__.py:
from app.agents.workflows.<name>_workflow import (
<name>_workflow,
build_<name>_orchestrator,
)
__all__ = [
# ...
"<name>_workflow",
"build_<name>_orchestrator",
]
如果用户希望前端能触发该工作流,需在 app/routes/agent_workflow.py(或新建路由)里调 build_<name>_orchestrator()。这一步不属于 add-workflow 本身,建议触发后让用户走 add-route skill。
import asyncio
import uuid
from app.agents.orchestration import AgentState
from app.agents.workflows import build_<name>_orchestrator
orch = build_<name>_orchestrator()
state = AgentState(
task_id=str(uuid.uuid4()),
correlation_id=str(uuid.uuid4()),
workflow_id="<name>",
input_data={"requirement": "测一个登录接口", "project_id": 1, "mock": True},
)
final = asyncio.run(orch.run_workflow("<name>", state))
print(final.metadata.get("workflow_status"))
print(final.output_data)
from app.agents.workflows import build_<name>_orchestrator 能 import。workflow_status == "completed"。business/ 中由 add-agent 完成。register_agent 必须先于 register_workflow。entry_point —— 必填字段。