Treaties are also pacts, and sometimes vice versa. Both are agreements.
Although both pacts and treaties are types of agreements, they are not separate, distinct types of agreement with no overlap.
Rather than being different things, substantial overlap occurs between pact and treaty, so there can be no right answer to your question about which one you “should” use.
A pact is merely an agreement between persons or parties, whether formal or informal. The word is often used loosely not specifically. The OED provides:
An agreement between persons or parties, a compact.
A treaty is specifically a signed contract between states with force of law behind it. The OED offers:
3b. spec. A contract between two or more states, relating to peace, truce, alliance, commerce, or other international relation; also, the document embodying such contract, in modern usage formally signed by plenipotentiaries appointed by the government of each state. (Now the prevailing sense.)
You’ll also find the related terms accord, concord, understanding, arrangement, understanding, charter, compact, convention, covenant, settlement used to describe agreements.
Again, do not think that these are all somehow different things applicable to only one situation each. Language is not math nor even computer programming, and it just does not work that way.
Treaties in Domestic Law versus International Law
You also need to consider how these terms are used in different sectors of the anglosphere. For example, the Wikipedia article on the Treaty Clause of the American Constitution explicitly points this out in the following text:
In the United States, the term "treaty" is used in a more restricted legal sense than in international law. U.S. law distinguishes what it calls treaties from congressional-executive agreements and sole-executive agreements. All three classes are considered treaties under international law; they are distinct only from the perspective of internal United States law. Distinctions among the three concern their method of ratification: by two-thirds of the Senate, by normal legislative process, or by the President alone, respectively. The Treaty Clause empowers the President to make or enter into treaties with the "advice and consent" of two-thirds of the Senate. In contrast, normal legislation becomes law after approval by simple majorities in both the Senate and the House of Representatives.
Throughout U.S. history, the President has also made international "agreements" through congressional-executive agreements (CEAs) that are ratified with only a majority from both houses of Congress, or sole-executive agreements made by the President alone.
Therefore if you are talking about formal agreements between the United States and other plenipotentiaries, be sensitive to what treaty means in that context.