test_async_both_commands_additive_messages() — langchain Function Reference
Architecture documentation for the test_async_both_commands_additive_messages() function in test_wrap_model_call_state_update.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 27773a64_cc86_16f8_6afe_6a894b80f58b["test_async_both_commands_additive_messages()"] 0f39b70e_2926_951e_853d_3344387750a6["TestAsyncComposition"] 27773a64_cc86_16f8_6afe_6a894b80f58b -->|defined in| 0f39b70e_2926_951e_853d_3344387750a6 style 27773a64_cc86_16f8_6afe_6a894b80f58b 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 688–733
async def test_async_both_commands_additive_messages(self) -> None:
"""Async: both inner and outer command messages are added alongside model."""
class OuterMiddleware(AgentMiddleware):
async def awrap_model_call(
self,
request: ModelRequest,
handler: Callable[[ModelRequest], Awaitable[ModelResponse]],
) -> ExtendedModelResponse:
response = await handler(request)
return ExtendedModelResponse(
model_response=response,
command=Command(
update={"messages": [HumanMessage(content="Outer msg", id="outer")]}
),
)
class InnerMiddleware(AgentMiddleware):
async def awrap_model_call(
self,
request: ModelRequest,
handler: Callable[[ModelRequest], Awaitable[ModelResponse]],
) -> ExtendedModelResponse:
response = await handler(request)
return ExtendedModelResponse(
model_response=response,
command=Command(
update={"messages": [HumanMessage(content="Inner msg", id="inner")]}
),
)
model = GenericFakeChatModel(messages=iter([AIMessage(content="Hello")]))
agent = create_agent(
model=model,
middleware=[OuterMiddleware(), InnerMiddleware()],
)
result = await agent.ainvoke({"messages": [HumanMessage("Hi")]})
# All messages additive: model + inner + outer
messages = result["messages"]
assert len(messages) == 4
assert messages[0].content == "Hi"
assert messages[1].content == "Hello"
assert messages[2].content == "Inner msg"
assert messages[3].content == "Outer msg"
Domain
Subdomains
Defined In
Source
Frequently Asked Questions
What does test_async_both_commands_additive_messages() do?
test_async_both_commands_additive_messages() 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_async_both_commands_additive_messages() defined?
test_async_both_commands_additive_messages() is defined in libs/langchain_v1/tests/unit_tests/agents/middleware/core/test_wrap_model_call_state_update.py at line 688.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free