Pact is a game-theoretic negotiation framework that moves beyond "polite" AI. By combining Large Language Models with formal International Relations theory, Pact simulates high-stakes environments where agents must maximise utility functions, manage "Audience Costs," and navigate the "Shadow of the Future."
Unlike standard chatbots, Pact agents have the mathematical freedom to defect, leading to emergent, realistic strategic behaviors.
- The Orchestration: Powered by FastAPI and LangGraph, utilising a "World State" where agents participate in a Recency-Penalised Urgency Auction to earn the right to speak.
-
The Strategy Layer: Implements six classic repeated Prisoner's Dilemma strategies:
- Tit-for-Tat: Reciprocal cooperation or retaliation.
- Grim Trigger: Permanent defection following the first betrayal.
- Zero-Determinant (ZD): Coercive strategies that unilaterally dictate the terms of cooperation.
-
The Utility Function: Agents calculate success based on:
$$U_i = (1 - \text{Tension}) \times (0.5 + 0.5 \times \delta)$$ Where $\delta$ represents the Shadow of the Future (discount factor).
Frontend: Next.js 16 (Turbopack) · Tailwind CSS 4 · shadcn/ui · Motion
Backend: FastAPI · LangGraph · Python 3.13+
# Install all dependencies
cd frontend
pnpm install
cd ../backend
uv sync# Launch the Nash Engine (Backend)
cd backend
uv run fastapi dev main.py# Launch the Strategic Dashboard (Frontend)
cd frontend
pnpm devThe simulation avoids "infinite loops" by monitoring a Consensus Threshold. If no agent’s Adjusted_Urgency exceeds 2.0, the Nash Engine declares a stable equilibrium and terminates the simulation.
To prevent "Diplomatic Drift," all treaties are managed via a rigorous JSON-based Proposal System. If the math behind a concession fails to align with an agent's BATNA (Best Alternative to Negotiated Agreement), the engine rejects the interaction at the protocol level before it reaches the chat interface.
frontend/ -> Next.js frontend (Strategic Dashboard)
├── app/ -> Next.js App Router
│ ├── simulate/ -> Simulation interface page
│ ├── vis/ -> Game tree visualisation page
│ └── page.tsx -> Home page
├── components/ui/ -> shadcn/ui visualisation components
├── lib/ -> Utility functions
└── types/ -> TypeScript type definitions
backend/ -> FastAPI (The Nash Engine & LangGraph state machine)
├── core/ -> Core constants and configuration
├── routers/ -> API endpoints (simulation_router.py)
├── services/ -> Business logic (LLM & simulation services)
├── engine.py -> Nash Engine core
├── schemas.py -> Pydantic data models
└── main.py -> FastAPI application entry point