test_human_in_the_loop.py — langchain Source File
Architecture documentation for test_human_in_the_loop.py, a python file in the langchain codebase. 9 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR b9ab5ab1_a37b_d0e1_974a_34ca8a76a788["test_human_in_the_loop.py"] b7996424_637b_0b54_6edf_2e18e9c1a8bf["re"] b9ab5ab1_a37b_d0e1_974a_34ca8a76a788 --> b7996424_637b_0b54_6edf_2e18e9c1a8bf feec1ec4_6917_867b_d228_b134d0ff8099["typing"] b9ab5ab1_a37b_d0e1_974a_34ca8a76a788 --> feec1ec4_6917_867b_d228_b134d0ff8099 23cb242e_1754_041d_200a_553fcb8abe1b["unittest.mock"] b9ab5ab1_a37b_d0e1_974a_34ca8a76a788 --> 23cb242e_1754_041d_200a_553fcb8abe1b f69d6389_263d_68a4_7fbf_f14c0602a9ba["pytest"] b9ab5ab1_a37b_d0e1_974a_34ca8a76a788 --> f69d6389_263d_68a4_7fbf_f14c0602a9ba 9444498b_8066_55c7_b3a2_1d90c4162a32["langchain_core.messages"] b9ab5ab1_a37b_d0e1_974a_34ca8a76a788 --> 9444498b_8066_55c7_b3a2_1d90c4162a32 e07f6d54_afcc_052d_d33f_8ccdcc46f752["langgraph.runtime"] b9ab5ab1_a37b_d0e1_974a_34ca8a76a788 --> e07f6d54_afcc_052d_d33f_8ccdcc46f752 598be07d_58e8_b830_8ebe_d631441aa2fe["langchain.agents.middleware"] b9ab5ab1_a37b_d0e1_974a_34ca8a76a788 --> 598be07d_58e8_b830_8ebe_d631441aa2fe 03c229df_84b8_879b_01ed_1058376cd6f6["langchain.agents.middleware.human_in_the_loop"] b9ab5ab1_a37b_d0e1_974a_34ca8a76a788 --> 03c229df_84b8_879b_01ed_1058376cd6f6 a681398d_ed44_c914_1a44_5d174223b069["langchain.agents.middleware.types"] b9ab5ab1_a37b_d0e1_974a_34ca8a76a788 --> a681398d_ed44_c914_1a44_5d174223b069 style b9ab5ab1_a37b_d0e1_974a_34ca8a76a788 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
import re
from typing import Any
from unittest.mock import patch
import pytest
from langchain_core.messages import AIMessage, HumanMessage, ToolCall, ToolMessage
from langgraph.runtime import Runtime
from langchain.agents.middleware import InterruptOnConfig
from langchain.agents.middleware.human_in_the_loop import (
Action,
HumanInTheLoopMiddleware,
)
from langchain.agents.middleware.types import AgentState
def test_human_in_the_loop_middleware_initialization() -> None:
"""Test HumanInTheLoopMiddleware initialization."""
middleware = HumanInTheLoopMiddleware(
interrupt_on={"test_tool": {"allowed_decisions": ["approve", "edit", "reject"]}},
description_prefix="Custom prefix",
)
assert middleware.interrupt_on == {
"test_tool": {"allowed_decisions": ["approve", "edit", "reject"]}
}
assert middleware.description_prefix == "Custom prefix"
def test_human_in_the_loop_middleware_no_interrupts_needed() -> None:
"""Test HumanInTheLoopMiddleware when no interrupts are needed."""
middleware = HumanInTheLoopMiddleware(
interrupt_on={"test_tool": {"allowed_decisions": ["approve", "edit", "reject"]}}
)
# Test with no messages
state = AgentState[Any](messages=[])
result = middleware.after_model(state, Runtime())
assert result is None
# Test with message but no tool calls
state = AgentState[Any](messages=[HumanMessage(content="Hello"), AIMessage(content="Hi there")])
result = middleware.after_model(state, Runtime())
assert result is None
# Test with tool calls that don't require interrupts
ai_message = AIMessage(
content="I'll help you",
tool_calls=[{"name": "other_tool", "args": {"input": "test"}, "id": "1"}],
)
state = AgentState[Any](messages=[HumanMessage(content="Hello"), ai_message])
result = middleware.after_model(state, Runtime())
assert result is None
def test_human_in_the_loop_middleware_single_tool_accept() -> None:
"""Test HumanInTheLoopMiddleware with single tool accept response."""
middleware = HumanInTheLoopMiddleware(
interrupt_on={"test_tool": {"allowed_decisions": ["approve", "edit", "reject"]}}
// ... (696 more lines)
Domain
Subdomains
Functions
- test_human_in_the_loop_middleware_boolean_configs()
- test_human_in_the_loop_middleware_description_as_callable()
- test_human_in_the_loop_middleware_disallowed_action()
- test_human_in_the_loop_middleware_edit_with_modified_args()
- test_human_in_the_loop_middleware_initialization()
- test_human_in_the_loop_middleware_interrupt_request_structure()
- test_human_in_the_loop_middleware_mixed_auto_approved_and_interrupt()
- test_human_in_the_loop_middleware_multiple_tools_edit_responses()
- test_human_in_the_loop_middleware_multiple_tools_mixed_responses()
- test_human_in_the_loop_middleware_no_interrupts_needed()
- test_human_in_the_loop_middleware_preserves_order_with_edits()
- test_human_in_the_loop_middleware_preserves_order_with_rejections()
- test_human_in_the_loop_middleware_preserves_tool_call_order()
- test_human_in_the_loop_middleware_sequence_mismatch()
- test_human_in_the_loop_middleware_single_tool_accept()
- test_human_in_the_loop_middleware_single_tool_edit()
- test_human_in_the_loop_middleware_single_tool_response()
- test_human_in_the_loop_middleware_unknown_response_type()
Dependencies
- langchain.agents.middleware
- langchain.agents.middleware.human_in_the_loop
- langchain.agents.middleware.types
- langchain_core.messages
- langgraph.runtime
- pytest
- re
- typing
- unittest.mock
Source
Frequently Asked Questions
What does test_human_in_the_loop.py do?
test_human_in_the_loop.py is a source file in the langchain codebase, written in python. It belongs to the LangChainCore domain, MessageInterface subdomain.
What functions are defined in test_human_in_the_loop.py?
test_human_in_the_loop.py defines 18 function(s): test_human_in_the_loop_middleware_boolean_configs, test_human_in_the_loop_middleware_description_as_callable, test_human_in_the_loop_middleware_disallowed_action, test_human_in_the_loop_middleware_edit_with_modified_args, test_human_in_the_loop_middleware_initialization, test_human_in_the_loop_middleware_interrupt_request_structure, test_human_in_the_loop_middleware_mixed_auto_approved_and_interrupt, test_human_in_the_loop_middleware_multiple_tools_edit_responses, test_human_in_the_loop_middleware_multiple_tools_mixed_responses, test_human_in_the_loop_middleware_no_interrupts_needed, and 8 more.
What does test_human_in_the_loop.py depend on?
test_human_in_the_loop.py imports 9 module(s): langchain.agents.middleware, langchain.agents.middleware.human_in_the_loop, langchain.agents.middleware.types, langchain_core.messages, langgraph.runtime, pytest, re, typing, and 1 more.
Where is test_human_in_the_loop.py in the architecture?
test_human_in_the_loop.py is located at libs/langchain_v1/tests/unit_tests/agents/middleware/implementations/test_human_in_the_loop.py (domain: LangChainCore, subdomain: MessageInterface, directory: libs/langchain_v1/tests/unit_tests/agents/middleware/implementations).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free