fix: get_tools() and get_system_prompt() now read from tool_registry too
Root cause: app.py registers tools via agent._tool_registry.register() which adds to the ToolRegistry but NOT to agent._tools (which is only populated by use_tool() from config). Both get_tools() and get_system_prompt() were reading only _tools, missing all post-init registered tools. Now both methods merge _tools with _tool_registry.list_tools().
This commit is contained in:
parent
f7225bc91a
commit
55421dd126
|
|
@ -397,8 +397,13 @@ class ConfigDrivenAgent(BaseAgent, EvolutionMixin):
|
|||
self.use_tool(retrieve_tool)
|
||||
|
||||
def get_tools(self) -> list[Tool]:
|
||||
"""Return registered tools for this agent."""
|
||||
return list(self._tools)
|
||||
"""Return registered tools for this agent (from config + post-init registration)."""
|
||||
all_tools = list(self._tools)
|
||||
if self._tool_registry:
|
||||
for tool in self._tool_registry.list_tools():
|
||||
if not any(t.name == tool.name for t in all_tools):
|
||||
all_tools.append(tool)
|
||||
return all_tools
|
||||
|
||||
def get_model(self) -> str:
|
||||
"""Return the LLM model name for this agent."""
|
||||
|
|
@ -416,16 +421,23 @@ class ConfigDrivenAgent(BaseAgent, EvolutionMixin):
|
|||
parts.append(val)
|
||||
|
||||
# Append available tools description so the LLM knows what it can use
|
||||
if self._tools:
|
||||
tools_desc = self._build_tools_description()
|
||||
# Use _tool_registry (which may have tools registered post-init) as well as _tools (from config)
|
||||
all_tools = list(self._tools)
|
||||
if self._tool_registry:
|
||||
for tool in self._tool_registry.list_tools():
|
||||
if not any(t.name == tool.name for t in all_tools):
|
||||
all_tools.append(tool)
|
||||
if all_tools:
|
||||
tools_desc = self._build_tools_description(all_tools)
|
||||
parts.append(f"\n\n## 可用工具\n{tools_desc}")
|
||||
|
||||
return "\n".join(parts) if parts else None
|
||||
|
||||
def _build_tools_description(self) -> str:
|
||||
def _build_tools_description(self, tools: list | None = None) -> str:
|
||||
"""Build a text description of available tools for the system prompt."""
|
||||
tools = tools or self._tools
|
||||
lines = []
|
||||
for tool in self._tools:
|
||||
for tool in tools:
|
||||
lines.append(f"- **{tool.name}**: {tool.description}")
|
||||
if tool.input_schema and "properties" in tool.input_schema:
|
||||
params = list(tool.input_schema["properties"].keys())
|
||||
|
|
|
|||
Loading…
Reference in New Issue