test_wrap_model_call_state_update.py — langchain Source File
Architecture documentation for test_wrap_model_call_state_update.py, a python file in the langchain codebase. 8 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 08361e76_a995_1e57_f200_e292474e2f00["test_wrap_model_call_state_update.py"] 2bf6d401_816d_d011_3b05_a6114f55ff58["collections.abc"] 08361e76_a995_1e57_f200_e292474e2f00 --> 2bf6d401_816d_d011_3b05_a6114f55ff58 f69d6389_263d_68a4_7fbf_f14c0602a9ba["pytest"] 08361e76_a995_1e57_f200_e292474e2f00 --> f69d6389_263d_68a4_7fbf_f14c0602a9ba 00fc047e_6208_0289_ebf0_f5b91b72ee90["langchain_core.language_models.fake_chat_models"] 08361e76_a995_1e57_f200_e292474e2f00 --> 00fc047e_6208_0289_ebf0_f5b91b72ee90 9444498b_8066_55c7_b3a2_1d90c4162a32["langchain_core.messages"] 08361e76_a995_1e57_f200_e292474e2f00 --> 9444498b_8066_55c7_b3a2_1d90c4162a32 0d9bee28_60c3_678e_4f8f_88a0911c2a47["langgraph.errors"] 08361e76_a995_1e57_f200_e292474e2f00 --> 0d9bee28_60c3_678e_4f8f_88a0911c2a47 726d73c8_7999_511a_c1ec_4524fb1cc31a["langgraph.types"] 08361e76_a995_1e57_f200_e292474e2f00 --> 726d73c8_7999_511a_c1ec_4524fb1cc31a d9a6942a_c37a_07f8_ed13_74d0fdc117be["langchain.agents"] 08361e76_a995_1e57_f200_e292474e2f00 --> d9a6942a_c37a_07f8_ed13_74d0fdc117be a681398d_ed44_c914_1a44_5d174223b069["langchain.agents.middleware.types"] 08361e76_a995_1e57_f200_e292474e2f00 --> a681398d_ed44_c914_1a44_5d174223b069 style 08361e76_a995_1e57_f200_e292474e2f00 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
"""Unit tests for ExtendedModelResponse command support in wrap_model_call.
Tests that wrap_model_call middleware can return ExtendedModelResponse to provide
a Command alongside the model response. Commands are applied as separate state
updates through graph reducers (e.g. add_messages for messages).
"""
from collections.abc import Awaitable, Callable
import pytest
from langchain_core.language_models.fake_chat_models import GenericFakeChatModel
from langchain_core.messages import AIMessage, HumanMessage
from langgraph.errors import InvalidUpdateError
from langgraph.types import Command
from langchain.agents import AgentState, create_agent
from langchain.agents.middleware.types import (
AgentMiddleware,
ExtendedModelResponse,
ModelRequest,
ModelResponse,
wrap_model_call,
)
class TestBasicCommand:
"""Test basic ExtendedModelResponse functionality with Command."""
def test_command_messages_added_alongside_model_messages(self) -> None:
"""Command messages are added alongside model response messages (additive)."""
class AddMessagesMiddleware(AgentMiddleware):
def wrap_model_call(
self,
request: ModelRequest,
handler: Callable[[ModelRequest], ModelResponse],
) -> ExtendedModelResponse:
response = handler(request)
custom_msg = HumanMessage(content="Custom message", id="custom")
return ExtendedModelResponse(
model_response=response,
command=Command(update={"messages": [custom_msg]}),
)
model = GenericFakeChatModel(messages=iter([AIMessage(content="Hello!")]))
agent = create_agent(model=model, middleware=[AddMessagesMiddleware()])
result = agent.invoke({"messages": [HumanMessage(content="Hi")]})
# Both model response AND command messages appear (additive via add_messages)
messages = result["messages"]
assert len(messages) == 3
assert messages[0].content == "Hi"
assert messages[1].content == "Hello!"
assert messages[2].content == "Custom message"
def test_command_with_extra_messages_and_model_response(self) -> None:
"""Middleware can add extra messages via command alongside model messages."""
class ExtraMessagesMiddleware(AgentMiddleware):
// ... (858 more lines)
Domain
Subdomains
Classes
- AddMessagesMiddleware
- AsyncAddMiddleware
- AsyncGotoMiddleware
- AsyncGraphMiddleware
- AsyncResumeMiddleware
- CustomFieldMiddleware
- CustomState
- ExtraMessagesMiddleware
- GotoMiddleware
- GraphMiddleware
- InnerMiddleware
- MyState
- NoCommandMiddleware
- OuterMiddleware
- OverrideMiddleware
- PassthroughMiddleware
- ResumeMiddleware
- ShortCircuitMiddleware
- StructuredMiddleware
- SummaryMiddleware
- TestAsyncComposition
- TestAsyncExtendedModelResponse
- TestBackwardsCompatibility
- TestBasicCommand
- TestCommandGotoDisallowed
- TestCommandGraphDisallowed
- TestCommandResumeDisallowed
- TestComposition
- TestCustomStateField
Dependencies
- collections.abc
- langchain.agents
- langchain.agents.middleware.types
- langchain_core.language_models.fake_chat_models
- langchain_core.messages
- langgraph.errors
- langgraph.types
- pytest
Source
Frequently Asked Questions
What does test_wrap_model_call_state_update.py do?
test_wrap_model_call_state_update.py is a source file in the langchain codebase, written in python. It belongs to the LangChainCore domain, LanguageModelBase subdomain.
What does test_wrap_model_call_state_update.py depend on?
test_wrap_model_call_state_update.py imports 8 module(s): collections.abc, langchain.agents, langchain.agents.middleware.types, langchain_core.language_models.fake_chat_models, langchain_core.messages, langgraph.errors, langgraph.types, pytest.
Where is test_wrap_model_call_state_update.py in the architecture?
test_wrap_model_call_state_update.py is located at libs/langchain_v1/tests/unit_tests/agents/middleware/core/test_wrap_model_call_state_update.py (domain: LangChainCore, subdomain: LanguageModelBase, directory: libs/langchain_v1/tests/unit_tests/agents/middleware/core).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free