todo.py — langchain Source File
Architecture documentation for todo.py, a python file in the langchain codebase. 9 imports, 0 dependents.
Entity Profile
Dependency Diagram
graph LR 446b9f1c_796b_e509_22cc_36bc6d734792["todo.py"] feec1ec4_6917_867b_d228_b134d0ff8099["typing"] 446b9f1c_796b_e509_22cc_36bc6d734792 --> feec1ec4_6917_867b_d228_b134d0ff8099 2bf6d401_816d_d011_3b05_a6114f55ff58["collections.abc"] 446b9f1c_796b_e509_22cc_36bc6d734792 --> 2bf6d401_816d_d011_3b05_a6114f55ff58 e07f6d54_afcc_052d_d33f_8ccdcc46f752["langgraph.runtime"] 446b9f1c_796b_e509_22cc_36bc6d734792 --> e07f6d54_afcc_052d_d33f_8ccdcc46f752 9444498b_8066_55c7_b3a2_1d90c4162a32["langchain_core.messages"] 446b9f1c_796b_e509_22cc_36bc6d734792 --> 9444498b_8066_55c7_b3a2_1d90c4162a32 121262a1_0bd6_d637_bce3_307ab6b3ecd4["langchain_core.tools"] 446b9f1c_796b_e509_22cc_36bc6d734792 --> 121262a1_0bd6_d637_bce3_307ab6b3ecd4 726d73c8_7999_511a_c1ec_4524fb1cc31a["langgraph.types"] 446b9f1c_796b_e509_22cc_36bc6d734792 --> 726d73c8_7999_511a_c1ec_4524fb1cc31a f85fae70_1011_eaec_151c_4083140ae9e5["typing_extensions"] 446b9f1c_796b_e509_22cc_36bc6d734792 --> f85fae70_1011_eaec_151c_4083140ae9e5 a681398d_ed44_c914_1a44_5d174223b069["langchain.agents.middleware.types"] 446b9f1c_796b_e509_22cc_36bc6d734792 --> a681398d_ed44_c914_1a44_5d174223b069 b036e189_bfab_a345_61aa_93be8b3e73bc["langchain.tools"] 446b9f1c_796b_e509_22cc_36bc6d734792 --> b036e189_bfab_a345_61aa_93be8b3e73bc style 446b9f1c_796b_e509_22cc_36bc6d734792 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
"""Planning and task management middleware for agents."""
from __future__ import annotations
from typing import TYPE_CHECKING, Annotated, Any, Literal, cast
if TYPE_CHECKING:
from collections.abc import Awaitable, Callable
from langgraph.runtime import Runtime
from langchain_core.messages import AIMessage, SystemMessage, ToolMessage
from langchain_core.tools import tool
from langgraph.types import Command
from typing_extensions import NotRequired, TypedDict, override
from langchain.agents.middleware.types import (
AgentMiddleware,
AgentState,
ContextT,
ModelRequest,
ModelResponse,
OmitFromInput,
ResponseT,
)
from langchain.tools import InjectedToolCallId
class Todo(TypedDict):
"""A single todo item with content and status."""
content: str
"""The content/description of the todo item."""
status: Literal["pending", "in_progress", "completed"]
"""The current status of the todo item."""
class PlanningState(AgentState[ResponseT]):
"""State schema for the todo middleware.
Type Parameters:
ResponseT: The type of the structured response. Defaults to `Any`.
"""
todos: Annotated[NotRequired[list[Todo]], OmitFromInput]
"""List of todo items for tracking task progress."""
WRITE_TODOS_TOOL_DESCRIPTION = """Use this tool to create and manage a structured task list for your current work session. This helps you track progress, organize complex tasks, and demonstrate thoroughness to the user.
Only use this tool if you think it will be helpful in staying organized. If the user's request is trivial and takes less than 3 steps, it is better to NOT use this tool and just do the task directly.
## When to Use This Tool
Use this tool in these scenarios:
1. Complex multi-step tasks - When a task requires 3 or more distinct steps or actions
2. Non-trivial and complex tasks - Tasks that require careful planning or multiple operations
3. User explicitly requests todo list - When the user directly asks you to use the todo list
4. User provides multiple tasks - When users provide a list of things to be done (numbered or comma-separated)
// ... (268 more lines)
Domain
Subdomains
Functions
Dependencies
- collections.abc
- langchain.agents.middleware.types
- langchain.tools
- langchain_core.messages
- langchain_core.tools
- langgraph.runtime
- langgraph.types
- typing
- typing_extensions
Source
Frequently Asked Questions
What does todo.py do?
todo.py is a source file in the langchain codebase, written in python. It belongs to the LangChainCore domain, ApiManagement subdomain.
What functions are defined in todo.py?
todo.py defines 2 function(s): collections, write_todos.
What does todo.py depend on?
todo.py imports 9 module(s): collections.abc, langchain.agents.middleware.types, langchain.tools, langchain_core.messages, langchain_core.tools, langgraph.runtime, langgraph.types, typing, and 1 more.
Where is todo.py in the architecture?
todo.py is located at libs/langchain_v1/langchain/agents/middleware/todo.py (domain: LangChainCore, subdomain: ApiManagement, directory: libs/langchain_v1/langchain/agents/middleware).
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free