OpenAI, the maker of ChatGPT, said on Friday that it had reached an agreement with the Pentagon to provide its artificial intelligence technologies for classified systems, just hours after President Trump ordered federal agencies to stop using A.I. technology made by rival Anthropic. Under the deal, OpenAI agreed to let the Pentagon use its A.I. systems for any lawful purpose. The San Francisco company also said it had found a way to ensure that its technologies would not be applied for domestic surveillance in the United States or with autonomous weapons by installing specific technical guardrails on its systems. But Anthropic said it needed terms that would ensure that its A.I. technology would not be used for domestic surveillance of Americans or for autonomous lethal weapons. The Pentagon, in turn, said a private contractor could not decide how its tools would be used for national security. Their disagreement erupted into public view this month and escalated as both dug in their heels.