Home / Function/ test_todo_middleware_on_model_call() — langchain Function Reference

test_todo_middleware_on_model_call() — langchain Function Reference

Architecture documentation for the test_todo_middleware_on_model_call() function in test_todo.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  c6d17951_b7d2_9059_963f_911b0079a0d3["test_todo_middleware_on_model_call()"]
  d2f3bc2a_72aa_59d0_8558_330793eda010["test_todo.py"]
  c6d17951_b7d2_9059_963f_911b0079a0d3 -->|defined in| d2f3bc2a_72aa_59d0_8558_330793eda010
  style c6d17951_b7d2_9059_963f_911b0079a0d3 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain_v1/tests/unit_tests/agents/middleware/implementations/test_todo.py lines 136–171

def test_todo_middleware_on_model_call(
    original_prompt: str | None, expected_prompt_prefix: str
) -> None:
    """Test that wrap_model_call handles system prompts correctly."""
    middleware = TodoListMiddleware()
    model = FakeToolCallingModel()

    state: PlanningState = {"messages": [HumanMessage(content="Hello")]}

    request = ModelRequest(
        model=model,
        system_prompt=original_prompt,
        messages=[HumanMessage(content="Hello")],
        tool_choice=None,
        tools=[],
        response_format=None,
        state=state,
        runtime=cast("Runtime", object()),
        model_settings={},
    )

    captured_request = None

    def mock_handler(req: ModelRequest) -> ModelResponse:
        nonlocal captured_request
        captured_request = req
        return ModelResponse(result=[AIMessage(content="mock response")])

    # Call wrap_model_call to trigger the middleware logic
    middleware.wrap_model_call(request, mock_handler)
    # Check that the modified request passed to handler has the expected prompt
    assert captured_request is not None
    assert captured_request.system_prompt is not None
    assert captured_request.system_prompt.startswith(expected_prompt_prefix)
    # Original request should be unchanged
    assert request.system_prompt == original_prompt

Domain

Subdomains

Frequently Asked Questions

What does test_todo_middleware_on_model_call() do?
test_todo_middleware_on_model_call() is a function in the langchain codebase, defined in libs/langchain_v1/tests/unit_tests/agents/middleware/implementations/test_todo.py.
Where is test_todo_middleware_on_model_call() defined?
test_todo_middleware_on_model_call() is defined in libs/langchain_v1/tests/unit_tests/agents/middleware/implementations/test_todo.py at line 136.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free