test_todo.py — langchain Source File
Architecture documentation for test_todo.py, a python file in the langchain codebase. 9 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR fd3d6c88_0753_9025_2354_dd7714bc7b74["test_todo.py"] 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3["typing"] fd3d6c88_0753_9025_2354_dd7714bc7b74 --> 8e2034b7_ceb8_963f_29fc_2ea6b50ef9b3 120e2591_3e15_b895_72b6_cb26195e40a6["pytest"] fd3d6c88_0753_9025_2354_dd7714bc7b74 --> 120e2591_3e15_b895_72b6_cb26195e40a6 833aeadc_c3e9_bfcf_db07_ecb37ad3ba24["langchain_core.language_models.fake_chat_models"] fd3d6c88_0753_9025_2354_dd7714bc7b74 --> 833aeadc_c3e9_bfcf_db07_ecb37ad3ba24 d758344f_537f_649e_f467_b9d7442e86df["langchain_core.messages"] fd3d6c88_0753_9025_2354_dd7714bc7b74 --> d758344f_537f_649e_f467_b9d7442e86df 6f5e6c4b_1a3f_fd09_4697_631c27ef1033["langchain.agents.factory"] fd3d6c88_0753_9025_2354_dd7714bc7b74 --> 6f5e6c4b_1a3f_fd09_4697_631c27ef1033 c93ae36d_6c4a_a801_cd42_2de962dfca55["langchain.agents.middleware.todo"] fd3d6c88_0753_9025_2354_dd7714bc7b74 --> c93ae36d_6c4a_a801_cd42_2de962dfca55 50acc543_e5f0_2162_cf07_c2bf50723e0c["langchain.agents.middleware.types"] fd3d6c88_0753_9025_2354_dd7714bc7b74 --> 50acc543_e5f0_2162_cf07_c2bf50723e0c d135b586_15fc_7b4a_47fb_a8b2bcda78a5["tests.unit_tests.agents.model"] fd3d6c88_0753_9025_2354_dd7714bc7b74 --> d135b586_15fc_7b4a_47fb_a8b2bcda78a5 5dbfd558_f2f2_9663_3a3f_c317926ac1c1["langgraph.runtime"] fd3d6c88_0753_9025_2354_dd7714bc7b74 --> 5dbfd558_f2f2_9663_3a3f_c317926ac1c1 style fd3d6c88_0753_9025_2354_dd7714bc7b74 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
"""Unit tests for TodoListMiddleware."""
from __future__ import annotations
from typing import TYPE_CHECKING, Any, cast
import pytest
from langchain_core.language_models.fake_chat_models import GenericFakeChatModel
from langchain_core.messages import AIMessage, HumanMessage, ToolMessage
from langchain.agents.factory import create_agent
from langchain.agents.middleware.todo import (
WRITE_TODOS_SYSTEM_PROMPT,
WRITE_TODOS_TOOL_DESCRIPTION,
PlanningState,
TodoListMiddleware,
write_todos,
)
from langchain.agents.middleware.types import AgentState, ModelRequest, ModelResponse
from tests.unit_tests.agents.model import FakeToolCallingModel
if TYPE_CHECKING:
from langgraph.runtime import Runtime
def _fake_runtime() -> Runtime:
return cast("Runtime", object())
def _make_request(system_prompt: str | None = None) -> ModelRequest:
"""Create a minimal ModelRequest for testing."""
model = GenericFakeChatModel(messages=iter([AIMessage(content="response")]))
return ModelRequest(
model=model,
system_prompt=system_prompt,
messages=[],
tool_choice=None,
tools=[],
response_format=None,
state=AgentState(messages=[]),
runtime=_fake_runtime(),
model_settings={},
)
# ==============================================================================
# Synchronous Tests
# ==============================================================================
def test_todo_middleware_initialization() -> None:
"""Test that TodoListMiddleware initializes correctly."""
middleware = TodoListMiddleware()
assert middleware.state_schema == PlanningState
assert len(middleware.tools) == 1
assert middleware.tools[0].name == "write_todos"
def test_has_write_todos_tool() -> None:
"""Test that middleware registers the write_todos tool."""
// ... (748 more lines)
Domain
Subdomains
Functions
- _fake_runtime()
- _make_request()
- langgraph()
- test_adds_system_prompt_when_none_exists()
- test_adds_system_prompt_when_none_exists_async()
- test_appends_to_existing_system_prompt()
- test_appends_to_existing_system_prompt_async()
- test_custom_system_prompt()
- test_custom_system_prompt_async()
- test_custom_tool_description()
- test_handler_called_with_modified_request_async()
- test_has_write_todos_tool()
- test_parallel_write_todos_calls_rejected()
- test_parallel_write_todos_calls_rejected_async()
- test_parallel_write_todos_with_other_tools()
- test_parallel_write_todos_with_other_tools_async()
- test_single_write_todos_call_allowed()
- test_single_write_todos_call_allowed_async()
- test_todo_middleware_agent_creation_with_middleware()
- test_todo_middleware_custom_system_prompt()
- test_todo_middleware_custom_system_prompt_and_tool_description()
- test_todo_middleware_custom_system_prompt_in_agent()
- test_todo_middleware_custom_tool_description()
- test_todo_middleware_default_prompts()
- test_todo_middleware_initialization()
- test_todo_middleware_on_model_call()
- test_todo_middleware_write_todos_tool_execution()
- test_todo_middleware_write_todos_tool_validation_errors()
Dependencies
- langchain.agents.factory
- langchain.agents.middleware.todo
- langchain.agents.middleware.types
- langchain_core.language_models.fake_chat_models
- langchain_core.messages
- langgraph.runtime
- pytest
- tests.unit_tests.agents.model
- typing
Source
Frequently Asked Questions
What does test_todo.py do?
test_todo.py is a source file in the langchain codebase, written in python. It belongs to the CoreAbstractions domain, Serialization subdomain.
What functions are defined in test_todo.py?
test_todo.py defines 28 function(s): _fake_runtime, _make_request, langgraph, test_adds_system_prompt_when_none_exists, test_adds_system_prompt_when_none_exists_async, test_appends_to_existing_system_prompt, test_appends_to_existing_system_prompt_async, test_custom_system_prompt, test_custom_system_prompt_async, test_custom_tool_description, and 18 more.
What does test_todo.py depend on?
test_todo.py imports 9 module(s): langchain.agents.factory, langchain.agents.middleware.todo, langchain.agents.middleware.types, langchain_core.language_models.fake_chat_models, langchain_core.messages, langgraph.runtime, pytest, tests.unit_tests.agents.model, and 1 more.
Where is test_todo.py in the architecture?
test_todo.py is located at libs/langchain_v1/tests/unit_tests/agents/middleware/implementations/test_todo.py (domain: CoreAbstractions, subdomain: Serialization, directory: libs/langchain_v1/tests/unit_tests/agents/middleware/implementations).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free