Home / Function/ test_middleware_with_additional_tools() — langchain Function Reference

test_middleware_with_additional_tools() — langchain Function Reference

Architecture documentation for the test_middleware_with_additional_tools() function in test_tools.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  8cf92201_03b1_e967_c2c8_9506b2516e8a["test_middleware_with_additional_tools()"]
  5e05f5a6_3c9a_6b02_08a5_596bf1a6469a["test_tools.py"]
  8cf92201_03b1_e967_c2c8_9506b2516e8a -->|defined in| 5e05f5a6_3c9a_6b02_08a5_596bf1a6469a
  style 8cf92201_03b1_e967_c2c8_9506b2516e8a fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain_v1/tests/unit_tests/agents/middleware/core/test_tools.py lines 321–360

def test_middleware_with_additional_tools() -> None:
    """Test middleware that provides additional tools via tools attribute."""

    @tool
    def base_tool(value: str) -> str:
        """Base tool."""
        return "base"

    @tool
    def middleware_tool(value: str) -> str:
        """Tool provided by middleware."""
        return "middleware"

    class ToolProvidingMiddleware(AgentMiddleware):
        tools = (middleware_tool,)

    # Model calls the middleware-provided tool
    model = FakeToolCallingModel(
        tool_calls=[
            [{"args": {"value": "test"}, "id": "1", "name": "middleware_tool"}],
            [],
        ]
    )

    agent = create_agent(
        model=model,
        tools=[base_tool],
        system_prompt="You are a helpful assistant.",
        middleware=[ToolProvidingMiddleware()],
    )

    result = agent.invoke({"messages": [HumanMessage("Use middleware tool")]})

    # Verify that the middleware tool was executed
    messages = result["messages"]
    tool_messages = [m for m in messages if isinstance(m, ToolMessage)]
    assert len(tool_messages) == 1
    assert tool_messages[0].name == "middleware_tool"
    assert isinstance(tool_messages[0].content, str)
    assert "middleware" in tool_messages[0].content.lower()

Domain

Subdomains

Frequently Asked Questions

What does test_middleware_with_additional_tools() do?
test_middleware_with_additional_tools() is a function in the langchain codebase, defined in libs/langchain_v1/tests/unit_tests/agents/middleware/core/test_tools.py.
Where is test_middleware_with_additional_tools() defined?
test_middleware_with_additional_tools() is defined in libs/langchain_v1/tests/unit_tests/agents/middleware/core/test_tools.py at line 321.

Analyze Your Own Codebase

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

Try Supermodel Free