Optionaloptions: TodoListMiddlewareOptionsA configured middleware instance that provides todo management capabilities
import { todoListMiddleware, createAgent } from 'langchain';
const agent = createAgent({
model: "openai:gpt-4o",
middleware: [todoListMiddleware()],
});
// Agent now has access to write_todos tool and todo state tracking
const result = await agent.invoke({
messages: [new HumanMessage("Help me refactor my codebase")]
});
console.log(result.todos); // Array of todo items with status tracking
Creates a middleware that provides todo list management capabilities to agents.
This middleware adds a
write_todostool that allows agents to create and manage structured task lists for complex multi-step operations. It's designed to help agents track progress, organize complex tasks, and provide users with visibility into task completion status.The middleware automatically injects system prompts that guide the agent on when and how to use the todo functionality effectively. It also enforces that the
write_todostool is called at most once per model turn, since the tool replaces the entire todo list and parallel calls would create ambiguity about precedence.