test_outer_command_messages_added_alongside_model() — langchain Function Reference
Architecture documentation for the test_outer_command_messages_added_alongside_model() function in test_wrap_model_call_state_update.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD a9938455_2c48_8cba_a118_749c3cb86a5f["test_outer_command_messages_added_alongside_model()"] 269d8393_43ba_e665_6d86_95d75ce0c396["TestComposition"] a9938455_2c48_8cba_a118_749c3cb86a5f -->|defined in| 269d8393_43ba_e665_6d86_95d75ce0c396 style a9938455_2c48_8cba_a118_749c3cb86a5f fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/langchain_v1/tests/unit_tests/agents/middleware/core/test_wrap_model_call_state_update.py lines 320–372
def test_outer_command_messages_added_alongside_model(self) -> None:
"""Outer middleware's command messages are added alongside model messages."""
execution_order: list[str] = []
class OuterMiddleware(AgentMiddleware):
def wrap_model_call(
self,
request: ModelRequest,
handler: Callable[[ModelRequest], ModelResponse],
) -> ExtendedModelResponse:
execution_order.append("outer-before")
response = handler(request)
execution_order.append("outer-after")
return ExtendedModelResponse(
model_response=response,
command=Command(
update={"messages": [HumanMessage(content="Outer msg", id="outer-msg")]}
),
)
class InnerMiddleware(AgentMiddleware):
def wrap_model_call(
self,
request: ModelRequest,
handler: Callable[[ModelRequest], ModelResponse],
) -> ModelResponse:
execution_order.append("inner-before")
response = handler(request)
execution_order.append("inner-after")
return response
model = GenericFakeChatModel(messages=iter([AIMessage(content="Composed")]))
agent = create_agent(
model=model,
middleware=[OuterMiddleware(), InnerMiddleware()],
)
result = agent.invoke({"messages": [HumanMessage("Hi")]})
# Execution order: outer wraps inner
assert execution_order == [
"outer-before",
"inner-before",
"inner-after",
"outer-after",
]
# Model messages + outer command messages (additive)
messages = result["messages"]
assert len(messages) == 3
assert messages[0].content == "Hi"
assert messages[1].content == "Composed"
assert messages[2].content == "Outer msg"
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does test_outer_command_messages_added_alongside_model() do?
test_outer_command_messages_added_alongside_model() is a function in the langchain codebase, defined in libs/langchain_v1/tests/unit_tests/agents/middleware/core/test_wrap_model_call_state_update.py.
Where is test_outer_command_messages_added_alongside_model() defined?
test_outer_command_messages_added_alongside_model() is defined in libs/langchain_v1/tests/unit_tests/agents/middleware/core/test_wrap_model_call_state_update.py at line 320.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free