test_on_model_call_decorator() — langchain Function Reference
Architecture documentation for the test_on_model_call_decorator() function in test_decorators.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 4e2b5161_2b74_80d0_9675_529c6ffba955["test_on_model_call_decorator()"] 85a104a3_11cf_6539_d0c0_ba69a17a41d4["test_decorators.py"] 4e2b5161_2b74_80d0_9675_529c6ffba955 -->|defined in| 85a104a3_11cf_6539_d0c0_ba69a17a41d4 style 4e2b5161_2b74_80d0_9675_529c6ffba955 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/langchain_v1/tests/unit_tests/agents/middleware/core/test_decorators.py lines 98–133
def test_on_model_call_decorator() -> None:
"""Test wrap_model_call decorator with all configuration options."""
@wrap_model_call(state_schema=CustomState, tools=[test_tool], name="CustomOnModelCall")
def custom_on_model_call(
request: ModelRequest,
handler: Callable[[ModelRequest], ModelResponse],
) -> ModelCallResult:
return handler(request.override(system_message=SystemMessage(content="Modified")))
# Verify all options were applied
assert isinstance(custom_on_model_call, AgentMiddleware)
assert custom_on_model_call.state_schema == CustomState
assert custom_on_model_call.tools == [test_tool]
assert custom_on_model_call.__class__.__name__ == "CustomOnModelCall"
# Verify it works
original_request = ModelRequest(
model=FakeToolCallingModel(),
system_prompt="Original",
messages=[HumanMessage("Hello")],
tool_choice=None,
tools=[],
response_format=None,
state={"messages": [HumanMessage("Hello")]},
runtime=None,
)
def mock_handler(req: ModelRequest) -> ModelResponse:
return ModelResponse(
result=[AIMessage(content=f"Handled with prompt: {req.system_prompt}")]
)
result = custom_on_model_call.wrap_model_call(original_request, mock_handler)
assert isinstance(result, ModelResponse)
assert result.result[0].content == "Handled with prompt: Modified"
Domain
Subdomains
Source
Frequently Asked Questions
What does test_on_model_call_decorator() do?
test_on_model_call_decorator() is a function in the langchain codebase, defined in libs/langchain_v1/tests/unit_tests/agents/middleware/core/test_decorators.py.
Where is test_on_model_call_decorator() defined?
test_on_model_call_decorator() is defined in libs/langchain_v1/tests/unit_tests/agents/middleware/core/test_decorators.py at line 98.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free