test_system_message.py — langchain Source File
Architecture documentation for test_system_message.py, a python file in the langchain codebase. 9 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR f3b810a8_9aba_8793_30c3_bcc8068e5c38["test_system_message.py"] cfe2bde5_180e_e3b0_df2b_55b3ebaca8e7["collections.abc"] f3b810a8_9aba_8793_30c3_bcc8068e5c38 --> cfe2bde5_180e_e3b0_df2b_55b3ebaca8e7 aac5f8ad_7f2a_3a8e_3b4b_b07d681cbdcf["dataclasses"] f3b810a8_9aba_8793_30c3_bcc8068e5c38 --> aac5f8ad_7f2a_3a8e_3b4b_b07d681cbdcf 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3["typing"] f3b810a8_9aba_8793_30c3_bcc8068e5c38 --> 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3 120e2591_3e15_b895_72b6_cb26195e40a6["pytest"] f3b810a8_9aba_8793_30c3_bcc8068e5c38 --> 120e2591_3e15_b895_72b6_cb26195e40a6 833aeadc_c3e9_bfcf_db07_ecb37ad3ba24["langchain_core.language_models.fake_chat_models"] f3b810a8_9aba_8793_30c3_bcc8068e5c38 --> 833aeadc_c3e9_bfcf_db07_ecb37ad3ba24 d758344f_537f_649e_f467_b9d7442e86df["langchain_core.messages"] f3b810a8_9aba_8793_30c3_bcc8068e5c38 --> d758344f_537f_649e_f467_b9d7442e86df 5dbfd558_f2f2_9663_3a3f_c317926ac1c1["langgraph.runtime"] f3b810a8_9aba_8793_30c3_bcc8068e5c38 --> 5dbfd558_f2f2_9663_3a3f_c317926ac1c1 6f5e6c4b_1a3f_fd09_4697_631c27ef1033["langchain.agents.factory"] f3b810a8_9aba_8793_30c3_bcc8068e5c38 --> 6f5e6c4b_1a3f_fd09_4697_631c27ef1033 50acc543_e5f0_2162_cf07_c2bf50723e0c["langchain.agents.middleware.types"] f3b810a8_9aba_8793_30c3_bcc8068e5c38 --> 50acc543_e5f0_2162_cf07_c2bf50723e0c style f3b810a8_9aba_8793_30c3_bcc8068e5c38 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
"""Comprehensive unit tests for system message handling in agents.
This module consolidates all system message and dynamic prompt tests:
- Basic system message scenarios (none, string, SystemMessage)
- ModelRequest system_message field support
- System message updates via middleware
- Multiple middleware chaining
- Cache control preservation
- Metadata merging
- Dynamic system prompt middleware
- Edge cases and error handling
These tests replicate functionality from langchainjs PR #9459.
"""
from collections.abc import Callable
from dataclasses import dataclass
from typing import Any
import pytest
from langchain_core.language_models.fake_chat_models import GenericFakeChatModel
from langchain_core.messages import AIMessage, HumanMessage, SystemMessage, TextContentBlock
from langgraph.runtime import Runtime
from langchain.agents.factory import create_agent
from langchain.agents.middleware.types import AgentState, ModelRequest, ModelResponse
def _make_request(
system_message: SystemMessage | None = None,
system_prompt: str | None = None,
) -> ModelRequest:
"""Create a minimal ModelRequest for testing."""
model = GenericFakeChatModel(messages=iter([AIMessage(content="response")]))
return ModelRequest(
model=model,
system_message=system_message,
system_prompt=system_prompt,
messages=[],
tool_choice=None,
tools=[],
response_format=None,
state=AgentState(messages=[]),
runtime=Runtime(),
model_settings={},
)
# =============================================================================
# ModelRequest Tests
# =============================================================================
class TestModelRequestSystemMessage:
"""Test ModelRequest with system_message field."""
@pytest.mark.parametrize(
("system_message", "system_prompt", "expected_msg", "expected_prompt"),
[
# Test with SystemMessage
// ... (1004 more lines)
Domain
Subdomains
Functions
Classes
Dependencies
- collections.abc
- dataclasses
- langchain.agents.factory
- langchain.agents.middleware.types
- langchain_core.language_models.fake_chat_models
- langchain_core.messages
- langgraph.runtime
- pytest
- typing
Source
Frequently Asked Questions
What does test_system_message.py do?
test_system_message.py is a source file in the langchain codebase, written in python. It belongs to the CoreAbstractions domain, MessageSchema subdomain.
What functions are defined in test_system_message.py?
test_system_message.py defines 1 function(s): _make_request.
What does test_system_message.py depend on?
test_system_message.py imports 9 module(s): collections.abc, dataclasses, langchain.agents.factory, langchain.agents.middleware.types, langchain_core.language_models.fake_chat_models, langchain_core.messages, langgraph.runtime, pytest, and 1 more.
Where is test_system_message.py in the architecture?
test_system_message.py is located at libs/langchain_v1/tests/unit_tests/agents/test_system_message.py (domain: CoreAbstractions, subdomain: MessageSchema, directory: libs/langchain_v1/tests/unit_tests/agents).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free