Skip to content

JiuwenSwarm is an intelligent AI Agent built on openJiuwen. It extends the powerful capabilities of large language models directly to your fingertips through various communication apps you use daily.

Python

fix(skill-turbo): 输出任务列表为任务编号

n99357702835dd87126f85
diff --git a/jiuwenswarm/agents/harness/common/rails/stream_event_rail.py b/jiuwenswarm/agents/harness/common/rails/stream_event_rail.py
index fce2418f65..d319ad613f 100644
--- a/jiuwenswarm/agents/harness/common/rails/stream_event_rail.py
+++ b/jiuwenswarm/agents/harness/common/rails/stream_event_rail.py
@@ -49,6 +49,9 @@ from jiuwenswarm.agents.harness.common.rails.read_file_validation import (
is_read_file_tool,
normalize_read_file_tool_outcome,
)
+from jiuwenswarm.agents.harness.common.rails.task_execution_rail import (
+ SKILL_TURBO_OUTER_TODO_ACTIVE_EXTRA_KEY,
+)
from jiuwenswarm.common.tool_display import (
build_tool_display_name,
extract_call_goal,
@@ -288,6 +291,7 @@ _SKILL_TURBO_METADATA_TOKEN_EXTRA_KEY = "_jiuwenswarm_skill_turbo_metadata_token
_SKILL_TURBO_WORKSPACE_TOKEN_EXTRA_KEY = "_jiuwenswarm_skill_turbo_workspace_token"
_SKILL_TURBO_INTERACTIVE_ASK_TOKEN_EXTRA_KEY = "_jiuwenswarm_skill_turbo_interactive_ask_token"
_SKILL_TURBO_RESUME_ANSWERS_TOKEN_EXTRA_KEY = "_jiuwenswarm_skill_turbo_resume_answers_token"
+_SKILL_TURBO_OUTER_TODO_TOKEN_EXTRA_KEY = "_jiuwenswarm_skill_turbo_outer_todo_token"
_SUBAGENT_PARENT_SESSION_TOKEN_EXTRA_KEY = "_jiuwenswarm_subagent_parent_session_token"
@@ -343,6 +347,29 @@ def _reset_skill_turbo_resume_answers_token(ctx: AgentCallbackContext) -> None:
reset_skill_turbo_resume_answers(token)
+def _reset_skill_turbo_outer_todo_token(ctx: AgentCallbackContext) -> None:
+ """Restore the display-ownership binding for this tool call."""
+ token = ctx.extra.pop(_SKILL_TURBO_OUTER_TODO_TOKEN_EXTRA_KEY, None)
+ if token is not None:
+ from jiuwenswarm.server.runtime.skill_turbo.skill_turbo_tools import (
+ reset_skill_turbo_outer_todo_active,
+ )
+ reset_skill_turbo_outer_todo_active(token)
+
+
+def _bind_skill_turbo_outer_todo_token(ctx: AgentCallbackContext) -> None:
+ """Rebind outer-todo display ownership into the tool context."""
+ active = ctx.extra.get(SKILL_TURBO_OUTER_TODO_ACTIVE_EXTRA_KEY)
+ if not isinstance(active, bool):
+ return
+ from jiuwenswarm.server.runtime.skill_turbo.skill_turbo_tools import (
+ set_skill_turbo_outer_todo_active,
+ )
+ ctx.extra[_SKILL_TURBO_OUTER_TODO_TOKEN_EXTRA_KEY] = (
+ set_skill_turbo_outer_todo_active(active)
+ )
+
+
def _reset_subagent_parent_session_token(ctx: AgentCallbackContext) -> None:
"""Restore subagent parent session ContextVar binding for this tool call."""
token = ctx.extra.pop(_SUBAGENT_PARENT_SESSION_TOKEN_EXTRA_KEY, None)
@@ -948,6 +975,7 @@ class JiuSwarmStreamEventRail(DeepAgentRail):
_reset_skill_turbo_workspace_token(ctx)
_reset_skill_turbo_interactive_ask_token(ctx)
_reset_skill_turbo_resume_answers_token(ctx)
+ _reset_skill_turbo_outer_todo_token(ctx)
_reset_subagent_parent_session_token(ctx)
# ------------------------------------------------------------------
@@ -1210,6 +1238,8 @@ class JiuSwarmStreamEventRail(DeepAgentRail):
exc_info=True,
)
+ _bind_skill_turbo_outer_todo_token(ctx)
+
# SkillTurbo request metadata ContextVar 转绑:
# 请求任务里 set_current_request_metadata 的绑定无法传播到本工具执行上下文,
# 这里用 rail 上保存的副本重新绑定,供 skill_turbo 工具读取 session_id 等。
@@ -1276,6 +1306,7 @@ class JiuSwarmStreamEventRail(DeepAgentRail):
async def after_tool_call(self, ctx: AgentCallbackContext) -> None:
_reset_subagent_parent_session_token(ctx)
_reset_skill_turbo_resume_answers_token(ctx)
+ _reset_skill_turbo_outer_todo_token(ctx)
session = ctx.session
if session is None or not isinstance(ctx.inputs, ToolCallInputs):
@@ -1394,6 +1425,7 @@ class JiuSwarmStreamEventRail(DeepAgentRail):
_reset_skill_turbo_workspace_token(ctx)
_reset_skill_turbo_interactive_ask_token(ctx)
_reset_skill_turbo_resume_answers_token(ctx)
+ _reset_skill_turbo_outer_todo_token(ctx)
_reset_subagent_parent_session_token(ctx)
if ctx.context is not None:
logger.info("[StreamEventRail] Attempting context repair after model exception")
diff --git a/jiuwenswarm/agents/harness/common/rails/task_execution_rail.py b/jiuwenswarm/agents/harness/common/rails/task_execution_rail.py
index 9afdbe5e09..1b46ac1534 100644
--- a/jiuwenswarm/agents/harness/common/rails/task_execution_rail.py
+++ b/jiuwenswarm/agents/harness/common/rails/task_execution_rail.py
@@ -35,6 +35,9 @@ from jiuwenswarm.common.utils import logger
_ACTIVE_TASK_ID: ContextVar[str | None] = ContextVar(
"active_task_id", default=None
)
+SKILL_TURBO_OUTER_TODO_ACTIVE_EXTRA_KEY = (
+ "_jiuwenswarm_skill_turbo_outer_todo_active"
+)
def get_current_task_id() -> str | None:
@@ -970,6 +973,13 @@ class TaskExecutionRail(DeepAgentRail):
self._tool_start_times[tool_call_id] = time.time()
self._bind_context_to_in_progress_task()
+ if tool_name == "skill_acceleration_exec":
+ # Rail callbacks and the tool body may run in copied Contexts.
+ # Export only display ownership; this does not affect tool
+ # registration, selection, or execution.
+ ctx.extra[SKILL_TURBO_OUTER_TODO_ACTIVE_EXTRA_KEY] = (
+ _ACTIVE_TASK_ID.get() is not None
+ )
async def after_tool_call(self, ctx: AgentCallbackContext) -> None:
if not isinstance(ctx.inputs, ToolCallInputs):
diff --git a/jiuwenswarm/server/runtime/skill_turbo/skill_turbo_tools.py b/jiuwenswarm/server/runtime/skill_turbo/skill_turbo_tools.py
index 6bcccdf9ef..82bbcb1613 100644
--- a/jiuwenswarm/server/runtime/skill_turbo/skill_turbo_tools.py
+++ b/jiuwenswarm/server/runtime/skill_turbo/skill_turbo_tools.py
@@ -81,10 +81,37 @@ _SKILL_TURBO_TASK_EVENT_TYPES: frozenset[str] = frozenset({
"task.update",
})
+
+def _without_inner_task_routing(payload: dict[str, Any]) -> dict[str, Any]:
+ """Copy a parent-bound event without its SkillTurbo-only task id."""
+ task_id = payload.get("task_id")
+ if not isinstance(task_id, str) or not task_id.startswith("task_"):
+ return payload
+ cleaned = dict(payload)
+ cleaned.pop("task_id", None)
+ return cleaned
+
+
# ── ContextVar:在 before_tool_call 中注入,供工具函数读取 ──
_current_skill_turbo_adapter: ContextVar[Any] = ContextVar(
"current_skill_turbo_adapter", default=None
)
+_skill_turbo_outer_todo_active: ContextVar[bool | None] = ContextVar(
+ "skill_turbo_outer_todo_active", default=None
+)
+
+
+def set_skill_turbo_outer_todo_active(active: bool) -> Token:
+ """Bind whether the parent task list owns this tool call's display."""
+ return _skill_turbo_outer_todo_active.set(active)
+
+
+def get_skill_turbo_outer_todo_active() -> bool | None:
+ return _skill_turbo_outer_todo_active.get()
+
+
+def reset_skill_turbo_outer_todo_active(token: Token) -> None:
+ _skill_turbo_outer_todo_active.reset(token)
# ── ContextVar:SkillTurbo HITL 中断信号 ──
# skill_turbo_tools catch AbortError 后提取 ToolInterruptException 存入此 ContextVar,
@@ -376,11 +403,18 @@ async def skill_turbo(query: str) -> dict[str, Any] | str:
# chat.* 事件自然归到外层 todo 步骤的 segment 下渲染。
# 无活跃 todo 时:PPT 的 task 事件正常转发,独立展示步骤列表。
outer_task_id = get_current_task_id()
- has_outer_todo = outer_task_id is not None
+ rebound_outer_todo = get_skill_turbo_outer_todo_active()
+ has_outer_todo = (
+ rebound_outer_todo
+ if rebound_outer_todo is not None
+ else outer_task_id is not None
+ )
logger.info(
- "[SkillTurboTool] outer todo active=%s outer_task_id=%s parent_session=%s, "
+ "[SkillTurboTool] outer todo active=%s rebound=%s outer_task_id=%s "
+ "parent_session=%s, "
"task events will be %s",
has_outer_todo,
+ rebound_outer_todo,
outer_task_id,
type(parent_session).__name__ if parent_session is not None else None,
"skipped" if has_outer_todo else "forwarded as-is",
@@ -551,6 +585,13 @@ async def skill_turbo(query: str) -> dict[str, Any] | str:
if has_outer_todo and event_type in _SKILL_TURBO_TASK_EVENT_TYPES:
continue
+ payload = chunk.payload
+ if has_outer_todo and isinstance(payload, dict):
+ # Internal task ids are meaningful to SkillTurbo itself, but
+ # become untitled task rows in the parent UI. The original
+ # chunk remains untouched for execution/resume diagnostics.
+ payload = _without_inner_task_routing(payload)
+
# 转发 chunk 到父会话 stream(前端实时可见)
if parent_session is not None:
# SkillTurbo executor 产出的 event_type 带 "chat." 前缀(如 "chat.tool_call"),
@@ -560,7 +601,7 @@ async def skill_turbo(query: str) -> dict[str, Any] | str:
output = OutputSchema(
type=output_type,
index=0,
- payload=chunk.payload,
+ payload=payload,
)
try:
await parent_session.write_stream(output)
diff --git a/tests/unit_tests/agentserver/rails/test_task_execution_todo_create_defer_start.py b/tests/unit_tests/agentserver/rails/test_task_execution_todo_create_defer_start.py
index 12740c2e9e..44e2328a8e 100644
--- a/tests/unit_tests/agentserver/rails/test_task_execution_todo_create_defer_start.py
+++ b/tests/unit_tests/agentserver/rails/test_task_execution_todo_create_defer_start.py
@@ -7,8 +7,10 @@ from __future__ import annotations
from types import SimpleNamespace
import pytest
+from openjiuwen.core.single_agent.rail.base import ToolCallInputs
from jiuwenswarm.agents.harness.common.rails.task_execution_rail import (
+ SKILL_TURBO_OUTER_TODO_ACTIVE_EXTRA_KEY,
TaskExecutionRail,
get_current_task_id,
)
@@ -117,6 +119,39 @@ async def test_lazy_start_opens_deferred_in_progress_on_work_tool(monkeypatch) -
assert "todo:sync_weekly_report_0831" in rail._active_tasks
+async def test_skill_turbo_tool_call_exports_outer_todo_display_ownership() -> None:
+ rail = TaskExecutionRail()
+ rail._todo_map = {
+ "create_ppt": {
+ "content": "生成 PPT",
+ "status": "pending",
+ "index": 0,
+ "total": 1,
+ },
+ }
+ tool_call = SimpleNamespace(
+ id="call-skill-turbo",
+ name="skill_acceleration_exec",
+ arguments={"query": "生成 PPT"},
+ )
+ ctx = SimpleNamespace(
+ session=_FakeSession(),
+ inputs=ToolCallInputs(
+ tool_call=tool_call,
+ tool_name=tool_call.name,
+ tool_args=tool_call.arguments,
+ tool_result=None,
+ ),
+ extra={},
+ )
+
+ await rail.before_tool_call(ctx)
+
+ assert get_current_task_id() == "todo:create_ppt"
+ assert ctx.extra[SKILL_TURBO_OUTER_TODO_ACTIVE_EXTRA_KEY] is True
+
+
@pytest.mark.asyncio
async def test_deferred_in_progress_completed_emits_start_then_complete(monkeypatch) -> None:
rail = TaskExecutionRail()
diff --git a/tests/unit_tests/agentserver/test_skill_turbo_tools.py b/tests/unit_tests/agentserver/test_skill_turbo_tools.py
index 75885bbc50..d873989a80 100644
--- a/tests/unit_tests/agentserver/test_skill_turbo_tools.py
+++ b/tests/unit_tests/agentserver/test_skill_turbo_tools.py
@@ -9,7 +9,12 @@ from unittest.mock import AsyncMock, MagicMock, patch
import pytest
from jiuwenswarm.server.runtime.skill_turbo.plan_node import AbortError
-from jiuwenswarm.server.runtime.skill_turbo.skill_turbo_tools import skill_turbo
+from jiuwenswarm.server.runtime.skill_turbo.skill_turbo_tools import (
+ _without_inner_task_routing,
+ reset_skill_turbo_outer_todo_active,
+ set_skill_turbo_outer_todo_active,
+ skill_turbo,
+)
_QUERY = "做一份关于黄仁勋GTC讲话的PPT"
@@ -38,9 +43,24 @@ def _skill_turbo_runtime():
def test_skill_acceleration_exec_defers_timeout_to_pipeline() -> None:
+ assert skill_turbo.card.name == "skill_acceleration_exec"
assert skill_turbo.card.properties["resilience"]["timeout_s"] is None
+def test_without_inner_task_routing_preserves_stage_content() -> None:
+ payload = {
+ "event_type": "chat.delta",
+ "content": "开始执行 Stage 2: 意图分类(2/14)",
+ "task_id": "task_6d61d336",
+ }
+
+ cleaned = _without_inner_task_routing(payload)
+
+ assert "task_id" not in cleaned
+ assert cleaned["content"] == payload["content"]
+ assert payload["task_id"] == "task_6d61d336"
+
+
@pytest.mark.asyncio
async def test_load_resume_ctx_failure_still_post_runs_turbo_session(_skill_turbo_runtime) -> None:
adapter, turbo_session = _skill_turbo_runtime
@@ -431,3 +451,105 @@ async def test_not_handled_clears_resume_ctx(_skill_turbo_runtime) -> None:
assert result.get("success") is False
clear_ctx.assert_awaited_once_with(turbo_session)
turbo_session.post_run.assert_awaited_once()
+
+
+ ("outer_todo_active", "expected_event_types"),
+ [
+ (True, ["chat.delta", "chat.usage_metadata"]),
+ (False, ["task.update", "chat.delta", "chat.usage_metadata"]),
+ ],
+)
+async def test_outer_todo_hides_inner_tasks_without_hiding_stage_messages(
+ _skill_turbo_runtime,
+ outer_todo_active: bool,
+ expected_event_types: list[str],
+) -> None:
+ adapter, _turbo_session = _skill_turbo_runtime
+ parent_session = SimpleNamespace(
+ write_stream=AsyncMock(),
+ get_session_id=lambda: "sess-1",
+ )
+
+ async def stream(*_args, **_kwargs):
+ yield SimpleNamespace(
+ payload={
+ "event_type": "task.update",
+ "tasks": [{
+ "task_id": "task_deadbeef",
+ "task_content": "Stage 1: 流水线初始化",
+ "status": "in_progress",
+ }],
+ }
+ )
+ yield SimpleNamespace(
+ payload={
+ "event_type": "chat.delta",
+ "content": "开始执行 Stage 1: 流水线初始化(1/14)\n",
+ "task_id": "task_deadbeef",
+ }
+ )
+ yield SimpleNamespace(
+ payload={
+ "event_type": "chat.usage_metadata",
+ "metadata": {"plan_name": "p1_intent_classify"},
+ "task_id": "task_6d61d336",
+ }
+ )
+
+ turbo = _fake_turbo()
+ turbo.run_stream = MagicMock(side_effect=stream)
+ token = set_skill_turbo_outer_todo_active(outer_todo_active)
+ try:
+ with (
+ patch(
+ "jiuwenswarm.server.runtime.skill_turbo.skill_turbo_tools.get_current_skill_turbo_adapter",
+ return_value=adapter,
+ ),
+ patch(
+ "jiuwenswarm.server.runtime.skill_turbo.skill_turbo_tools.get_current_task_id",
+ return_value=None,
+ ),
+ patch(
+ "jiuwenswarm.server.runtime.skill_turbo.skill_turbo_tools.get_skill_turbo_resume_answers",
+ return_value=None,
+ ),
+ patch(
+ "jiuwenswarm.server.runtime.skill_turbo.skill_turbo_tools.get_current_request_metadata",
+ return_value={},
+ ),
+ patch(
+ "jiuwenswarm.agents.harness.common.tools.subagent_executor.get_subagent_parent_session",
+ return_value=parent_session,
+ ),
+ patch(
+ "jiuwenswarm.agents.harness.common.tools.subagent_executor.context_vars.get_effective_request_workspace_dir",
+ return_value=None,
+ ),
+ patch(
+ "jiuwenswarm.server.runtime.skill_turbo.agent.SkillTurbo",
+ return_value=turbo,
+ ),
+ ):
+ result = await skill_turbo.invoke({"query": _QUERY})
+ finally:
+ reset_skill_turbo_outer_todo_active(token)
+
+ assert result.get("success") is True
+ forwarded = [
+ call.args[0].payload
+ for call in parent_session.write_stream.await_args_list
+ ]
+ assert [
+ payload["event_type"] for payload in forwarded
+ ] == expected_event_types
+ delta = next(
+ payload for payload in forwarded
+ if payload["event_type"] == "chat.delta"
+ )
+ assert "Stage 1: 流水线初始化" in delta["content"]
+ if outer_todo_active:
+ assert all("task_id" not in payload for payload in forwarded)
+ else:
+ assert forwarded[0]["tasks"][0]["task_id"] == "task_deadbeef"
diff --git a/tests/unit_tests/agentserver/test_stream_event_rail_todo.py b/tests/unit_tests/agentserver/test_stream_event_rail_todo.py
index a305f941e4..1d428ecfb0 100644
--- a/tests/unit_tests/agentserver/test_stream_event_rail_todo.py
+++ b/tests/unit_tests/agentserver/test_stream_event_rail_todo.py
@@ -6,6 +6,14 @@ from openjiuwen.core.single_agent.rail.base import ToolCallInputs
from openjiuwen.harness.rails.interrupt.ask_user_rail import AskUserRequest
from jiuwenswarm.agents.harness.common.rails.stream_event_rail import (
JiuSwarmStreamEventRail,
+ _bind_skill_turbo_outer_todo_token,
+ _reset_skill_turbo_outer_todo_token,
+)
+from jiuwenswarm.agents.harness.common.rails.task_execution_rail import (
+ SKILL_TURBO_OUTER_TODO_ACTIVE_EXTRA_KEY,
+)
+from jiuwenswarm.server.runtime.skill_turbo.skill_turbo_tools import (
+ get_skill_turbo_outer_todo_active,
)
@@ -50,6 +58,23 @@ class _TestRail(JiuSwarmStreamEventRail):
await self._emit_context_usage(ctx)
[email protected]("active", [True, False])
+def test_outer_todo_display_ownership_rebinds_into_tool_context(
+ active: bool,
+) -> None:
+ ctx = SimpleNamespace(
+ extra={SKILL_TURBO_OUTER_TODO_ACTIVE_EXTRA_KEY: active}
+ )
+
+ _bind_skill_turbo_outer_todo_token(ctx)
+ try:
+ assert get_skill_turbo_outer_todo_active() is active
+ finally:
+ _reset_skill_turbo_outer_todo_token(ctx)
+
+ assert get_skill_turbo_outer_todo_active() is None
+
+
@pytest.mark.asyncio
async def test_empty_todo_list_is_emitted_to_clear_frontend():
rail = _TestRail()