Home / Function/ test_async_command_adds_messages() — langchain Function Reference

test_async_command_adds_messages() — langchain Function Reference

Architecture documentation for the test_async_command_adds_messages() function in test_wrap_model_call_state_update.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  876aec65_af3b_7d30_64a7_8668d492a047["test_async_command_adds_messages()"]
  62fed73a_37ab_9497_9ced_d00470614047["TestAsyncExtendedModelResponse"]
  876aec65_af3b_7d30_64a7_8668d492a047 -->|defined in| 62fed73a_37ab_9497_9ced_d00470614047
  style 876aec65_af3b_7d30_64a7_8668d492a047 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 253–279

    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"

Domain

Subdomains

Frequently Asked Questions

What does test_async_command_adds_messages() do?
test_async_command_adds_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_command_adds_messages() defined?
test_async_command_adds_messages() is defined in libs/langchain_v1/tests/unit_tests/agents/middleware/core/test_wrap_model_call_state_update.py at line 253.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free