Skip to content

Tailor agent system prompt to available tools#239

Merged
alexkroman merged 1 commit into
mainfrom
claude/amazing-thompson-47xcih
Jun 18, 2026
Merged

Tailor agent system prompt to available tools#239
alexkroman merged 1 commit into
mainfrom
claude/amazing-thompson-47xcih

Conversation

@alexkroman

Copy link
Copy Markdown
Collaborator

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 a tools parameter and generates guidance tailored to the resolved tool set. Capabilities are only advertised if their backing tool is present (e.g., web search only if TAVILY_API_KEY is 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_NAME constant to web_search.py so 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 to build_system_prompt().

Testing

Added comprehensive tests covering:

  • Prompt includes all capabilities when all tools are present
  • Web search is omitted from guidance when the search tool is absent
  • Model is told not to promise tools when none are available
  • Grammar of the capability-joining logic
  • Tool name constant matches the actual registered tool name

https://claude.ai/code/session_01WvDSFotLTrHbtxeM9QaGWA

`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
@alexkroman alexkroman enabled auto-merge June 18, 2026 04:59
@alexkroman alexkroman added this pull request to the merge queue Jun 18, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jun 18, 2026
@alexkroman alexkroman added this pull request to the merge queue Jun 18, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jun 18, 2026
@alexkroman alexkroman added this pull request to the merge queue Jun 18, 2026
Merged via the queue into main with commit 7281bf5 Jun 18, 2026
20 checks passed
@alexkroman alexkroman deleted the claude/amazing-thompson-47xcih branch June 18, 2026 05:44
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.

2 participants