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(symphony): 技能编排补充HITL,追问确认执行
lin-xiaoyu2c3a2f8739f9
diff --git a/jiuwenswarm/extensions/symphony/extension.py b/jiuwenswarm/extensions/symphony/extension.pyindex 8d7fa7362e..67fac5e20d 100644--- a/jiuwenswarm/extensions/symphony/extension.py+++ b/jiuwenswarm/extensions/symphony/extension.py@@ -10,6 +10,7 @@ from datetime import datetime, timezonefrom pathlib import Pathfrom typing import Any+from jiuwenswarm.common.config import get_configfrom jiuwenswarm.extensions.sdk import BaseExtensionfrom jiuwenswarm.server.runtime.skill import load_execution_disabled_skillsfrom jiuwenswarm.symphony.llm import LLMConfig@@ -218,7 +219,10 @@ class SymphonyExtension(BaseExtension):"mode": orchestration_config.mode,**payload,}- presentation = _build_presentation(payload)+ preferred_language = str(+ get_config().get("preferred_language") or "zh"+ ).strip().lower()+ presentation = _build_presentation(payload, language=preferred_language)return {"success": True,"score_dir": str(score_dir),@@ -604,7 +608,11 @@ def _compact_details(details: dict[str, Any]) -> str:return rendered if len(rendered) <= 500 else rendered[:497] + "..."-def _build_presentation(payload: dict[str, Any]) -> dict[str, str]:+def _build_presentation(+ payload: dict[str, Any],+ *,+ language: str = "zh",+) -> dict[str, str]:plan = select_primary_plan(payload)title = str(plan.get("title") or "Symphony plan").strip()mermaid = _plan_to_mermaid(plan, payload.get("execution_graph") or {})@@ -618,6 +626,14 @@ def _build_presentation(payload: dict[str, Any]) -> dict[str, str]:reason = str(plan.get("reason") or payload.get("reason") or "").strip()if reason:lines.extend(["", reason])+ steps = plan.get("steps") if isinstance(plan, dict) else []+ if isinstance(steps, list) and steps:+ confirmation = (+ "Would you like to proceed with the orchestration plan above?"+ if language == "en"+ else "是否按照上述编排结果执行?"+ )+ lines.extend(["", confirmation])return {"markdown": "\n".join(lines), "mermaid": mermaid}diff --git a/tests/unit_tests/symphony/test_extension.py b/tests/unit_tests/symphony/test_extension.pyindex c74affcd39..83c2bfc0a5 100644--- a/tests/unit_tests/symphony/test_extension.py+++ b/tests/unit_tests/symphony/test_extension.py@@ -2,6 +2,8 @@ import asyncioimport jsonfrom pathlib import Path+import pytest+from jiuwenswarm.extensions.symphony.extension import (SYMPHONY_BUILD_SCORE,SYMPHONY_GRAPH,@@ -11,6 +13,7 @@ from jiuwenswarm.extensions.symphony.extension import (SymphonyExtension,_BuildProcessLogger,_build_log_payload,+ _build_presentation,_latest_effective_build_log_entry,)from jiuwenswarm.common.schema.agent import AgentRequest@@ -20,6 +23,14 @@ from jiuwenswarm.symphony.config import symphony_config_from_dictfrom jiuwenswarm.symphony.orchestration.artifacts import ScoreArtifacts[email protected](autouse=True)+def _use_chinese_preferred_language(monkeypatch):+ monkeypatch.setattr(+ "jiuwenswarm.extensions.symphony.extension.get_config",+ lambda: {"preferred_language": "zh"},+ )++class _Registry:def __init__(self):self.handlers = {}@@ -369,6 +380,7 @@ def test_plan_presentation_uses_recommended_plan(monkeypatch, tmp_path):assert "Status:" not in result["content"]assert result["result"]["recommended_plans"][0]["status"] == "ready"assert "Best match." in result["content"]+ assert result["content"].endswith("是否按照上述编排结果执行?")assert "Missing inputs:" not in result["content"]assert "收件邮箱地址" not in result["content"]assert "imap-smtp-email" not in result["content"]@@ -390,6 +402,49 @@ def test_plan_presentation_uses_recommended_plan(monkeypatch, tmp_path):assert "0.91" not in result["mermaid"]+def test_plan_presentation_does_not_ask_to_execute_empty_plan():+ presentation = _build_presentation(+ {+ "recommended_plans": [+ {"title": "Empty Plan", "status": "ready", "steps": []}+ ]+ }+ )++ assert "是否按照上述编排结果执行?" not in presentation["markdown"]+++def test_plan_presentation_asks_to_execute_in_english():+ presentation = _build_presentation(+ {+ "recommended_plans": [+ {+ "title": "Recommended Plan",+ "status": "ready",+ "steps": [{"skill_id": "skill-1"}],+ }+ ]+ },+ language="en",+ )++ assert presentation["markdown"].endswith(+ "Would you like to proceed with the orchestration plan above?"+ )+++def test_plan_presentation_does_not_ask_to_execute_no_plan():+ presentation = _build_presentation(+ {+ "recommended_plans": [+ {"title": "No Plan", "status": "no_plan", "steps": []}+ ]+ }+ )++ assert "是否按照上述编排结果执行?" not in presentation["markdown"]++def test_build_score_awaits_service_and_records_build_log(monkeypatch, tmp_path):configured_score_dir = tmp_path / "configured"skills_root = tmp_path / "skills"diff --git a/tests/unit_tests/symphony/test_toolkit.py b/tests/unit_tests/symphony/test_toolkit.pyindex 16d8242372..d59db93121 100644--- a/tests/unit_tests/symphony/test_toolkit.py+++ b/tests/unit_tests/symphony/test_toolkit.py@@ -401,7 +401,10 @@ def test_toolkit_plan_preserves_display_content_after_score_summary():lambda _params, request=None: {"success": True,"presentation": {- "markdown": "## Recommended Plan\n\nUse skill A, then skill B.",+ "markdown": (+ "## Recommended Plan\n\nUse skill A, then skill B.\n\n"+ "是否按照上述编排结果执行?"+ ),"mermaid": "flowchart LR\n A --> B",},},@@ -412,6 +415,7 @@ def test_toolkit_plan_preserves_display_content_after_score_summary():assert result["direct_display"] is Trueassert result["display_format"] == "markdown"assert result["content"].startswith("## Recommended Plan")+ assert result["content"].endswith("是否按照上述编排结果执行?")assert "## Symphony score" not in result["content"]assert "Detail: up to date" not in result["content"]assert result["mermaid"] == "flowchart LR\n A --> B"