Implement a ToDo List system for AI agents that manages tasks with various states and handles task dependencies. The problem starts simple but progressively adds complexity through multiple parts.
Given structure:
TaskStatus (Enum): States like READY, IN_PROGRESS, SUCCEEDED, FAILED, BLOCKED
Task (Class): Represents a single task
ToDoList (Class): Manages the collection of tasks
Key challenges:
Regression Testing: Each new part has independent test cases. Your code modifications must NOT break previous parts.
Code Volume: High implementation speed is required.
State Management: Properly handle cascading state updates through dependency chains.
There are multiple parts to this problem - ask the interviewer how many parts there are to better manage your time
Each part builds on the previous one while maintaining backward compatibility
Write your own test cases and ensure your code compiles and runs correctly
Implement the fundamental operations for task management.
add_task(task_id: str, description: str) -> Task
Create a new task with the given ID and description
Retrieve a task by its ID
Raise exception if task does not exist
update_status(task_id: str, new_status: TaskStatus) -> None
Update the status of an existing task
Raise exception if task does not exist
` todo_list = ToDoList()
task1 = todo_list.add_task("task1", "First task") print(task1.status) # TaskStatus.READY
retrieved = todo_list.get_task("task1") print(retrieved.task_id) # "task1"
todo_list.update_status("task1", TaskStatus.IN_PROGRESS) todo_list.update_status("task1", TaskStatus.SUCCEEDED) print(todo_list.get_task("task1").status) # TaskStatus.SUCCEEDED `
How should we handle same-task dependencies (task depending on itself)?
Should we validate state transitions (e.g., cannot go from SUCCEEDED to READY)?
What happens if we try to add a duplicate task ID?
Add support for task dependencies with cascading state management.
When updating a task's status, trigger cascading updates: