TestBasicCommand Class — langchain Architecture
Architecture documentation for the TestBasicCommand class in test_wrap_model_call_state_update.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD 32ccf275_216c_0c5f_4a10_07f3bc9d69a5["TestBasicCommand"] 949c7cf4_56fe_f3b4_cd89_9631a7e9cb1e["AgentMiddleware"] 32ccf275_216c_0c5f_4a10_07f3bc9d69a5 -->|extends| 949c7cf4_56fe_f3b4_cd89_9631a7e9cb1e e4070722_d3c6_f73d_d727_5779ab576a2a["AgentState"] 32ccf275_216c_0c5f_4a10_07f3bc9d69a5 -->|extends| e4070722_d3c6_f73d_d727_5779ab576a2a 08361e76_a995_1e57_f200_e292474e2f00["test_wrap_model_call_state_update.py"] 32ccf275_216c_0c5f_4a10_07f3bc9d69a5 -->|defined in| 08361e76_a995_1e57_f200_e292474e2f00 04483ccb_4c64_7ff1_4669_71171222d0eb["test_command_messages_added_alongside_model_messages()"] 32ccf275_216c_0c5f_4a10_07f3bc9d69a5 -->|method| 04483ccb_4c64_7ff1_4669_71171222d0eb dd6f5635_507b_9aec_47c5_038caeb19080["test_command_with_extra_messages_and_model_response()"] 32ccf275_216c_0c5f_4a10_07f3bc9d69a5 -->|method| dd6f5635_507b_9aec_47c5_038caeb19080 b9c9a03c_fc16_a250_4e3b_00804123b967["test_command_structured_response_conflicts_with_model_response()"] 32ccf275_216c_0c5f_4a10_07f3bc9d69a5 -->|method| b9c9a03c_fc16_a250_4e3b_00804123b967 e327cf86_4eab_962c_02fa_5a242f4ebbbb["test_command_with_custom_state_field()"] 32ccf275_216c_0c5f_4a10_07f3bc9d69a5 -->|method| e327cf86_4eab_962c_02fa_5a242f4ebbbb
Relationship Graph
Source Code
libs/langchain_v1/tests/unit_tests/agents/middleware/core/test_wrap_model_call_state_update.py lines 26–142
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):
def wrap_model_call(
self,
request: ModelRequest,
handler: Callable[[ModelRequest], ModelResponse],
) -> ExtendedModelResponse:
response = handler(request)
summary = HumanMessage(content="Summary", id="summary")
return ExtendedModelResponse(
model_response=response,
command=Command(update={"messages": [summary]}),
)
model = GenericFakeChatModel(messages=iter([AIMessage(content="Hello!")]))
agent = create_agent(model=model, middleware=[ExtraMessagesMiddleware()])
result = agent.invoke({"messages": [HumanMessage(content="Hi")]})
messages = result["messages"]
assert len(messages) == 3
assert messages[0].content == "Hi"
assert messages[1].content == "Hello!"
assert messages[2].content == "Summary"
def test_command_structured_response_conflicts_with_model_response(self) -> None:
"""Command and model response both setting structured_response raises."""
class OverrideMiddleware(AgentMiddleware):
def wrap_model_call(
self,
request: ModelRequest,
handler: Callable[[ModelRequest], ModelResponse],
) -> ExtendedModelResponse:
response = handler(request)
response_with_structured = ModelResponse(
result=response.result,
structured_response={"from": "model"},
)
return ExtendedModelResponse(
model_response=response_with_structured,
command=Command(
update={
"structured_response": {"from": "command"},
}
),
)
Defined In
Extends
Source
Frequently Asked Questions
What is the TestBasicCommand class?
TestBasicCommand 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 TestBasicCommand defined?
TestBasicCommand is defined in libs/langchain_v1/tests/unit_tests/agents/middleware/core/test_wrap_model_call_state_update.py at line 26.
What does TestBasicCommand extend?
TestBasicCommand extends AgentMiddleware, AgentState.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free