test_state_schema.py — langchain Source File
Architecture documentation for test_state_schema.py, a python file in the langchain codebase. 8 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 66766fa0_29a7_681e_a16a_052d542c8f12["test_state_schema.py"] 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3["typing"] 66766fa0_29a7_681e_a16a_052d542c8f12 --> 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3 d758344f_537f_649e_f467_b9d7442e86df["langchain_core.messages"] 66766fa0_29a7_681e_a16a_052d542c8f12 --> d758344f_537f_649e_f467_b9d7442e86df 43d88577_548b_2248_b01b_7987bae85dcc["langchain_core.tools"] 66766fa0_29a7_681e_a16a_052d542c8f12 --> 43d88577_548b_2248_b01b_7987bae85dcc 839143dd_e377_b604_96de_3624dbdffeb5["langchain.agents"] 66766fa0_29a7_681e_a16a_052d542c8f12 --> 839143dd_e377_b604_96de_3624dbdffeb5 50acc543_e5f0_2162_cf07_c2bf50723e0c["langchain.agents.middleware.types"] 66766fa0_29a7_681e_a16a_052d542c8f12 --> 50acc543_e5f0_2162_cf07_c2bf50723e0c e85266a5_b172_4ddd_2fa6_e91b38ae8c0e["langchain.tools"] 66766fa0_29a7_681e_a16a_052d542c8f12 --> e85266a5_b172_4ddd_2fa6_e91b38ae8c0e d135b586_15fc_7b4a_47fb_a8b2bcda78a5["tests.unit_tests.agents.model"] 66766fa0_29a7_681e_a16a_052d542c8f12 --> d135b586_15fc_7b4a_47fb_a8b2bcda78a5 5dbfd558_f2f2_9663_3a3f_c317926ac1c1["langgraph.runtime"] 66766fa0_29a7_681e_a16a_052d542c8f12 --> 5dbfd558_f2f2_9663_3a3f_c317926ac1c1 style 66766fa0_29a7_681e_a16a_052d542c8f12 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
"""Test state_schema parameter in create_agent.
This module tests that the state_schema parameter allows users to extend
AgentState without needing to create custom middleware.
"""
from __future__ import annotations
from typing import TYPE_CHECKING, Annotated, Any
from langchain_core.messages import HumanMessage
from langchain_core.tools import tool
from langchain.agents import create_agent
from langchain.agents.middleware.types import (
AgentMiddleware,
AgentState,
PrivateStateAttr,
)
# Cannot move ToolRuntime to TYPE_CHECKING as parameters of @tool annotated functions
# are inspected at runtime.
from langchain.tools import ToolRuntime # noqa: TC001
from tests.unit_tests.agents.model import FakeToolCallingModel
if TYPE_CHECKING:
from langgraph.runtime import Runtime
@tool
def simple_tool(x: int) -> str:
"""Simple tool for basic tests."""
return f"Result: {x}"
def test_state_schema_single_custom_field() -> None:
"""Test that a single custom state field is preserved through agent execution."""
class CustomState(AgentState[Any]):
custom_field: str
agent = create_agent(
model=FakeToolCallingModel(
tool_calls=[[{"args": {"x": 1}, "id": "call_1", "name": "simple_tool"}], []]
),
tools=[simple_tool],
state_schema=CustomState,
)
result = agent.invoke({"messages": [HumanMessage("Test")], "custom_field": "test_value"})
assert result["custom_field"] == "test_value"
assert len(result["messages"]) == 4
def test_state_schema_multiple_custom_fields() -> None:
"""Test that multiple custom state fields are preserved through agent execution."""
class CustomState(AgentState[Any]):
user_id: str
// ... (196 more lines)
Domain
Subdomains
Functions
Classes
Dependencies
- langchain.agents
- langchain.agents.middleware.types
- langchain.tools
- langchain_core.messages
- langchain_core.tools
- langgraph.runtime
- tests.unit_tests.agents.model
- typing
Source
Frequently Asked Questions
What does test_state_schema.py do?
test_state_schema.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_state_schema.py?
test_state_schema.py defines 9 function(s): langgraph, simple_tool, test_state_schema_async, test_state_schema_multiple_custom_fields, test_state_schema_none_uses_default, test_state_schema_single_custom_field, test_state_schema_with_middleware, test_state_schema_with_private_state_field, test_state_schema_with_tool_runtime.
What does test_state_schema.py depend on?
test_state_schema.py imports 8 module(s): langchain.agents, langchain.agents.middleware.types, langchain.tools, langchain_core.messages, langchain_core.tools, langgraph.runtime, tests.unit_tests.agents.model, typing.
Where is test_state_schema.py in the architecture?
test_state_schema.py is located at libs/langchain_v1/tests/unit_tests/agents/test_state_schema.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