Files
qing 5cb35945a4 feat(aibox): 后台进程池 v3.8——智能体运行/管理长驻进程与交互式 I/O
新增 ProcessManager 子系统 + 5 个 worker 执行面工具
(bg_run/bg_write/bg_list/bg_output/bg_kill),弥补 run_command
同步阻塞、超时即杀的不足;run_command 原路径零改动。

- 生命周期三决策:用户中断不影响后台进程;aibox 退出经 atexit
  收尾(非 detach 全杀,detach=true 豁免);注册表跨会话/跨子代理
  全局共享
- 交互式 I/O:stdin 管道 + watermark 写读对齐(bg_output(since=
  watermark) 必然且仅为本条输入的响应);wait_lines expect 式同步
  等待;写入 watchdog 线程兜底防管道写满阻塞
- 输出缓冲:每进程 256KB 环形缓冲(单行截断 16KB);log_file=true
  同步 tee 无界全档,可被原生工具 tail/cat 读取
- 三级优雅终止:关 stdin → SIGTERM 宽限 → SIGKILL 兜底
- 安全边界:运行上限 16/条目上限 32/单次写入 64KB;background_
  processes 配置节双闸;proc_name 规整规避 execute_tool 首参撞名
- 测试:test_process_manager.py 39 项(生命周期/游标续读/环形淘汰/
  watermark 对齐/EOF 优雅终止/log tee/工具分发),全量 532 passed
  / 4 failed(平台环境项,与基线一致)零回归
2026-08-21 11:17:11 +08:00

88 lines
2.4 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"""
tools - aibox 工具系统基础模块(包)
抽离自 aibox.py 的工具基类与注册器,供 aibox.py 及后续迁移的
工具子类导入。当前包含:
- base.py : Tool 抽象基类
- registry.py : ToolRegistry 工具注册器
- basic_tools.py : 基础工具集(A 批:文件/网页/时间/计算器,无外部子系统依赖)
- command_tool.py : CommandLineTool 命令行执行工具(B 批)
- skill_tools.py : 技能搜索/重载/安装/创建 4 个工具(B 批)
- db_tools.py : MemoryTool/MemoTool 数据库工具(B 批)
- prompt_tools.py : 身份/灵魂更新 + 结束对话 3 个工具(B 批)
- proxy_tools.py : SetProxy/GetProxy 代理工具(B 批)
- misc_tools.py : AskUserTool 询问工具(B 批)
形成单向依赖:common <- subsystems <- tools <- aibox。
采用"重导出"策略:外部统一用 `from tools import Tool, ToolRegistry`,
调用点无需关心具体子模块所在文件。
"""
from .base import Tool
from .registry import ToolRegistry
from .basic_tools import (
FileToolBase,
ReadFileTool,
WriteFileTool,
ListFilesTool,
SimpleWebCrawlerTool,
GetCurrentTimeTool,
CalculatorTool,
)
# B 批工具
from .command_tool import CommandLineTool
from .skill_tools import (
SearchSkillsTool,
ReloadSkillsTool,
InstallSkillTool,
CreateSkillTool,
)
from .db_tools import MemoryTool, MemoTool
from .prompt_tools import (
UpdateIdentityTool,
UpdateSoulTool,
SaveMemoryAndEndConversationTool,
)
from .proxy_tools import SetProxyTool, GetProxyTool
from .misc_tools import AskUserTool
from .process_tools import (
BgRunTool,
BgWriteTool,
BgListTool,
BgOutputTool,
BgKillTool,
)
__all__ = [
"Tool",
"ToolRegistry",
# A 批基础工具
"FileToolBase",
"ReadFileTool",
"WriteFileTool",
"ListFilesTool",
"SimpleWebCrawlerTool",
"GetCurrentTimeTool",
"CalculatorTool",
# B 批工具
"CommandLineTool",
"SearchSkillsTool",
"ReloadSkillsTool",
"InstallSkillTool",
"CreateSkillTool",
"MemoryTool",
"MemoTool",
"UpdateIdentityTool",
"UpdateSoulTool",
"SaveMemoryAndEndConversationTool",
"SetProxyTool",
"GetProxyTool",
"AskUserTool",
# 后台进程管理工具(bg_run/bg_write/bg_list/bg_output/bg_kill)
"BgRunTool",
"BgWriteTool",
"BgListTool",
"BgOutputTool",
"BgKillTool",
]