Home / Function/ test_todo_middleware_custom_system_prompt_and_tool_description() — langchain Function Reference

test_todo_middleware_custom_system_prompt_and_tool_description() — langchain Function Reference

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

Entity Profile

Dependency Diagram

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

Relationship Graph

Source Code

libs/langchain_v1/tests/unit_tests/agents/middleware/implementations/test_todo.py lines 252–295

def test_todo_middleware_custom_system_prompt_and_tool_description() -> None:
    """Test that TodoListMiddleware can be initialized with both custom prompts."""
    custom_system_prompt = "Custom system prompt"
    custom_tool_description = "Custom tool description"
    middleware = TodoListMiddleware(
        system_prompt=custom_system_prompt,
        tool_description=custom_tool_description,
    )

    # Verify system prompt
    model = FakeToolCallingModel()
    state: PlanningState = {"messages": [HumanMessage(content="Hello")]}

    request = ModelRequest(
        model=model,
        system_prompt=None,
        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 == custom_system_prompt
    # Original request should be unchanged
    assert request.system_prompt is None

    # Verify tool description
    assert len(middleware.tools) == 1
    tool = middleware.tools[0]
    assert tool.description == custom_tool_description

Domain

Subdomains

Frequently Asked Questions

What does test_todo_middleware_custom_system_prompt_and_tool_description() do?
test_todo_middleware_custom_system_prompt_and_tool_description() 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_custom_system_prompt_and_tool_description() defined?
test_todo_middleware_custom_system_prompt_and_tool_description() is defined in libs/langchain_v1/tests/unit_tests/agents/middleware/implementations/test_todo.py at line 252.

Analyze Your Own Codebase

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

Try Supermodel Free