mirror of
https://github.com/langbot-app/LangBot.git
synced 2026-06-23 14:04:19 +00:00
refactor(tools): unify tool-detail normalization in ToolManager
Drop the PluginToolLoader.get_tool() override that returned a raw
ComponentManifest, so every loader's get_tool() now returns a uniform
resource_tool.LLMTool (PluginToolLoader.get_tools() already did this
conversion). This removes the only source of tool-shape heterogeneity.
- ToolManager.get_tool_schema(): drop the ComponentManifest-vs-LLMTool branch
- ToolManager.get_tool_detail(): new host-level shape {name, description,
human_desc, parameters}
- handler.py GET_TOOL_DETAIL: call tool_mgr.get_tool_detail(); delete the
handler-local _build_tool_detail + _i18n_to_dict/_i18n_to_text adapters and
the litellm TODO
- ToolLookupResult is now just LLMTool
The dropped label/spec fields were not consumed by any runner (local-agent
build_llm_tool and external harnesses use only name/description/parameters).
This commit is contained in:
@@ -14,12 +14,11 @@ Authorization paths:
|
||||
from __future__ import annotations
|
||||
|
||||
import pytest
|
||||
import types
|
||||
from unittest.mock import AsyncMock, MagicMock
|
||||
|
||||
from langbot.pkg.agent.runner.descriptor import AgentRunnerDescriptor
|
||||
from langbot.pkg.agent.runner.session_registry import AgentRunSessionRegistry
|
||||
from langbot.pkg.plugin.handler import _build_tool_detail, _get_pipeline_knowledge_base_uuids
|
||||
from langbot.pkg.plugin.handler import _get_pipeline_knowledge_base_uuids
|
||||
|
||||
# Import shared test fixtures from conftest.py
|
||||
from .conftest import make_resources, make_session
|
||||
@@ -287,31 +286,39 @@ class TestInvokeLLMStreamAuthorization:
|
||||
assert run_id is None
|
||||
|
||||
|
||||
def test_build_tool_detail_normalizes_plugin_component_manifest():
|
||||
"""GET_TOOL_DETAIL returns a uniform schema for ordinary plugin Tool manifests."""
|
||||
manifest_tool = types.SimpleNamespace(
|
||||
metadata=types.SimpleNamespace(
|
||||
name='search',
|
||||
label={'en_US': 'Search'},
|
||||
description={'en_US': 'Search public data'},
|
||||
),
|
||||
spec={
|
||||
'llm_prompt': 'Search test data',
|
||||
'parameters': {
|
||||
'type': 'object',
|
||||
'properties': {'q': {'type': 'string'}},
|
||||
},
|
||||
},
|
||||
@pytest.mark.asyncio
|
||||
async def test_tool_manager_get_tool_detail_returns_uniform_schema():
|
||||
"""ToolManager.get_tool_detail returns a uniform host-level tool detail shape.
|
||||
|
||||
All loaders normalize to resource_tool.LLMTool, so GET_TOOL_DETAIL no longer
|
||||
needs a handler-local adapter for plugin ComponentManifest objects.
|
||||
"""
|
||||
import langbot_plugin.api.entities.builtin.resource.tool as resource_tool
|
||||
from langbot.pkg.provider.tools.toolmgr import ToolManager
|
||||
|
||||
tool = resource_tool.LLMTool(
|
||||
name='search',
|
||||
human_desc='Search public data',
|
||||
description='Search test data',
|
||||
parameters={'type': 'object', 'properties': {'q': {'type': 'string'}}},
|
||||
func=lambda **kwargs: {},
|
||||
)
|
||||
|
||||
detail = _build_tool_detail(manifest_tool, requested_tool_name='author/plugin/search')
|
||||
mgr = ToolManager.__new__(ToolManager)
|
||||
|
||||
assert detail['name'] == 'author/plugin/search'
|
||||
assert detail['description'] == 'Search test data'
|
||||
assert detail['human_desc'] == 'Search test data'
|
||||
assert detail['parameters']['properties']['q']['type'] == 'string'
|
||||
assert detail['label'] == {'en_US': 'Search'}
|
||||
assert detail['spec'] == manifest_tool.spec
|
||||
async def fake_get_tool_by_name(name):
|
||||
return tool if name == 'search' else None
|
||||
|
||||
mgr.get_tool_by_name = fake_get_tool_by_name
|
||||
|
||||
detail = await mgr.get_tool_detail('search')
|
||||
assert detail == {
|
||||
'name': 'search',
|
||||
'description': 'Search test data',
|
||||
'human_desc': 'Search public data',
|
||||
'parameters': {'type': 'object', 'properties': {'q': {'type': 'string'}}},
|
||||
}
|
||||
assert await mgr.get_tool_detail('missing') is None
|
||||
|
||||
|
||||
class TestCallToolAuthorization:
|
||||
@@ -1510,7 +1517,6 @@ class TestStorageResourcePermissionHelper:
|
||||
assert registry.is_resource_allowed(session, 'storage', 'workspace') is False
|
||||
|
||||
|
||||
|
||||
class TestRealActionHandlerSimulation:
|
||||
"""Tests that simulate real RuntimeConnectionHandler action registration and execution.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user