test_custom_tool() — langchain Function Reference
Architecture documentation for the test_custom_tool() function in test_responses_api.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD f8c8e24c_0be5_421b_8fcd_51f858962089["test_custom_tool()"] 992496d5_b7d4_139f_00cf_3e585d851f81["test_responses_api.py"] f8c8e24c_0be5_421b_8fcd_51f858962089 -->|defined in| 992496d5_b7d4_139f_00cf_3e585d851f81 style f8c8e24c_0be5_421b_8fcd_51f858962089 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/partners/openai/tests/integration_tests/chat_models/test_responses_api.py lines 1084–1109
def test_custom_tool(output_version: Literal["responses/v1", "v1"]) -> None:
@custom_tool
def execute_code(code: str) -> str:
"""Execute python code."""
return "27"
llm = ChatOpenAI(model="gpt-5", output_version=output_version).bind_tools(
[execute_code]
)
input_message = {"role": "user", "content": "Use the tool to evaluate 3^3."}
tool_call_message = llm.invoke([input_message])
assert isinstance(tool_call_message, AIMessage)
assert len(tool_call_message.tool_calls) == 1
tool_call = tool_call_message.tool_calls[0]
tool_message = execute_code.invoke(tool_call)
response = llm.invoke([input_message, tool_call_message, tool_message])
assert isinstance(response, AIMessage)
# Test streaming
full: BaseMessageChunk | None = None
for chunk in llm.stream([input_message]):
assert isinstance(chunk, AIMessageChunk)
full = chunk if full is None else full + chunk
assert isinstance(full, AIMessageChunk)
assert len(full.tool_calls) == 1
Domain
Subdomains
Source
Frequently Asked Questions
What does test_custom_tool() do?
test_custom_tool() is a function in the langchain codebase, defined in libs/partners/openai/tests/integration_tests/chat_models/test_responses_api.py.
Where is test_custom_tool() defined?
test_custom_tool() is defined in libs/partners/openai/tests/integration_tests/chat_models/test_responses_api.py at line 1084.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free