fix: include available tools in system prompt so LLM knows what it can call

Previously get_system_prompt() only returned identity/instructions but
did not tell the LLM what tools are available. The LLM would therefore
refuse to call tools even when they were registered, saying it had no
tools. Now the system prompt includes a '## 可用工具' section listing
all registered tools with their descriptions and parameters.
This commit is contained in:
chiguyong 2026-06-11 22:00:30 +08:00
parent b6ec13cbca
commit f7225bc91a
1 changed files with 21 additions and 4 deletions

View File

@ -405,16 +405,33 @@ class ConfigDrivenAgent(BaseAgent, EvolutionMixin):
return self._config.llm.get("model", "default") if self._config.llm else "default"
def get_system_prompt(self) -> str | None:
"""Return the system prompt for this agent."""
"""Return the system prompt for this agent, including available tools."""
parts = []
if self._prompt_template:
sections = self._prompt_template._sections
parts = []
for key in ("identity", "context", "instructions", "constraints", "output_format"):
val = getattr(sections, key, "")
if val:
parts.append(val)
return "\n".join(parts) if parts else None
return None
# Append available tools description so the LLM knows what it can use
if self._tools:
tools_desc = self._build_tools_description()
parts.append(f"\n\n## 可用工具\n{tools_desc}")
return "\n".join(parts) if parts else None
def _build_tools_description(self) -> str:
"""Build a text description of available tools for the system prompt."""
lines = []
for tool in self._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())
if params:
lines[-1] += f" (参数: {', '.join(params)})"
return "\n".join(lines)
def get_react_config(self) -> dict:
"""Return ReAct engine configuration."""