The agent engineering platform.
Python agentsaiai-agentsanthropicchatgptdeepagentsenterpriseframeworkgeminigenerative-ailangchainlanggraphllmmultiagentopen-sourceopenaipydanticpythonragtypescript
fix(langchain): rename `PlanningMiddleware` to `TodoListMiddleware` (#33476)
Sydney Runklefff87e95d190
diff --git a/libs/langchain_v1/langchain/agents/middleware/__init__.py b/libs/langchain_v1/langchain/agents/middleware/__init__.pyindex 1b0c50bb8d..607707b99b 100644--- a/libs/langchain_v1/langchain/agents/middleware/__init__.py+++ b/libs/langchain_v1/langchain/agents/middleware/__init__.py@@ -11,8 +11,8 @@ from .human_in_the_loop import (from .model_call_limit import ModelCallLimitMiddlewarefrom .model_fallback import ModelFallbackMiddlewarefrom .pii import PIIDetectionError, PIIMiddleware-from .planning import PlanningMiddlewarefrom .summarization import SummarizationMiddleware+from .todo import TodoListMiddlewarefrom .tool_call_limit import ToolCallLimitMiddlewarefrom .tool_emulator import LLMToolEmulatorfrom .tool_selection import LLMToolSelectorMiddleware@@ -45,8 +45,8 @@ __all__ = ["ModelResponse","PIIDetectionError","PIIMiddleware",- "PlanningMiddleware","SummarizationMiddleware",+ "TodoListMiddleware","ToolCallLimitMiddleware","after_agent","after_model",diff --git a/libs/langchain_v1/langchain/agents/middleware/planning.py b/libs/langchain_v1/langchain/agents/middleware/todo.pysimilarity index 97%rename from libs/langchain_v1/langchain/agents/middleware/planning.pyrename to libs/langchain_v1/langchain/agents/middleware/todo.pyindex 991dffa11a..4ae206584a 100644--- a/libs/langchain_v1/langchain/agents/middleware/planning.py+++ b/libs/langchain_v1/langchain/agents/middleware/todo.py@@ -126,7 +126,7 @@ def write_todos(todos: list[Todo], tool_call_id: Annotated[str, InjectedToolCall)-class PlanningMiddleware(AgentMiddleware):+class TodoListMiddleware(AgentMiddleware):"""Middleware that provides todo list management capabilities to agents.This middleware adds a `write_todos` tool that allows agents to create and manage@@ -139,10 +139,10 @@ class PlanningMiddleware(AgentMiddleware):Example:```python- from langchain.agents.middleware.planning import PlanningMiddleware+ from langchain.agents.middleware.todo import TodoListMiddlewarefrom langchain.agents import create_agent- agent = create_agent("openai:gpt-4o", middleware=[PlanningMiddleware()])+ agent = create_agent("openai:gpt-4o", middleware=[TodoListMiddleware()])# Agent now has access to write_todos tool and todo state trackingresult = await agent.invoke({"messages": [HumanMessage("Help me refactor my codebase")]})@@ -165,7 +165,7 @@ class PlanningMiddleware(AgentMiddleware):system_prompt: str = WRITE_TODOS_SYSTEM_PROMPT,tool_description: str = WRITE_TODOS_TOOL_DESCRIPTION,) -> None:- """Initialize the PlanningMiddleware with optional custom prompts.+ """Initialize the TodoListMiddleware with optional custom prompts.Args:system_prompt: Custom system prompt to guide the agent on using the todo tool.diff --git a/libs/langchain_v1/tests/unit_tests/agents/test_middleware_agent.py b/libs/langchain_v1/tests/unit_tests/agents/test_middleware_agent.pyindex a50644fc81..05f20bee1d 100644--- a/libs/langchain_v1/tests/unit_tests/agents/test_middleware_agent.py+++ b/libs/langchain_v1/tests/unit_tests/agents/test_middleware_agent.py@@ -32,8 +32,8 @@ from langchain.agents.middleware.human_in_the_loop import (Action,HumanInTheLoopMiddleware,)-from langchain.agents.middleware.planning import (- PlanningMiddleware,+from langchain.agents.middleware.todo import (+ TodoListMiddleware,PlanningState,WRITE_TODOS_SYSTEM_PROMPT,write_todos,@@ -1457,10 +1457,10 @@ def test_jump_to_is_ephemeral() -> None:assert "jump_to" not in result-# Tests for PlanningMiddleware-def test_planning_middleware_initialization() -> None:- """Test that PlanningMiddleware initializes correctly."""- middleware = PlanningMiddleware()+# Tests for TodoListMiddleware+def test_todo_middleware_initialization() -> None:+ """Test that TodoListMiddleware initializes correctly."""+ middleware = TodoListMiddleware()assert middleware.state_schema == PlanningStateassert len(middleware.tools) == 1assert middleware.tools[0].name == "write_todos"@@ -1473,9 +1473,9 @@ def test_planning_middleware_initialization() -> None:(None, "## `write_todos`"),],)-def test_planning_middleware_on_model_call(original_prompt, expected_prompt_prefix) -> None:+def test_todo_middleware_on_model_call(original_prompt, expected_prompt_prefix) -> None:"""Test that wrap_model_call handles system prompts correctly."""- middleware = PlanningMiddleware()+ middleware = TodoListMiddleware()model = FakeToolCallingModel()state: PlanningState = {"messages": [HumanMessage(content="Hello")]}@@ -1526,7 +1526,7 @@ def test_planning_middleware_on_model_call(original_prompt, expected_prompt_pref),],)-def test_planning_middleware_write_todos_tool_execution(todos, expected_message) -> None:+def test_todo_middleware_write_todos_tool_execution(todos, expected_message) -> None:"""Test that the write_todos tool executes correctly."""tool_call = {"args": {"todos": todos},@@ -1546,7 +1546,7 @@ def test_planning_middleware_write_todos_tool_execution(todos, expected_message)[{"status": "pending"}],],)-def test_planning_middleware_write_todos_tool_validation_errors(invalid_todos) -> None:+def test_todo_middleware_write_todos_tool_validation_errors(invalid_todos) -> None:"""Test that the write_todos tool rejects invalid input."""tool_call = {"args": {"todos": invalid_todos},@@ -1558,7 +1558,7 @@ def test_planning_middleware_write_todos_tool_validation_errors(invalid_todos) -write_todos.invoke(tool_call)-def test_planning_middleware_agent_creation_with_middleware() -> None:+def test_todo_middleware_agent_creation_with_middleware() -> None:"""Test that an agent can be created with the planning middleware."""model = FakeToolCallingModel(tool_calls=[@@ -1589,7 +1589,7 @@ def test_planning_middleware_agent_creation_with_middleware() -> None:[],])- middleware = PlanningMiddleware()+ middleware = TodoListMiddleware()agent = create_agent(model=model, middleware=[middleware])result = agent.invoke({"messages": [HumanMessage("Hello")]})@@ -1606,12 +1606,14 @@ def test_planning_middleware_agent_creation_with_middleware() -> None:assert len(result["messages"]) == 8-def test_planning_middleware_custom_system_prompt() -> None:- """Test that PlanningMiddleware can be initialized with custom system prompt."""+def test_todo_middleware_custom_system_prompt() -> None:+ """Test that TodoListMiddleware can be initialized with custom system prompt."""custom_system_prompt = "Custom todo system prompt for testing"- middleware = PlanningMiddleware(system_prompt=custom_system_prompt)+ middleware = TodoListMiddleware(system_prompt=custom_system_prompt)model = FakeToolCallingModel()+ state: PlanningState = {"messages": [HumanMessage(content="Hello")]}+request = ModelRequest(model=model,system_prompt="Original prompt",@@ -1620,10 +1622,10 @@ def test_planning_middleware_custom_system_prompt() -> None:tools=[],response_format=None,model_settings={},+ state=state,+ runtime=cast(Runtime, object()),)- state: PlanningState = {"messages": [HumanMessage(content="Hello")]}-def mock_handler(req: ModelRequest) -> AIMessage:return AIMessage(content="mock response")@@ -1633,21 +1635,21 @@ def test_planning_middleware_custom_system_prompt() -> None:assert request.system_prompt == f"Original prompt\n\n{custom_system_prompt}"-def test_planning_middleware_custom_tool_description() -> None:- """Test that PlanningMiddleware can be initialized with custom tool description."""+def test_todo_middleware_custom_tool_description() -> None:+ """Test that TodoListMiddleware can be initialized with custom tool description."""custom_tool_description = "Custom tool description for testing"- middleware = PlanningMiddleware(tool_description=custom_tool_description)+ middleware = TodoListMiddleware(tool_description=custom_tool_description)assert len(middleware.tools) == 1tool = middleware.tools[0]assert tool.description == custom_tool_description-def test_planning_middleware_custom_system_prompt_and_tool_description() -> None:- """Test that PlanningMiddleware can be initialized with both custom prompts."""+def test_todo_middleware_custom_system_prompt_and_tool_description() -> None:+ """Test that TodoListMiddleware can be initialized with both custom prompts."""custom_system_prompt = "Custom system prompt"custom_tool_description = "Custom tool description"- middleware = PlanningMiddleware(+ middleware = TodoListMiddleware(system_prompt=custom_system_prompt,tool_description=custom_tool_description,)@@ -1682,9 +1684,9 @@ def test_planning_middleware_custom_system_prompt_and_tool_description() -> Noneassert tool.description == custom_tool_description-def test_planning_middleware_default_prompts() -> None:- """Test that PlanningMiddleware uses default prompts when none provided."""- middleware = PlanningMiddleware()+def test_todo_middleware_default_prompts() -> None:+ """Test that TodoListMiddleware uses default prompts when none provided."""+ middleware = TodoListMiddleware()# Verify default system promptassert middleware.system_prompt == WRITE_TODOS_SYSTEM_PROMPT@@ -1696,9 +1698,9 @@ def test_planning_middleware_default_prompts() -> None:assert tool.description == WRITE_TODOS_TOOL_DESCRIPTION-def test_planning_middleware_custom_system_prompt() -> None:+def test_todo_middleware_custom_system_prompt_in_agent() -> None:"""Test that custom tool executes correctly in an agent."""- middleware = PlanningMiddleware(system_prompt="call the write_todos tool")+ middleware = TodoListMiddleware(system_prompt="call the write_todos tool")model = FakeToolCallingModel(tool_calls=[