Tailor agent system prompt to available tools#239
Merged
Conversation
`assembly live` told the model it could "search the web" in every session, but the Tavily search tool is only bound when a TAVILY_API_KEY is set. With no key, the model would narrate "I'll search for the latest news…" and then the turn would end with no result — the announced tool was never actually available to call, so the answer never came back. Build the live agent's system prompt from the tools actually resolved for the session: each capability clause (web search, URL fetch, docs lookup) is advertised only when a tool backing it is present, and with no tools at all the model is told to answer from its own knowledge and not promise an action it can't take. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01WvDSFotLTrHbtxeM9QaGWA
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix a bug where the agent would announce actions it couldn't perform, leaving conversations hanging with no answer. The system prompt now dynamically advertises only the capabilities backed by actually-present tools, and explicitly tells the model not to promise unavailable actions.
Changes
Dynamic tool guidance:
build_system_prompt()now accepts atoolsparameter and generates guidance tailored to the resolved tool set. Capabilities are only advertised if their backing tool is present (e.g., web search only ifTAVILY_API_KEYis set; docs tools only if the host is reachable).No-tools fallback: When no tools are available, the model is explicitly told to answer from its own knowledge and never promise to search, look things up, or fetch pages — preventing the bug where it would narrate "I'll search for that…" and then stall.
Helper functions:
_tool_capabilities(): Inspects resolved tools and returns the capabilities they support_join_clause(): Formats capability phrases with proper grammar (Oxford comma for 3+)Tool name exports: Added
WEB_SEARCH_TOOL_NAMEconstant toweb_search.pyso the prompt builder can reliably detect web-search availability by tool name, with a test pinning it against the actual registered name.Updated call site:
build_graph()now passes the resolved tools tobuild_system_prompt().Testing
Added comprehensive tests covering:
https://claude.ai/code/session_01WvDSFotLTrHbtxeM9QaGWA