| name | tool-manager |
| description | 管理 LLM 工具和内置指令的启停和列出操作 |
| version | 2.0.0 |
| author | AstrBot Community |
| requires_admin | true |
| requires_computer_use | true |
Tool Manager
管理 LLM 工具(FunctionTool)和内置指令(Command)。
使用场景
- "有哪些工具?" / "列出所有 LLM 工具"
- "禁用发邮件功能"
- "有哪些指令?" / "列出所有命令"
- "禁用 /debug 指令"
可用工具
1. 列出 LLM 工具
async def list_llm_tools(context):
try:
tools = context.get_llm_tool_manager().func_list
if not tools:
return "没有已注册的 LLM 工具。"
lines = ["🛠️ 已注册的 LLM 工具:\n"]
for tool in tools:
name = tool.name
desc = tool.description or "无描述"
active = getattr(tool, 'active', True)
status = "✅启用" if active else "❌禁用"
lines.append(f"- [{status}] **{name}**: {desc}")
return "\n".join(lines)
except Exception as e:
return f"❌ 列出工具失败:{e}"
event = globals().get('event')
if not event.is_admin():
print("❌ 错误:仅管理员可用")
import sys; sys.exit(1)
context = globals().get('context')
result = await list_llm_tools(context)
print(result)
2. 启用/禁用 LLM 工具
async def toggle_llm_tool(context, tool_name: str, enable: bool):
try:
tool_mgr = context.get_llm_tool_manager()
tool = tool_mgr.get_func(tool_name)
if not tool:
return f"❌ 工具「{tool_name}」不存在。"
tool.active = enable
action = "启用" if enable else "禁用"
return f"✅ 已{action}工具「{tool_name}」。"
except Exception as e:
return f"❌ 操作失败:{e}"
result = await toggle_llm_tool(context, tool_name="<工具名>", enable=False)
print(result)
3. 列出指令
async def list_commands(context):
try:
from astrbot.core.star.star_handler import CommandHandler
commands = CommandHandler.get_all_commands()
if not commands:
return "没有已注册的指令。"
lines = ["⚡ 已注册的指令:\n"]
for cmd in commands:
name = cmd.get("name", "")
desc = cmd.get("description", "无描述")
enabled = cmd.get("enabled", True)
status = "✅启用" if enabled else "❌禁用"
lines.append(f"- [{status}] **/{name}**: {desc}")
return "\n".join(lines)
except Exception as e:
return f"❌ 列出指令失败:{e}"
result = await list_commands(context)
print(result)
4. 启用/禁用指令
async def toggle_command(context, command_name: str, enable: bool):
try:
from astrbot.core.star.star_handler import CommandHandler
success = CommandHandler.set_command_enabled(command_name, enable)
if success:
action = "启用" if enable else "禁用"
return f"✅ 已{action}指令「/{command_name}」。"
else:
return f"❌ 指令「/{command_name}」不存在。"
except Exception as e:
return f"❌ 操作失败:{e}"
result = await toggle_command(context, command_name="<指令名>", enable=False)
print(result)
注意事项
- 禁用工具后,Agent 将无法调用该工具
- 禁用指令后,用户将无法使用该指令
- 核心工具和指令不建议禁用,可能影响系统功能