Skip to content

Commit bd0d204

Browse files
suluyanaluyan
andauthored
fix tool name exceed (#679)
Co-authored-by: luyan <suluyan.sly@aliabab-inc.com>
1 parent 0e4211f commit bd0d204

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

ms_agent/tools/tool_manager.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Copyright (c) Alibaba, Inc. and its affiliates.
22
import asyncio
3+
import os
34
from copy import copy
45
from typing import Any, Dict, List, Optional
56

@@ -10,6 +11,8 @@
1011
from ms_agent.tools.mcp_client import MCPClient
1112
from ms_agent.tools.split_task import SplitTask
1213

14+
MAX_TOOL_NAME_LEN = os.getenv('MAX_TOOL_NAME_LEN', 64)
15+
1316

1417
class ToolManager:
1518
"""Interacting with Agent class, hold all tools
@@ -45,7 +48,12 @@ async def reindex_tool(self):
4548
def extend_tool(tool_ins: ToolBase, server_name: str,
4649
tool_list: List[Tool]):
4750
for tool in tool_list:
48-
key = server_name + ':' + tool['tool_name']
51+
max_server_len = MAX_TOOL_NAME_LEN - len(
52+
tool['tool_name']) - 1 # 减去 ':' 的 1 个字符
53+
if len(server_name) > max_server_len:
54+
key = f"{server_name[:max_server_len]}:{tool['tool_name']}"
55+
else:
56+
key = f"{server_name}:{tool['tool_name']}"
4957
assert key not in self._tool_index, f'Tool name duplicated {tool["tool_name"]}'
5058
tool = copy(tool)
5159
tool['tool_name'] = key

0 commit comments

Comments
 (0)