Skip to content

Commit c4dc8e3

Browse files
committed
feat: add OS information to tool descriptions and implement unit tests
1 parent 0dbe32e commit c4dc8e3

2 files changed

Lines changed: 22 additions & 2 deletions

File tree

astrbot/core/computer/tools/python.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import platform
12
from dataclasses import dataclass, field
23

34
import mcp
@@ -61,7 +62,9 @@ async def handle_result(result: dict, event: AstrMessageEvent) -> ToolExecResult
6162
@dataclass
6263
class PythonTool(FunctionTool):
6364
name: str = "astrbot_execute_ipython"
64-
description: str = "Run codes in an IPython shell."
65+
description: str = (
66+
f"Run codes in an IPython shell. Current OS: {platform.system()}."
67+
)
6568
parameters: dict = field(default_factory=lambda: param_schema)
6669

6770
async def call(
@@ -83,7 +86,7 @@ async def call(
8386
@dataclass
8487
class LocalPythonTool(FunctionTool):
8588
name: str = "astrbot_execute_python"
86-
description: str = "Execute codes in a Python environment."
89+
description: str = f"Execute codes in a Python environment. Current OS: {platform.system()}. Use system-compatible commands."
8790

8891
parameters: dict = field(default_factory=lambda: param_schema)
8992

tests/unit/test_python_tools.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import platform
2+
from astrbot.core.computer.tools.python import PythonTool, LocalPythonTool
3+
4+
def test_python_tool_description_contains_os():
5+
"""测试 PythonTool 的描述中是否包含当前操作系统信息"""
6+
tool = PythonTool()
7+
current_os = platform.system()
8+
assert current_os in tool.description
9+
assert "IPython" in tool.description
10+
11+
def test_local_python_tool_description_contains_os():
12+
"""测试 LocalPythonTool 的描述中是否包含当前操作系统信息和兼容性提示"""
13+
tool = LocalPythonTool()
14+
current_os = platform.system()
15+
assert current_os in tool.description
16+
assert "Python environment" in tool.description
17+
assert "system-compatible" in tool.description

0 commit comments

Comments
 (0)