Fannie Mae and Freddie Mac are obligated to comply with recently enacted Massachusetts law requiring creditors to take commercially reasonable steps to avoid foreclosure, according to a letter to the GSEs conservator from state Attorney General Martha Coakley. The AGs Aug. 23 letter to Federal Housing Finance Agency Acting Director Edward DeMarco puts the agency on notice about a law signed Aug. 3 by Gov. Deval Patrick, D, An Act to Prevent Unnecessary and Unreasonable Foreclosures, which mandates loan modifications when they make economic sense.