Home / Function/ __init__() — langchain Function Reference

__init__() — langchain Function Reference

Architecture documentation for the __init__() function in todo.py from the langchain codebase.

Entity Profile

Dependency Diagram

graph TD
  d98ccf82_4d6c_11e1_1817_de4c6a3ada8b["__init__()"]
  60552546_6c10_6b0f_fd5d_93ed6530c806["TodoListMiddleware"]
  d98ccf82_4d6c_11e1_1817_de4c6a3ada8b -->|defined in| 60552546_6c10_6b0f_fd5d_93ed6530c806
  4db9c954_6050_9e2c_53b5_4429e85045e4["write_todos()"]
  d98ccf82_4d6c_11e1_1817_de4c6a3ada8b -->|calls| 4db9c954_6050_9e2c_53b5_4429e85045e4
  style d98ccf82_4d6c_11e1_1817_de4c6a3ada8b fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

libs/langchain_v1/langchain/agents/middleware/todo.py lines 167–199

    def __init__(
        self,
        *,
        system_prompt: str = WRITE_TODOS_SYSTEM_PROMPT,
        tool_description: str = WRITE_TODOS_TOOL_DESCRIPTION,
    ) -> None:
        """Initialize the `TodoListMiddleware` with optional custom prompts.

        Args:
            system_prompt: Custom system prompt to guide the agent on using the todo
                tool.
            tool_description: Custom description for the `write_todos` tool.
        """
        super().__init__()
        self.system_prompt = system_prompt
        self.tool_description = tool_description

        # Dynamically create the write_todos tool with the custom description
        @tool(description=self.tool_description)
        def write_todos(
            todos: list[Todo], tool_call_id: Annotated[str, InjectedToolCallId]
        ) -> Command[Any]:
            """Create and manage a structured task list for your current work session."""
            return Command(
                update={
                    "todos": todos,
                    "messages": [
                        ToolMessage(f"Updated todo list to {todos}", tool_call_id=tool_call_id)
                    ],
                }
            )

        self.tools = [write_todos]

Domain

Subdomains

Frequently Asked Questions

What does __init__() do?
__init__() is a function in the langchain codebase, defined in libs/langchain_v1/langchain/agents/middleware/todo.py.
Where is __init__() defined?
__init__() is defined in libs/langchain_v1/langchain/agents/middleware/todo.py at line 167.
What does __init__() call?
__init__() calls 1 function(s): write_todos.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free