from __future__ import annotations from collections.abc import Mapping from ..agent_tool_core import AgentTool, ToolHandler from ._builder import resolve_handler def build_execution_tools(handlers: Mapping[str, ToolHandler]) -> list[AgentTool]: """构建本地命令、Python 执行与短等待工具声明。""" return [ AgentTool( name='python_package', description=( '在当前用户独立 Python venv 中检查或安装 Python 包。' '用于 python_exec 缺少 pandas、pyarrow、openpyxl 等分析依赖时;' '不要通过 bash 执行 pip,也不要安装到项目 .venv。' ), parameters={ 'type': 'object', 'properties': { 'action': { 'type': 'string', 'enum': ['show', 'install'], 'description': 'show 查看当前 Python 环境和 pip;install 安装 packages。', }, 'packages': { 'type': 'array', 'items': {'type': 'string'}, 'description': '要安装的包名或 pip requirement spec,例如 pandas、pyarrow==15.0.0。', }, 'timeout_seconds': { 'type': 'number', 'minimum': 1, 'maximum': 600, 'description': '安装超时时间,默认 120 秒。', }, 'max_output_chars': { 'type': 'integer', 'minimum': 1000, 'maximum': 50000, }, }, 'required': ['action'], }, handler=resolve_handler(handlers, 'python_package', 'execution'), ), AgentTool( name='bash', description=( '运行真实 shell 命令,包括系统命令、进程控制、git 只读检查、用户已确认的依赖安装,' '以及所有 Python 脚本执行。' '执行 Python 时,把代码先写到 scratchpad 下的 .py 文件,' '再用本工具跑 `python3 -u