fix(core): keep create_custom_toolset for embedding hosts
Projects that embed AIAgent and import toolsets.create_custom_toolset to give it an exact tool list import and run again instead of failing with ImportError. The shared-bot route-gate tests reach the gate through _live_adapter again, so a change that stops forwarding the target thread now fails them. The zh-Hans tools reference no longer shows an empty messaging toolset section.
This commit is contained in:
committed by
Siddharth Balyan
parent
c4635985a0
commit
a2c05c0dd7
@@ -76,6 +76,18 @@ def _tool(args):
|
||||
return json.loads(send_message_tool(args))
|
||||
|
||||
|
||||
def _live_adapter_allows(platform, profile, chat_id, thread_id):
|
||||
"""The gate as the choke point applies it: ``_live_adapter`` resolves the profile itself (the
|
||||
fixture's ``sec``) and must forward the target's thread."""
|
||||
from tools.send_message_senders import SharedBotTargetRefused, _live_adapter
|
||||
|
||||
assert profile == "sec"
|
||||
try:
|
||||
return _live_adapter(platform, chat_id, thread_id)[1] is not None
|
||||
except SharedBotTargetRefused:
|
||||
return False
|
||||
|
||||
|
||||
def test_send_to_unrouted_chat_never_uses_the_primary_bot(satellite):
|
||||
slack = satellite.primary[Platform.SLACK]
|
||||
result = _tool({"action": "send", "target": "slack:C0UNROUTED", "message": "hi"})
|
||||
@@ -136,7 +148,7 @@ def test_satellite_acts_in_its_inbound_routed_conversation_only(satellite, shape
|
||||
routes, origin = _ORIGIN_ROUTED[shape]
|
||||
platform = Platform(origin["platform"])
|
||||
satellite.runner.config.profile_routes = parse_profile_routes(routes)
|
||||
allowed = satellite.runner._shared_bot_target_allowed
|
||||
allowed = _live_adapter_allows
|
||||
tokens = set_session_vars(profile="sec", **origin)
|
||||
try:
|
||||
assert allowed(platform, "sec", origin["chat_id"], None) is True
|
||||
@@ -164,7 +176,7 @@ def test_origin_topic_does_not_vouch_for_the_rest_of_its_chat(satellite):
|
||||
|
||||
satellite.runner.config.profile_routes = parse_profile_routes([
|
||||
{"name": "t", "platform": "telegram", "chat_id": "-100222", "thread_id": "7", "profile": "sec"}])
|
||||
allowed = satellite.runner._shared_bot_target_allowed
|
||||
allowed = _live_adapter_allows
|
||||
tokens = set_session_vars(profile="sec", platform="telegram", chat_id="-100222", thread_id="7")
|
||||
try:
|
||||
assert allowed(Platform.TELEGRAM, "sec", "-100222", None) is False
|
||||
@@ -181,7 +193,7 @@ def test_shared_channel_origin_matches_on_the_turn_sender(satellite):
|
||||
|
||||
satellite.runner.config.profile_routes = parse_profile_routes([
|
||||
{"name": "u", "platform": "slack", "user_id": "U1", "profile": "sec"}])
|
||||
allowed = satellite.runner._shared_bot_target_allowed
|
||||
allowed = _live_adapter_allows
|
||||
tokens = set_session_vars(profile="sec", platform="slack", chat_id="C0SHARED", actor_id="U1")
|
||||
try:
|
||||
assert allowed(Platform.SLACK, "sec", "C0SHARED", None) is True
|
||||
|
||||
@@ -8,6 +8,7 @@ from toolsets import (
|
||||
resolve_toolset,
|
||||
get_all_toolsets,
|
||||
validate_toolset,
|
||||
create_custom_toolset,
|
||||
get_toolset_info,
|
||||
)
|
||||
|
||||
@@ -118,6 +119,22 @@ class TestGetToolsetInfo:
|
||||
assert info["is_composite"] is True
|
||||
assert info["tool_count"] > len(info["direct_tools"])
|
||||
|
||||
class TestCreateCustomToolset:
|
||||
def test_runtime_creation(self):
|
||||
create_custom_toolset(
|
||||
name="_test_custom",
|
||||
description="Test toolset",
|
||||
tools=["web_search"],
|
||||
includes=["terminal"],
|
||||
)
|
||||
try:
|
||||
tools = resolve_toolset("_test_custom")
|
||||
assert "web_search" in tools
|
||||
assert "terminal" in tools
|
||||
assert validate_toolset("_test_custom") is True
|
||||
finally:
|
||||
del TOOLSETS["_test_custom"]
|
||||
|
||||
class TestRegistryOwnedToolsets:
|
||||
def test_registry_membership_is_live(self, monkeypatch):
|
||||
reg = ToolRegistry()
|
||||
|
||||
@@ -235,8 +235,8 @@ TOOLSETS = {
|
||||
# Toolset -> the session platforms it exists for, from the specs that carry ``platforms``.
|
||||
TOOLSET_SESSION_PLATFORMS = {name: spec["platforms"] for name, spec in TOOLSETS.items() if "platforms" in spec}
|
||||
|
||||
# Built-in names only: shared metrics may export only these names, so a plugin, MCP server or custom
|
||||
# toolset name never leaves the machine.
|
||||
# Captured before create_custom_toolset() can add user-named tools: shared metrics may export only
|
||||
# these names, so a plugin, MCP server or custom toolset name never leaves the machine.
|
||||
BUILTIN_TOOL_NAMES = frozenset(tool for spec in TOOLSETS.values() for tool in spec["tools"])
|
||||
BUILTIN_TOOLSET_NAMES = frozenset(TOOLSETS)
|
||||
|
||||
@@ -488,6 +488,11 @@ def validate_toolset(name: str) -> bool:
|
||||
or name in _get_plugin_toolset_names() or name in _get_registry_toolset_aliases())
|
||||
|
||||
|
||||
def create_custom_toolset(name: str, description: str, tools: list[str] | None = None, includes: list[str] | None = None) -> None:
|
||||
"""Register a runtime toolset in TOOLSETS."""
|
||||
TOOLSETS[name] = _ts(description, tools or [], includes or [])
|
||||
|
||||
|
||||
def get_toolset_info(name: str) -> dict[str, Any]:
|
||||
"""Toolset definition plus its resolved tools, or None if unknown."""
|
||||
toolset = get_toolset(name)
|
||||
|
||||
@@ -119,11 +119,6 @@ description: "Hermes 内置工具权威参考,按工具集分组"
|
||||
|------|------|----------|
|
||||
| `memory` | 将重要信息保存到跨会话持久化的记忆中。你的记忆会在会话启动时出现在系统 prompt 中——这是你在对话之间记住用户信息和环境信息的方式。何时保存… | — |
|
||||
|
||||
## `messaging` 工具集
|
||||
|
||||
| 工具 | 描述 | 所需环境 |
|
||||
|------|------|----------|
|
||||
|
||||
## `session_search` 工具集
|
||||
|
||||
| 工具 | 描述 | 所需环境 |
|
||||
|
||||
Reference in New Issue
Block a user