feat: Agent v2 测试端点 test_agent_v2.dspy

This commit is contained in:
ymq 2026-08-10 11:06:42 +08:00
parent 390869394c
commit c071ac19e2

View File

@ -0,0 +1,44 @@
# test_agent_v2.dspy - Agent v2 测试端点
# 用法: POST /pipeline-sdlc/api/test_agent_v2.dspy
# Body: {"prompt": "诊断项目进展"}
prompt = (params_kw or {}).get('prompt', '').strip()
if not prompt:
prompt = (params_kw or {}).get('message_text', '').strip()
if not prompt:
return g.json.dumps({"error": "缺少 prompt"}, ensure_ascii=False)
uid = await get_user()
if not uid:
return g.json.dumps({"error": "请先登录"}, ensure_ascii=False)
# 加载 v2 配置和执行引擎
from pipeline_core.agent_config import load_agent_config, SDLC_DEFAULT_CONFIG
from pipeline_service.agent_loop_v2 import AgentExecutor
config = await load_agent_config()
# 获取当前项目 ID复用 cockpit 的逻辑)
dbname = get_module_dbname('pipeline-sdlc')
async with DBPools().sqlorContext(dbname) as sor:
ctx = {}
recs = await sor.sqlExe(
"SELECT current_project_id FROM pipeline_agent_settings WHERE user_id=${u}$",
{"u": uid})
if recs:
ctx['pid'] = getattr(recs[0], 'current_project_id', '') or ''
executor = AgentExecutor(
config=config,
project_id=ctx.get('pid', ''),
user_id=uid,
)
async def agent_stream():
d = g.json.dumps({"type": "progress", "message": f"Agent v2 处理中... (max_turns={config.max_turns})"}, ensure_ascii=False) + '\n'
yield d
async for chunk in executor.run(prompt):
yield chunk
return await stream_response(request, agent_stream, 'text/plain; charset=utf-8')