diff --git a/backend_service/generated_visualizations/py_tree.png b/backend_service/generated_visualizations/py_tree.png index 4fe48a78..16912948 100644 Binary files a/backend_service/generated_visualizations/py_tree.png and b/backend_service/generated_visualizations/py_tree.png differ diff --git a/backend_service/src/__pycache__/__init__.cpython-310.pyc b/backend_service/src/__pycache__/__init__.cpython-310.pyc index 121bfb57..375d60dc 100644 Binary files a/backend_service/src/__pycache__/__init__.cpython-310.pyc and b/backend_service/src/__pycache__/__init__.cpython-310.pyc differ diff --git a/backend_service/src/__pycache__/main.cpython-310.pyc b/backend_service/src/__pycache__/main.cpython-310.pyc index 8867623a..d5e63a1b 100644 Binary files a/backend_service/src/__pycache__/main.cpython-310.pyc and b/backend_service/src/__pycache__/main.cpython-310.pyc differ diff --git a/backend_service/src/__pycache__/models.cpython-310.pyc b/backend_service/src/__pycache__/models.cpython-310.pyc index 5f7b5e7f..6e5f2e16 100644 Binary files a/backend_service/src/__pycache__/models.cpython-310.pyc and b/backend_service/src/__pycache__/models.cpython-310.pyc differ diff --git a/backend_service/src/__pycache__/py_tree_generator.cpython-310.pyc b/backend_service/src/__pycache__/py_tree_generator.cpython-310.pyc index c20c4daf..96dc69bc 100644 Binary files a/backend_service/src/__pycache__/py_tree_generator.cpython-310.pyc and b/backend_service/src/__pycache__/py_tree_generator.cpython-310.pyc differ diff --git a/backend_service/src/__pycache__/ros2_client.cpython-310.pyc b/backend_service/src/__pycache__/ros2_client.cpython-310.pyc index b7324418..80211e60 100644 Binary files a/backend_service/src/__pycache__/ros2_client.cpython-310.pyc and b/backend_service/src/__pycache__/ros2_client.cpython-310.pyc differ diff --git a/backend_service/src/__pycache__/websocket_manager.cpython-310.pyc b/backend_service/src/__pycache__/websocket_manager.cpython-310.pyc index 27239cc6..e9fbc8ca 100644 Binary files a/backend_service/src/__pycache__/websocket_manager.cpython-310.pyc and b/backend_service/src/__pycache__/websocket_manager.cpython-310.pyc differ diff --git a/backend_service/src/prompts/simple_mode_prompt.txt b/backend_service/src/prompts/simple_mode_prompt.txt index 404ebeaf..a5c20bcd 100644 --- a/backend_service/src/prompts/simple_mode_prompt.txt +++ b/backend_service/src/prompts/simple_mode_prompt.txt @@ -3,14 +3,14 @@ 输出要求(必须遵守): - 只输出一个JSON对象,不要任何解释或多余文本。 - JSON结构: -{"mode":"simple","action":{"name":"","params":{...}}} +{"root":{"type":"action","name":"","params":{...}}} - 与参数定义、取值范围,必须与“复杂模式”提示词(system_prompt.txt)中的定义完全一致。 -- 简单模式下不包含任何行为树结构与安全监控并行,仅输出单一原子动作。 +- 简单模式下root节点必须是action类型节点,不能是控制流节点。 示例: -- “起飞到10米” → {"mode":"simple","action":{"name":"takeoff","params":{"altitude":10.0}}} -- “移动到(120,80,20)” → {"mode":"simple","action":{"name":"fly_to_waypoint","params":{"x":120.0,"y":80.0,"z":20.0,"acceptance_radius":2.0}}} -- “飞机自检” → {"mode":"simple","action":{"name":"preflight_checks","params":{"check_level":"comprehensive"}}} +- “起飞到10米” → {"root":{"type":"action","name":"takeoff","params":{"altitude":10.0}}} +- “移动到(120,80,20)” → {"root":{"type":"action","name":"fly_to_waypoint","params":{"x":120.0,"y":80.0,"z":20.0,"acceptance_radius":2.0}}} +- “飞机自检” → {"root":{"type":"action","name":"preflight_checks","params":{"check_level":"comprehensive"}}} —— 可用节点定义—— ```json diff --git a/backend_service/src/py_tree_generator.py b/backend_service/src/py_tree_generator.py index 263121db..ab39f45a 100644 --- a/backend_service/src/py_tree_generator.py +++ b/backend_service/src/py_tree_generator.py @@ -337,28 +337,35 @@ def _generate_pytree_schema(allowed_actions: set, allowed_conditions: set) -> di def _generate_simple_mode_schema(allowed_actions: set) -> dict: """ - 生成简单模式JSON Schema:{"mode":"simple","action":{...}} + 生成简单模式JSON Schema:{"root":{"type":"action","name":"","params":{...}}} 仅校验动作名称在允许集合内,以及基本结构完整性;参数按对象形状放宽,由上游提示词与运行时再约束。 """ + # 使用复杂模式Schema中的node定义,但限制root节点必须是action类型 + node_definition = { + "type": "object", + "properties": { + "type": {"type": "string", "const": "action"}, + "name": {"type": "string", "enum": sorted(list(allowed_actions))}, + "params": {"type": "object"} + }, + "required": ["type", "name"], + "additionalProperties": False + } + schema = { "$schema": "http://json-schema.org/draft-07/schema#", "title": "SimpleMode", + "definitions": { + "node": node_definition + }, "type": "object", "properties": { - "mode": {"type": "string", "const": "simple"}, - "action": { - "type": "object", - "properties": { - "name": {"type": "string", "enum": sorted(list(allowed_actions))}, - "params": {"type": "object"} - }, - "required": ["name"], - "additionalProperties": True - } + "root": { "$ref": "#/definitions/node" } }, - "required": ["mode", "action"], + "required": ["root"], "additionalProperties": False } + return schema def _validate_pytree_with_schema(pytree_instance: dict, schema: dict) -> bool: @@ -689,16 +696,11 @@ class PyTreeGenerator: # 附加元信息并生成简单可视化(单动作) plan_id = str(uuid.uuid4()) pytree_dict['plan_id'] = plan_id - # 简单模式可视化:构造一个简化节点图 + # 简单模式可视化:直接使用root节点 try: vis_filename = "py_tree.png" vis_path = os.path.join(self.vis_dir, vis_filename) - simple_node = { - "type": "action", - "name": pytree_dict.get('action', {}).get('name', 'action'), - "params": pytree_dict.get('action', {}).get('params', {}) - } - _visualize_pytree(simple_node, os.path.splitext(vis_path)[0]) + _visualize_pytree(pytree_dict['root'], os.path.splitext(vis_path)[0]) pytree_dict['visualization_url'] = f"/static/{vis_filename}" except Exception as e: logging.warning(f"简单模式可视化失败: {e}") diff --git a/install/drone_interfaces/lib/python3.10/site-packages/drone_interfaces/__pycache__/__init__.cpython-310.pyc b/install/drone_interfaces/lib/python3.10/site-packages/drone_interfaces/__pycache__/__init__.cpython-310.pyc index 2c29da89..28ba6e11 100644 Binary files a/install/drone_interfaces/lib/python3.10/site-packages/drone_interfaces/__pycache__/__init__.cpython-310.pyc and b/install/drone_interfaces/lib/python3.10/site-packages/drone_interfaces/__pycache__/__init__.cpython-310.pyc differ diff --git a/install/drone_interfaces/lib/python3.10/site-packages/drone_interfaces/action/__pycache__/__init__.cpython-310.pyc b/install/drone_interfaces/lib/python3.10/site-packages/drone_interfaces/action/__pycache__/__init__.cpython-310.pyc index 728e2f1a..01a63273 100644 Binary files a/install/drone_interfaces/lib/python3.10/site-packages/drone_interfaces/action/__pycache__/__init__.cpython-310.pyc and b/install/drone_interfaces/lib/python3.10/site-packages/drone_interfaces/action/__pycache__/__init__.cpython-310.pyc differ diff --git a/install/drone_interfaces/lib/python3.10/site-packages/drone_interfaces/action/__pycache__/_execute_mission.cpython-310.pyc b/install/drone_interfaces/lib/python3.10/site-packages/drone_interfaces/action/__pycache__/_execute_mission.cpython-310.pyc index 7590d494..7e980350 100644 Binary files a/install/drone_interfaces/lib/python3.10/site-packages/drone_interfaces/action/__pycache__/_execute_mission.cpython-310.pyc and b/install/drone_interfaces/lib/python3.10/site-packages/drone_interfaces/action/__pycache__/_execute_mission.cpython-310.pyc differ diff --git a/tools/vector_store/chroma.sqlite3 b/tools/vector_store/chroma.sqlite3 index b414c88e..84e50c59 100644 Binary files a/tools/vector_store/chroma.sqlite3 and b/tools/vector_store/chroma.sqlite3 differ