The U.S. Securities and Exchange Commission's top inspector and examiner, Lori Richards, plans to leave the agency August 7, the SEC said on Wednesday.

Richards, director of the compliance inspections and examinations unit since it was created in 1995, leaves after a controversial year in which her division and the SEC enforcement unit were accused of failing to spot Bernard Madoff's $65 billion investment fraud.

The division was created under former Chairman Arthur Levitt and has been criticized for being unable to respond effectively to the changes on Wall Street.

Richards has spent more than two decades at the SEC in various capacities including administrator for the agency's enforcement program in Los Angeles and senior adviser to Levitt.

Richards, who will be taking some time to explore new opportunities, said she first started talking about leaving in May but wanted to stay to implement changes to her division.

Those changes include improving the tools available to examiners to detect fraud and improving surveillance and risk-based targeting, as well as examiners' training and expertise in fraud detection, among other things.

When asked whether any of the criticism played a part in her decision to leave, Richards said: Absolutely not.

I have been focused for 14 years on making the exam program as vigorous as it could possibly be to provide oversight of the securities industry, Richards said in an interview.

The division's associate director and chief counsel John Walsh will serve as its acting director when Richards leaves.

(Reporting by Rachelle Younglai, editing by Gerald E. McCormick)