Implement `agent_planning_and_reasoning_module_2_problem_8` in Python. Test cases verify edge cases and functional requirements.
agent_planning_and_reasoning_module_2_problem_8(*args, **kwargs)