From c071ac19e2cc2d064656ea887390be515cc7be54 Mon Sep 17 00:00:00 2001 From: ymq Date: Mon, 10 Aug 2026 11:06:42 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20Agent=20v2=20=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E7=AB=AF=E7=82=B9=20test=5Fagent=5Fv2.dspy?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- wwwroot/api/test_agent_v2.dspy | 44 ++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 wwwroot/api/test_agent_v2.dspy diff --git a/wwwroot/api/test_agent_v2.dspy b/wwwroot/api/test_agent_v2.dspy new file mode 100644 index 0000000..2f126f7 --- /dev/null +++ b/wwwroot/api/test_agent_v2.dspy @@ -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')