-
diff --git a/offline-backend-20260512/backend/app/gateway/routers/multi_agent.py b/offline-backend-20260512/backend/app/gateway/routers/multi_agent.py
index e0dabe0e..940aca3c 100644
--- a/offline-backend-20260512/backend/app/gateway/routers/multi_agent.py
+++ b/offline-backend-20260512/backend/app/gateway/routers/multi_agent.py
@@ -205,13 +205,21 @@ async def init_multi_agent(request: Request, payload: dict = Body(...)) -> dict[
headers = _auth_headers(request)
async with httpx.AsyncClient(timeout=None) as client:
- agent_threads: dict[str, str] = {}
- descriptions: list[str] = []
- for sub_id in agent_names:
+ # Optimization A: fetch every sub-agent's metadata and create its
+ # thread concurrently. With 6 seats this turns ~12 sequential
+ # loopback round-trips into one wave of 12 parallel ones.
+ async def _prepare_sub_agent(sub_id: str) -> tuple[str, str, str]:
info = await _get_agent(client, base, headers, sub_id)
sub_name = str(info["name"]).lower()
- agent_threads[sub_name] = await _create_thread(client, base, headers)
- descriptions.append(f"agent_name:{sub_name},{info.get('description', '')}")
+ thread_id = await _create_thread(client, base, headers)
+ return sub_name, thread_id, info.get("description", "") or ""
+
+ prepared = await asyncio.gather(*(_prepare_sub_agent(sid) for sid in agent_names))
+
+ agent_threads: dict[str, str] = {sub_name: thread_id for sub_name, thread_id, _ in prepared}
+ descriptions: list[str] = [
+ f"agent_name:{sub_name},{description}" for sub_name, _, description in prepared
+ ]
soul = (
"#核心定位:\n"
@@ -237,13 +245,10 @@ async def init_multi_agent(request: Request, payload: dict = Body(...)) -> dict[
if not ok and isinstance(result, str) and "exists" not in result:
raise HTTPException(status_code=500, detail=f"create coordinator agent failed: {result}")
- intro = (
- "你的职责:你只是若干个智能体的其中一员,你们的共同目标是完成一个庞大的任务,"
- "总控控制协调智能体会分配特定的活给你,你只需要用你自身的能力来完成这个特定的活\n"
- "注意:你只是一个子智能体,你不必把你的分析结果存放到文件里面去,"
- "你只关心于完成总控控制协调智能体分配的活即可"
- )
- await _broadcast(client, base, headers, intro, agent_threads, [main_agent_name])
+ # Optimization C: the sub-agent SOULs already declare "你只在被点到时
+ # 发言,由总控协调智能体派活", so the old intro broadcast (one human
+ # message per thread, 6 × GET-state + 6 × POST-state) is redundant.
+ # Skipping it removes the slowest stage of init entirely.
return {
"status": "success",
@@ -330,9 +335,10 @@ async def _leader_run(
captured = done
last_msg = _parse_last_message(captured)
+ leader_text = _flatten_content(last_msg.get("content", ""))
tool_calls = last_msg.get("tool_calls") or []
if not tool_calls:
- yield {"status": []}
+ yield {"status": [], "content": leader_text, "agent_name": agent_name}
return
dispatched: list[list[str]] = []
@@ -352,7 +358,7 @@ async def _leader_run(
dispatched.append([sub_name, task_text])
except Exception as exc:
logger.warning("dispatch failed: %s", exc)
- yield {"status": dispatched}
+ yield {"status": dispatched, "content": leader_text, "agent_name": agent_name}
async def _special_run(
@@ -392,7 +398,11 @@ async def _special_run(
agent_threads,
[agent_name],
)
- yield {"status": f"子智能体{agent_name}完成{new_message}工作"}
+ yield {
+ "status": f"子智能体{agent_name}完成{new_message}工作",
+ "content": content,
+ "agent_name": agent_name,
+ }
@router.post("/run/stream")