TestAsyncExtendedModelResponse Class — langchain Architecture
Architecture documentation for the TestAsyncExtendedModelResponse class in test_wrap_model_call_state_update.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 62fed73a_37ab_9497_9ced_d00470614047["TestAsyncExtendedModelResponse"] 949c7cf4_56fe_f3b4_cd89_9631a7e9cb1e["AgentMiddleware"] 62fed73a_37ab_9497_9ced_d00470614047 -->|extends| 949c7cf4_56fe_f3b4_cd89_9631a7e9cb1e 08361e76_a995_1e57_f200_e292474e2f00["test_wrap_model_call_state_update.py"] 62fed73a_37ab_9497_9ced_d00470614047 -->|defined in| 08361e76_a995_1e57_f200_e292474e2f00 876aec65_af3b_7d30_64a7_8668d492a047["test_async_command_adds_messages()"] 62fed73a_37ab_9497_9ced_d00470614047 -->|method| 876aec65_af3b_7d30_64a7_8668d492a047 21fdde48_92a6_42c1_8af2_dfde67e600e1["test_async_decorator_command()"] 62fed73a_37ab_9497_9ced_d00470614047 -->|method| 21fdde48_92a6_42c1_8af2_dfde67e600e1
Relationship Graph
Source Code
libs/langchain_v1/tests/unit_tests/agents/middleware/core/test_wrap_model_call_state_update.py lines 250–309
class TestAsyncExtendedModelResponse:
"""Test async variant of ExtendedModelResponse."""
async def test_async_command_adds_messages(self) -> None:
"""awrap_model_call command adds messages alongside model response."""
class AsyncAddMiddleware(AgentMiddleware):
async def awrap_model_call(
self,
request: ModelRequest,
handler: Callable[[ModelRequest], Awaitable[ModelResponse]],
) -> ExtendedModelResponse:
response = await handler(request)
custom = HumanMessage(content="Async custom", id="async-custom")
return ExtendedModelResponse(
model_response=response,
command=Command(update={"messages": [custom]}),
)
model = GenericFakeChatModel(messages=iter([AIMessage(content="Async hello!")]))
agent = create_agent(model=model, middleware=[AsyncAddMiddleware()])
result = await agent.ainvoke({"messages": [HumanMessage(content="Hi")]})
# Both model response and command messages are present (additive)
messages = result["messages"]
assert len(messages) == 3
assert messages[0].content == "Hi"
assert messages[1].content == "Async hello!"
assert messages[2].content == "Async custom"
async def test_async_decorator_command(self) -> None:
"""@wrap_model_call async decorator returns ExtendedModelResponse with command."""
@wrap_model_call
async def command_middleware(
request: ModelRequest,
handler: Callable[[ModelRequest], Awaitable[ModelResponse]],
) -> ExtendedModelResponse:
response = await handler(request)
return ExtendedModelResponse(
model_response=response,
command=Command(
update={
"messages": [
HumanMessage(content="Decorator msg", id="dec"),
]
}
),
)
model = GenericFakeChatModel(messages=iter([AIMessage(content="Async response")]))
agent = create_agent(model=model, middleware=[command_middleware])
result = await agent.ainvoke({"messages": [HumanMessage(content="Hi")]})
messages = result["messages"]
assert len(messages) == 3
assert messages[1].content == "Async response"
assert messages[2].content == "Decorator msg"
Defined In
Extends
Source
Frequently Asked Questions
What is the TestAsyncExtendedModelResponse class?
TestAsyncExtendedModelResponse is a class in the langchain codebase, defined in libs/langchain_v1/tests/unit_tests/agents/middleware/core/test_wrap_model_call_state_update.py.
Where is TestAsyncExtendedModelResponse defined?
TestAsyncExtendedModelResponse is defined in libs/langchain_v1/tests/unit_tests/agents/middleware/core/test_wrap_model_call_state_update.py at line 250.
What does TestAsyncExtendedModelResponse extend?
TestAsyncExtendedModelResponse extends AgentMiddleware.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free