fix(anthropic): add advisor_ prefix to builtin tool recognition (#38686)

This commit is contained in:
Radhakrishnan Pachyappan
2026-07-10 07:48:52 +05:30
committed by GitHub
parent 8107ff4065
commit a07356f839
2 changed files with 28 additions and 0 deletions

View File

@@ -161,6 +161,7 @@ _BUILTIN_TOOL_PREFIXES = [
"mcp_toolset",
"memory_",
"tool_search_",
"advisor_",
]
_ANTHROPIC_EXTRA_FIELDS: set[str] = {

View File

@@ -2575,6 +2575,33 @@ def test_tool_search_is_builtin_tool() -> None:
assert not _is_builtin_tool(regular_tool)
def test_advisor_is_builtin_tool() -> None:
"""Test that advisor_ tools are recognized as built-in and pass through bind_tools.
Regression test for https://github.com/langchain-ai/langchain/issues/38644.
advisor_20260301 (Anthropic Advisor native tool) was missing from
_BUILTIN_TOOL_PREFIXES, causing bind_tools() to route it through
convert_to_anthropic_tool() which crashed with KeyError: 'parameters'.
"""
advisor_tool = {
"type": "advisor_20260301",
"name": "advisor",
"model": MODEL_NAME,
"max_uses": 3,
"max_tokens": 1024,
}
assert _is_builtin_tool(advisor_tool)
# bind_tools() must pass the advisor tool through unchanged, not raise KeyError
model = ChatAnthropic(model=MODEL_NAME) # type: ignore[call-arg]
bound = model.bind_tools([advisor_tool])
payload = bound._get_request_payload( # type: ignore[attr-defined]
[HumanMessage("hello")],
**bound.kwargs, # type: ignore[attr-defined]
)
assert advisor_tool in payload["tools"]
def test_tool_search_beta_headers() -> None:
"""Test that tool search tools auto-append the correct beta headers."""
# Test regex variant