test_tool_use() — langchain Function Reference
Architecture documentation for the test_tool_use() function in test_base.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 9bd936d6_46e3_c8fb_e419_bdd12c0ba2be["test_tool_use()"] bd382a4e_442c_13ae_530c_6e34bc43623d["test_base.py"] 9bd936d6_46e3_c8fb_e419_bdd12c0ba2be -->|defined in| bd382a4e_442c_13ae_530c_6e34bc43623d style 9bd936d6_46e3_c8fb_e419_bdd12c0ba2be fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/partners/openai/tests/integration_tests/chat_models/test_base.py lines 505–541
def test_tool_use() -> None:
llm = ChatOpenAI(model="gpt-5-nano", temperature=0)
llm_with_tool = llm.bind_tools(tools=[GenerateUsername], tool_choice=True)
msgs: list = [HumanMessage("Sally has green hair, what would her username be?")]
ai_msg = llm_with_tool.invoke(msgs)
assert isinstance(ai_msg, AIMessage)
assert isinstance(ai_msg.tool_calls, list)
assert len(ai_msg.tool_calls) == 1
tool_call = ai_msg.tool_calls[0]
assert "args" in tool_call
tool_msg = ToolMessage("sally_green_hair", tool_call_id=ai_msg.tool_calls[0]["id"])
msgs.extend([ai_msg, tool_msg])
llm_with_tool.invoke(msgs)
# Test streaming
ai_messages = llm_with_tool.stream(msgs)
first = True
for message in ai_messages:
if first:
gathered = message
first = False
else:
gathered = gathered + message # type: ignore
assert isinstance(gathered, AIMessageChunk)
assert isinstance(gathered.tool_call_chunks, list)
assert len(gathered.tool_call_chunks) == 1
tool_call_chunk = gathered.tool_call_chunks[0]
assert "args" in tool_call_chunk
assert gathered.content_blocks == gathered.tool_calls
streaming_tool_msg = ToolMessage(
"sally_green_hair", tool_call_id=gathered.tool_calls[0]["id"]
)
msgs.extend([gathered, streaming_tool_msg])
llm_with_tool.invoke(msgs)
Domain
Subdomains
Source
Frequently Asked Questions
What does test_tool_use() do?
test_tool_use() is a function in the langchain codebase, defined in libs/partners/openai/tests/integration_tests/chat_models/test_base.py.
Where is test_tool_use() defined?
test_tool_use() is defined in libs/partners/openai/tests/integration_tests/chat_models/test_base.py at line 505.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free