|
@@ -276,6 +276,48 @@ def _build_evaluate_prompt(goal_description: str, messages: Optional[Messages])
|
|
|
return "\n".join(lines)
|
|
return "\n".join(lines)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+def _make_event_printer(label: str):
|
|
|
|
|
+ """
|
|
|
|
|
+ 创建子 Agent 执行过程打印函数。
|
|
|
|
|
+
|
|
|
|
|
+ 当父 runner.debug=True 时,传给 run_result(on_event=...),
|
|
|
|
|
+ 实时输出子 Agent 的工具调用和助手消息。
|
|
|
|
|
+ """
|
|
|
|
|
+ prefix = f" [{label}]"
|
|
|
|
|
+
|
|
|
|
|
+ def on_event(item):
|
|
|
|
|
+ from agent.trace.models import Trace, Message
|
|
|
|
|
+ if isinstance(item, Message):
|
|
|
|
|
+ if item.role == "assistant":
|
|
|
|
|
+ content = item.content
|
|
|
|
|
+ if isinstance(content, dict):
|
|
|
|
|
+ text = content.get("text", "")
|
|
|
|
|
+ tool_calls = content.get("tool_calls")
|
|
|
|
|
+ if text:
|
|
|
|
|
+ preview = text[:120] + "..." if len(text) > 120 else text
|
|
|
|
|
+ print(f"{prefix} {preview}")
|
|
|
|
|
+ if tool_calls:
|
|
|
|
|
+ for tc in tool_calls:
|
|
|
|
|
+ name = tc.get("function", {}).get("name", "unknown")
|
|
|
|
|
+ print(f"{prefix} 🛠️ {name}")
|
|
|
|
|
+ elif item.role == "tool":
|
|
|
|
|
+ content = item.content
|
|
|
|
|
+ if isinstance(content, dict):
|
|
|
|
|
+ name = content.get("tool_name", "unknown")
|
|
|
|
|
+ desc = item.description or ""
|
|
|
|
|
+ desc_short = (desc[:60] + "...") if len(desc) > 60 else desc
|
|
|
|
|
+ suffix = f": {desc_short}" if desc_short else ""
|
|
|
|
|
+ print(f"{prefix} ✅ {name}{suffix}")
|
|
|
|
|
+ elif isinstance(item, Trace):
|
|
|
|
|
+ if item.status == "completed":
|
|
|
|
|
+ print(f"{prefix} ✓ 完成")
|
|
|
|
|
+ elif item.status == "failed":
|
|
|
|
|
+ err = (item.error_message or "")[:80]
|
|
|
|
|
+ print(f"{prefix} ✗ 失败: {err}")
|
|
|
|
|
+
|
|
|
|
|
+ return on_event
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
# ===== 统一内部执行函数 =====
|
|
# ===== 统一内部执行函数 =====
|
|
|
|
|
|
|
|
async def _run_agents(
|
|
async def _run_agents(
|
|
@@ -365,6 +407,10 @@ async def _run_agents(
|
|
|
agent_msgs = list(msgs) + [{"role": "user", "content": task_item}]
|
|
agent_msgs = list(msgs) + [{"role": "user", "content": task_item}]
|
|
|
allowed_tools = _get_allowed_tools(single, context)
|
|
allowed_tools = _get_allowed_tools(single, context)
|
|
|
|
|
|
|
|
|
|
+ debug = getattr(runner, 'debug', False)
|
|
|
|
|
+ agent_label = (agent_type or ("delegate" if single else f"explore-{i+1}"))
|
|
|
|
|
+ on_event = _make_event_printer(agent_label) if debug else None
|
|
|
|
|
+
|
|
|
coro = runner.run_result(
|
|
coro = runner.run_result(
|
|
|
messages=agent_msgs,
|
|
messages=agent_msgs,
|
|
|
config=_make_run_config(
|
|
config=_make_run_config(
|
|
@@ -376,6 +422,7 @@ async def _run_agents(
|
|
|
name=task_item[:50],
|
|
name=task_item[:50],
|
|
|
skills=skills,
|
|
skills=skills,
|
|
|
),
|
|
),
|
|
|
|
|
+ on_event=on_event,
|
|
|
)
|
|
)
|
|
|
coros.append((i, cur_stid, collab_name, coro))
|
|
coros.append((i, cur_stid, collab_name, coro))
|
|
|
|
|
|
|
@@ -664,6 +711,7 @@ async def evaluate(
|
|
|
tools=allowed_tools,
|
|
tools=allowed_tools,
|
|
|
name=f"评估: {goal_id}",
|
|
name=f"评估: {goal_id}",
|
|
|
),
|
|
),
|
|
|
|
|
+ on_event=_make_event_printer("evaluate") if getattr(runner, 'debug', False) else None,
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
await broadcast_sub_trace_completed(
|
|
await broadcast_sub_trace_completed(
|