Home / Function/ test_injected_state_in_middleware_agent() — langchain Function Reference

test_injected_state_in_middleware_agent() — langchain Function Reference

Architecture documentation for the test_injected_state_in_middleware_agent() function in test_framework.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  95aa68d5_1d5c_12c0_e966_2ffe2ff71a88["test_injected_state_in_middleware_agent()"]
  8310d669_2524_e019_e333_8473b50a4990["test_framework.py"]
  95aa68d5_1d5c_12c0_e966_2ffe2ff71a88 -->|defined in| 8310d669_2524_e019_e333_8473b50a4990
  style 95aa68d5_1d5c_12c0_e966_2ffe2ff71a88 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain_v1/tests/unit_tests/agents/middleware/core/test_framework.py lines 444–463

def test_injected_state_in_middleware_agent() -> None:
    """Test that custom state is properly injected into tools when using middleware."""
    result = agent.invoke(
        {
            "custom_state": "I love pizza",
            "messages": [HumanMessage("Call the test state tool")],
        }
    )

    messages = result["messages"]
    assert len(messages) == 4  # Human message, AI message with tool call, tool message, AI message

    # Find the tool message
    tool_messages = [msg for msg in messages if isinstance(msg, ToolMessage)]
    assert len(tool_messages) == 1

    tool_message = tool_messages[0]
    assert tool_message.name == "test_state_tool"
    assert "success" in tool_message.content
    assert tool_message.tool_call_id == "test_call_1"

Domain

Subdomains

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free