Skip to content

Commit de67ddb

Browse files
committed
update V0.2.4
1 parent 9a1af1b commit de67ddb

4 files changed

Lines changed: 27 additions & 5 deletions

File tree

hello_agents/agents/react_agent.py

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,33 @@ def __init__(
8888
def add_tool(self, tool):
8989
"""
9090
添加工具到工具注册表
91+
支持MCP工具的自动展开
9192
9293
Args:
93-
tool: 工具实例
94+
tool: 工具实例(可以是普通Tool或MCPTool)
9495
"""
95-
self.tool_registry.register_tool(tool)
96+
# 检查是否是MCP工具
97+
if hasattr(tool, 'auto_expand') and tool.auto_expand:
98+
# MCP工具会自动展开为多个工具
99+
if hasattr(tool, '_available_tools') and tool._available_tools:
100+
for mcp_tool in tool._available_tools:
101+
# 创建包装工具
102+
from ..tools.base import Tool
103+
wrapped_tool = Tool(
104+
name=f"{tool.name}_{mcp_tool['name']}",
105+
description=mcp_tool.get('description', ''),
106+
func=lambda input_text, t=tool, tn=mcp_tool['name']: t.run({
107+
"action": "call_tool",
108+
"tool_name": tn,
109+
"arguments": {"input": input_text}
110+
})
111+
)
112+
self.tool_registry.register_tool(wrapped_tool)
113+
print(f"✅ MCP工具 '{tool.name}' 已展开为 {len(tool._available_tools)} 个独立工具")
114+
else:
115+
self.tool_registry.register_tool(tool)
116+
else:
117+
self.tool_registry.register_tool(tool)
96118

97119
def run(self, input_text: str, **kwargs) -> str:
98120
"""

hello_agents/agents/simple_agent.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ def remove_tool(self, tool_name: str) -> bool:
356356
def list_tools(self) -> list:
357357
"""列出所有可用工具"""
358358
if self.tool_registry:
359-
return list(self.tool_registry.tools.keys())
359+
return self.tool_registry.list_tools()
360360
return []
361361

362362
def has_tools(self) -> bool:

hello_agents/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"""版本信息"""
22

3-
__version__ = "0.2.3"
3+
__version__ = "0.2.4"
44
__author__ = "HelloAgents Team"
55
__email__ = "jjyaoao@126.com"
66
__description__ = "灵活、可扩展的多智能体框架 - 基于Datawhale Hello-Agents教程"

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
44

55
[project]
66
name = "hello-agents"
7-
version = "0.2.3"
7+
version = "0.2.4"
88
description = "灵活、可扩展的多智能体框架 - 基于OpenAI原生API"
99
readme = "README.md"
1010
license = {text = "CC-BY-NC-SA-4.0"}

0 commit comments

Comments
 (0)