test_middleware_can_update_via_system_message_object() — langchain Function Reference
Architecture documentation for the test_middleware_can_update_via_system_message_object() function in test_system_message.py from the langchain codebase.
Entity Profile
Dependency Diagram
graph TD a27d2d9b_0c5c_96ab_baae_ddc7bb601cb2["test_middleware_can_update_via_system_message_object()"] c8b5bf76_0cde_0cc9_8fe0_fa5a5836a1ac["TestSystemMessageUpdateViaMiddleware"] a27d2d9b_0c5c_96ab_baae_ddc7bb601cb2 -->|defined in| c8b5bf76_0cde_0cc9_8fe0_fa5a5836a1ac style a27d2d9b_0c5c_96ab_baae_ddc7bb601cb2 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
libs/langchain_v1/tests/unit_tests/agents/test_system_message.py lines 404–449
def test_middleware_can_update_via_system_message_object(self) -> None:
"""Test middleware updating system message using SystemMessage objects."""
def append_with_metadata_middleware(
request: ModelRequest,
handler: Callable[[ModelRequest], ModelResponse],
) -> ModelResponse:
"""Append using SystemMessage to preserve metadata."""
base_content = request.system_message.text if request.system_message else ""
base_kwargs = request.system_message.additional_kwargs if request.system_message else {}
new_message = SystemMessage(
content=base_content + " Additional instructions.",
additional_kwargs={**base_kwargs, "middleware": "applied"},
)
new_request = request.override(system_message=new_message)
return handler(new_request)
model = GenericFakeChatModel(messages=iter([AIMessage(content="response")]))
request = ModelRequest(
model=model,
system_message=SystemMessage(
content="Base prompt", additional_kwargs={"base": "value"}
),
messages=[],
tool_choice=None,
tools=[],
response_format=None,
state=AgentState(messages=[]),
runtime=Runtime(),
)
captured_request = None
def mock_handler(req: ModelRequest) -> ModelResponse:
nonlocal captured_request
captured_request = req
return ModelResponse(result=[AIMessage(content="response")])
append_with_metadata_middleware(request, mock_handler)
assert captured_request is not None
assert captured_request.system_message is not None
assert captured_request.system_message.text == "Base prompt Additional instructions."
assert captured_request.system_message.additional_kwargs["base"] == "value"
assert captured_request.system_message.additional_kwargs["middleware"] == "applied"
Domain
Subdomains
Source
Frequently Asked Questions
What does test_middleware_can_update_via_system_message_object() do?
test_middleware_can_update_via_system_message_object() is a function in the langchain codebase, defined in libs/langchain_v1/tests/unit_tests/agents/test_system_message.py.
Where is test_middleware_can_update_via_system_message_object() defined?
test_middleware_can_update_via_system_message_object() is defined in libs/langchain_v1/tests/unit_tests/agents/test_system_message.py at line 404.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free