test_wrap_tool_call.py — langchain Source File
Architecture documentation for test_wrap_tool_call.py, a python file in the langchain codebase. 10 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR a40c5ce1_2a15_d390_039f_c7ee0bc16e5b["test_wrap_tool_call.py"] 0c1d9a1b_c553_0388_dbc1_58af49567aa2["time"] a40c5ce1_2a15_d390_039f_c7ee0bc16e5b --> 0c1d9a1b_c553_0388_dbc1_58af49567aa2 cfe2bde5_180e_e3b0_df2b_55b3ebaca8e7["collections.abc"] a40c5ce1_2a15_d390_039f_c7ee0bc16e5b --> cfe2bde5_180e_e3b0_df2b_55b3ebaca8e7 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3["typing"] a40c5ce1_2a15_d390_039f_c7ee0bc16e5b --> 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3 d758344f_537f_649e_f467_b9d7442e86df["langchain_core.messages"] a40c5ce1_2a15_d390_039f_c7ee0bc16e5b --> d758344f_537f_649e_f467_b9d7442e86df 43d88577_548b_2248_b01b_7987bae85dcc["langchain_core.tools"] a40c5ce1_2a15_d390_039f_c7ee0bc16e5b --> 43d88577_548b_2248_b01b_7987bae85dcc 1fe3d0c5_4963_3c08_63e9_108cefcdbab5["langgraph.checkpoint.memory"] a40c5ce1_2a15_d390_039f_c7ee0bc16e5b --> 1fe3d0c5_4963_3c08_63e9_108cefcdbab5 0e93d2ee_1fb2_3a0f_5a76_8aba32d0d4ed["langgraph.types"] a40c5ce1_2a15_d390_039f_c7ee0bc16e5b --> 0e93d2ee_1fb2_3a0f_5a76_8aba32d0d4ed 6f5e6c4b_1a3f_fd09_4697_631c27ef1033["langchain.agents.factory"] a40c5ce1_2a15_d390_039f_c7ee0bc16e5b --> 6f5e6c4b_1a3f_fd09_4697_631c27ef1033 50acc543_e5f0_2162_cf07_c2bf50723e0c["langchain.agents.middleware.types"] a40c5ce1_2a15_d390_039f_c7ee0bc16e5b --> 50acc543_e5f0_2162_cf07_c2bf50723e0c d135b586_15fc_7b4a_47fb_a8b2bcda78a5["tests.unit_tests.agents.model"] a40c5ce1_2a15_d390_039f_c7ee0bc16e5b --> d135b586_15fc_7b4a_47fb_a8b2bcda78a5 style a40c5ce1_2a15_d390_039f_c7ee0bc16e5b fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
"""Tests for wrap_tool_call decorator functionality.
These tests verify the decorator-based approach for wrapping tool calls,
focusing on the handler pattern (not generators).
"""
import time
from collections.abc import Callable
from typing import Any
from langchain_core.messages import HumanMessage, ToolCall, ToolMessage
from langchain_core.tools import BaseTool, tool
from langgraph.checkpoint.memory import InMemorySaver
from langgraph.types import Command
from langchain.agents.factory import create_agent
from langchain.agents.middleware.types import ToolCallRequest, wrap_tool_call
from tests.unit_tests.agents.model import FakeToolCallingModel
@tool
def search(query: str) -> str:
"""Search for information."""
return f"Results for: {query}"
@tool
def calculator(expression: str) -> str:
"""Calculate an expression."""
return f"Calculated: {expression}"
@tool
def failing_tool(value: str) -> str:
"""Tool that always fails."""
msg = f"Failed: {value}"
raise ValueError(msg)
def test_wrap_tool_call_basic_passthrough() -> None:
"""Test basic passthrough with wrap_tool_call decorator."""
call_log = []
@wrap_tool_call
def passthrough(
request: ToolCallRequest, handler: Callable[[ToolCallRequest], ToolMessage | Command[Any]]
) -> ToolMessage | Command[Any]:
call_log.append("called")
return handler(request)
model = FakeToolCallingModel(
tool_calls=[
[ToolCall(name="search", args={"query": "test"}, id="1")],
[],
]
)
agent = create_agent(
model=model,
tools=[search],
// ... (808 more lines)
Domain
Subdomains
Functions
- calculator()
- failing_tool()
- search()
- test_wrap_tool_call_access_runtime()
- test_wrap_tool_call_access_state()
- test_wrap_tool_call_basic_passthrough()
- test_wrap_tool_call_caching_pattern()
- test_wrap_tool_call_inner_short_circuits()
- test_wrap_tool_call_logging()
- test_wrap_tool_call_mixed_passthrough_and_intercepting()
- test_wrap_tool_call_modify_args()
- test_wrap_tool_call_monitoring_pattern()
- test_wrap_tool_call_multiple_middleware_composition()
- test_wrap_tool_call_multiple_tools()
- test_wrap_tool_call_outer_intercepts_inner()
- test_wrap_tool_call_response_modification()
- test_wrap_tool_call_retry_on_error()
- test_wrap_tool_call_short_circuit()
- test_wrap_tool_call_three_levels_composition()
- test_wrap_tool_call_uses_function_name_as_default()
- test_wrap_tool_call_with_custom_name()
- test_wrap_tool_call_with_tools_parameter()
Dependencies
- collections.abc
- langchain.agents.factory
- langchain.agents.middleware.types
- langchain_core.messages
- langchain_core.tools
- langgraph.checkpoint.memory
- langgraph.types
- tests.unit_tests.agents.model
- time
- typing
Source
Frequently Asked Questions
What does test_wrap_tool_call.py do?
test_wrap_tool_call.py is a source file in the langchain codebase, written in python. It belongs to the CoreAbstractions domain, RunnableInterface subdomain.
What functions are defined in test_wrap_tool_call.py?
test_wrap_tool_call.py defines 22 function(s): calculator, failing_tool, search, test_wrap_tool_call_access_runtime, test_wrap_tool_call_access_state, test_wrap_tool_call_basic_passthrough, test_wrap_tool_call_caching_pattern, test_wrap_tool_call_inner_short_circuits, test_wrap_tool_call_logging, test_wrap_tool_call_mixed_passthrough_and_intercepting, and 12 more.
What does test_wrap_tool_call.py depend on?
test_wrap_tool_call.py imports 10 module(s): collections.abc, langchain.agents.factory, langchain.agents.middleware.types, langchain_core.messages, langchain_core.tools, langgraph.checkpoint.memory, langgraph.types, tests.unit_tests.agents.model, and 2 more.
Where is test_wrap_tool_call.py in the architecture?
test_wrap_tool_call.py is located at libs/langchain_v1/tests/unit_tests/agents/middleware/core/test_wrap_tool_call.py (domain: CoreAbstractions, subdomain: RunnableInterface, directory: libs/langchain_v1/tests/unit_tests/agents/middleware/core).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free