Lesson 17: Todo and Task State Management
Empower agents to plan, track, and execute multi-step initiatives using structured todos with opt-in history compaction and loss markers.
1. Why This Feature Exists
Long-running agents often drift or lose track of subtasks. Attaching a TodoComponent gives the agent an explicit checklist that it updates during execution while preventing context window explosion through compaction.
2. Key Symbols and Exports
3. Implementation Walkthrough
import {
ProviderType,
resolveProvider,
initializeClient,
loadCredentials,
getDefaultModel
} from 'merci-sdk';
const PROVIDER = resolveProvider();
const { client } = await initializeClient({ provider: PROVIDER, options: loadCredentials({ provider: PROVIDER }) });
const session = client.session(getDefaultModel({ provider: PROVIDER }))
.withTodos();
const prompt = `
We need to refactor our user authentication module:
1. Audit current bcrypt password hashing.
2. Draft a migration script to Argon2id.
3. Update unit test suite.
Track progress using your todo tools.
`;
const result = await session.run(prompt);
console.log('Result:', result);4. Wire and Telemetry Mechanics
The SDK injects the current todo list state into the system message. Tool invocations for add_todo, update_todo, etc. update the internal store and emit 'todo:update' telemetry events.
5. Run the Example
Execute the runnable example directly from the repository root:
node examples/09_memory_and_todos.mjsRead the full example: examples/09_memory_and_todos.mjs →