Brad Pitt and Angelina Jolie are working out the terms of their divorce. (Photo: Steve Granitz/WireImage)

Brad Pitt and Angelina Jolie have agreed to a temporary custody deal that was laid down by the L.A. County Dept. of Children and Family Services, and it involves therapists and random drug testing.

Sources familiar with the situation tell us, DCFS has made its recommendations and Brad and Angelina had 2 options … agree or fight it out in court. We’re told they both agreed with DCFS.

Related: Brad Pitt’s Urine Test for DCFS Was Voluntary

Here are the terms of the temporary agreement:

– Angelina gets full physical custody of the 6 kids.

– Brad gets visitation, with strings attached. The initial visit is with a therapist present and the therapist then has the power to either allow Brad subsequent unmonitored visits or insist on being present whenever he’s around the kids.

– Brad is subject to random drug/alcohol testing. As we reported, Angelina believes Brad has issues with alcohol and weed. Our law enforcement sources say Brad’s first test was negative for drugs and alcohol.

– Brad and Angelina will each submit to individual counseling. In addition, Brad, Angelina and the kids will undergo family counseling together.

Related: Brangelina’s Prenup Is Clear — Splitting Properties Is No Biggie, But Kids Will Be

We’re told Angelina is happy with the agreement and her focus is to “heal” her family.

We’re told the agreement will only last for another 3 weeks. At that point DCFS could impose new ground rules or possibly turn the matter over to the courts.