Molly: Making Large Language Model Agents Solve Python Problem More Logically