Home / Function/ test_run_limit_with_create_agent() — langchain Function Reference

test_run_limit_with_create_agent() — langchain Function Reference

Architecture documentation for the test_run_limit_with_create_agent() function in test_model_call_limit.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  d58e70b3_a571_564d_8818_4f23073d08f3["test_run_limit_with_create_agent()"]
  43d91b2d_3fa0_6f03_b3b8_f87c64a4f30a["test_model_call_limit.py"]
  d58e70b3_a571_564d_8818_4f23073d08f3 -->|defined in| 43d91b2d_3fa0_6f03_b3b8_f87c64a4f30a
  style d58e70b3_a571_564d_8818_4f23073d08f3 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain_v1/tests/unit_tests/agents/middleware/implementations/test_model_call_limit.py lines 110–141

def test_run_limit_with_create_agent() -> None:
    """Test that run limits work correctly with create_agent."""
    # Create a model that will make 2 calls
    model = FakeToolCallingModel(
        tool_calls=[
            [{"name": "simple_tool", "args": {"input": "test"}, "id": "1"}],
            [],  # No tool calls on second call
        ]
    )

    # Set run limit to 1 (should be exceeded after 1 call)
    agent = create_agent(
        model=model,
        tools=[simple_tool],
        middleware=[ModelCallLimitMiddleware(run_limit=1)],
        checkpointer=InMemorySaver(),
    )

    # This should hit the run limit after the first model call
    result = agent.invoke(
        {"messages": [HumanMessage("Hello")]}, {"configurable": {"thread_id": "thread1"}}
    )

    assert "messages" in result
    # The agent should have made 1 model call then jumped to end with limit exceeded message
    # So we should have: Human + AI + Tool + Limit exceeded AI message
    assert len(result["messages"]) == 4  # Human + AI + Tool + Limit AI
    assert isinstance(result["messages"][0], HumanMessage)
    assert isinstance(result["messages"][1], AIMessage)
    assert isinstance(result["messages"][2], ToolMessage)
    assert isinstance(result["messages"][3], AIMessage)  # Limit exceeded message
    assert "run limit" in result["messages"][3].content

Domain

Subdomains

Frequently Asked Questions

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

Analyze Your Own Codebase

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

Try Supermodel Free