A chat interface for the PolicyEngine agent. Ask questions about UK or US tax and benefit policy, calculate household impacts, and analyse economy-wide reforms.
- Bun runtime
- Modal account (for the agent)
- Supabase project (already deployed at
xieouadfboiipmwqrhyg)
- Install dependencies:
bun install- Create
.env.local(or use the existing one):
cp .env.local.example .env.local- Start the dev server:
bun devOpen http://localhost:3000 to use the chat.
The agent runs on Modal and stores logs in Supabase. To redeploy:
cd modal_agent
modal deploy agent.pyThe Modal function needs two secrets:
anthropic-api-key- your Anthropic API keypolicyengine-chat-supabase- Supabase URL and service key
| Variable | Description |
|---|---|
NEXT_PUBLIC_SUPABASE_URL |
Supabase API URL |
NEXT_PUBLIC_SUPABASE_ANON_KEY |
Supabase anonymous key |
SUPABASE_SERVICE_KEY |
Supabase service role key (server-side only) |
NEXT_PUBLIC_API_BASE_URL |
PolicyEngine API URL (default: https://v2.api.policyengine.org) |
Three tables:
- threads: Chat sessions with title and timestamps
- messages: User and assistant messages
- agent_logs: Streaming logs during agent execution
See supabase/migrations/001_initial.sql for the full schema.
┌─────────────┐ ┌──────────────┐ ┌─────────────┐
│ Next.js │────▶│ Modal │────▶│ Supabase │
│ Frontend │ │ Agent │ │ Database │
└─────────────┘ └──────────────┘ └─────────────┘
│ │ │
│ ▼ │
│ ┌──────────────┐ │
│ │ PolicyEngine │ │
│ │ API v2 │ │
│ └──────────────┘ │
│ │
└────────────────────────────────────────┘
(realtime updates)
- User sends message → saved to Supabase
- Next.js API spawns Modal agent
- Agent calls PolicyEngine API, streams logs to Supabase
- Agent saves final response to Supabase
- Frontend receives updates via Supabase realtime