Skip to content

fix: SimpleAgent 示例中 tool_registry 初始化顺序修正#711

Open
Zi-Lan-Cui wants to merge 1 commit into
datawhalechina:mainfrom
Zi-Lan-Cui:fix-SimpleAgent-示例中-tool_registry-初始化顺序修正

Hidden character warning

The head ref may contain hidden characters: "fix-SimpleAgent-\u793a\u4f8b\u4e2d-tool_registry-\u521d\u59cb\u5316\u987a\u5e8f\u4fee\u6b63"
Open

fix: SimpleAgent 示例中 tool_registry 初始化顺序修正#711
Zi-Lan-Cui wants to merge 1 commit into
datawhalechina:mainfrom
Zi-Lan-Cui:fix-SimpleAgent-示例中-tool_registry-初始化顺序修正

Conversation

@Zi-Lan-Cui

Copy link
Copy Markdown

问题:SimpleAgent 初始化后外部赋 tool_registry 无效,Agent 不具备工具调用能力

示例代码如下:

llm = HelloAgentsLLM()

# 创建Agent
agent = SimpleAgent(
    name="智能助手",
    llm=llm,
    system_prompt="你是一个有记忆和知识检索能力的AI助手"
)

# 创建工具注册表
tool_registry = ToolRegistry()

# 添加记忆工具
memory_tool = MemoryTool(user_id="user123")
tool_registry.register_tool(memory_tool)

# 添加RAG工具
rag_tool = RAGTool(knowledge_base_path="./knowledge_base")
tool_registry.register_tool(rag_tool)

# 为Agent配置工具
agent.tool_registry = tool_registry

因为Simple_Agent初始化时,enable_tool_calling是立刻确定的:

class SimpleAgent(Agent):
    """简单的对话Agent,支持可选的工具调用"""
    
    def __init__(
        self,
        name: str,
        llm: HelloAgentsLLM,
        system_prompt: Optional[str] = None,
        config: Optional[Config] = None,
        tool_registry: Optional['ToolRegistry'] = None,
        enable_tool_calling: bool = True
    ):
        super().__init__(name, llm, system_prompt, config)
        self.tool_registry = tool_registry
        self.enable_tool_calling = enable_tool_calling and tool_registry is not None

所以后续追加tool_registry并不能使模型拥有调用工具的能力,enable_tool_calling 仍为 False

Refactor agent creation to include tool registry.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant