# 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 json.dumps({"error": "缺少 prompt"}, ensure_ascii=False) uid = await get_user() # 测试模式:无认证时使用 test-user if not uid: uid = 'user-01' # fallback for testing # 加载 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 = json.dumps({"type": "progress", "message": "Agent v2 ... (max_turns=" + str(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')