test_programmatic_tool_use() — langchain Function Reference
Architecture documentation for the test_programmatic_tool_use() function in test_chat_models.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD f376a588_6c28_0ab4_8775_20c10dd30e1d["test_programmatic_tool_use()"] f27640dd_3870_5548_d153_f9504ae1021f["test_chat_models.py"] f376a588_6c28_0ab4_8775_20c10dd30e1d -->|defined in| f27640dd_3870_5548_d153_f9504ae1021f style f376a588_6c28_0ab4_8775_20c10dd30e1d fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/partners/anthropic/tests/integration_tests/test_chat_models.py lines 2153–2225
def test_programmatic_tool_use(output_version: str) -> None:
"""Test programmatic tool use.
Implicitly checks that `allowed_callers` in tool extras works.
"""
@tool(extras={"allowed_callers": ["code_execution_20250825"]})
def get_weather(location: str) -> str:
"""Get the weather at a location."""
return "It's sunny."
tools: list = [
{"type": "code_execution_20250825", "name": "code_execution"},
get_weather,
]
model = ChatAnthropic(
model="claude-sonnet-4-5",
betas=["advanced-tool-use-2025-11-20"],
reuse_last_container=True,
output_version=output_version,
)
agent = create_agent(model, tools=tools) # type: ignore[var-annotated]
input_query = {
"role": "user",
"content": "What's the weather in Boston?",
}
result = agent.invoke({"messages": [input_query]})
assert len(result["messages"]) == 4
tool_call_message = result["messages"][1]
response_message = result["messages"][-1]
if output_version == "v0":
server_tool_use_block = next(
block
for block in tool_call_message.content
if block["type"] == "server_tool_use"
)
assert server_tool_use_block
tool_use_block = next(
block for block in tool_call_message.content if block["type"] == "tool_use"
)
assert "caller" in tool_use_block
code_execution_result = next(
block
for block in response_message.content
if block["type"] == "code_execution_tool_result"
)
assert code_execution_result["content"]["return_code"] == 0
else:
server_tool_call_block = next(
block
for block in tool_call_message.content
if block["type"] == "server_tool_call"
)
assert server_tool_call_block
tool_call_block = next(
block for block in tool_call_message.content if block["type"] == "tool_call"
)
assert "caller" in tool_call_block["extras"]
server_tool_result = next(
block
for block in response_message.content
if block["type"] == "server_tool_result"
)
assert server_tool_result["output"]["return_code"] == 0
Domain
Subdomains
Source
Frequently Asked Questions
What does test_programmatic_tool_use() do?
test_programmatic_tool_use() is a function in the langchain codebase, defined in libs/partners/anthropic/tests/integration_tests/test_chat_models.py.
Where is test_programmatic_tool_use() defined?
test_programmatic_tool_use() is defined in libs/partners/anthropic/tests/integration_tests/test_chat_models.py at line 2153.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free