Skip to content

feat: AI policy analyst demo with Modal Sandbox#24

Merged
nikhilwoodruff merged 18 commits intomainfrom
feat/demo-agent
Dec 28, 2025
Merged

feat: AI policy analyst demo with Modal Sandbox#24
nikhilwoodruff merged 18 commits intomainfrom
feat/demo-agent

Conversation

@nikhilwoodruff
Copy link
Copy Markdown
Contributor

Adds an interactive demo where users can ask natural language questions about tax/benefit policy and get AI-generated analysis reports.

The agent uses Claude Sonnet with tool calling to search for parameters, create policy reforms, run economic impact analyses, and generate markdown reports. Runs in a Modal function for isolated, scalable execution.

New files

  • demo_modal.py - Modal function with Claude agent
  • demo_agent.py - Standalone agent for local testing
  • api/demo.py - FastAPI endpoints (/demo/ask, /demo/status/{job_id})
  • policy-chat.tsx - React chat UI component
  • docs/demo/page.tsx - Demo page in docs

Setup required

modal secret create anthropic-api-key ANTHROPIC_API_KEY=sk-ant-...
modal deploy src/policyengine_api/demo_modal.py

Test plan

  • Deploy Modal function with Anthropic secret
  • Test /demo/ask endpoint with sample questions
  • Verify chat UI in docs site
  • Test full flow: question → parameter search → policy creation → economic impact → report

Establishes three-level API architecture:
- Level 0: Simulations (single-world snapshots)
- Level 1: Analyses (operations on simulations)
- Level 2: Reports (AI-generated documents, future)

Renames Modal functions to match hierarchy:
- calculate_household_* → simulate_household_*
- run_report_* → economy_comparison_*

Adds docs/DESIGN.md with full endpoint mapping to policyengine package functions.
Adds an interactive demo where users can ask natural language questions
about tax/benefit policy and get AI-generated analysis reports.

Components:
- demo_modal.py: Modal function running Claude agent with PE API tools
- demo_agent.py: Standalone agent script for local testing
- api/demo.py: FastAPI endpoint (/demo/ask, /demo/status)
- policy-chat.tsx: React chat component for docs
- docs/demo/page.tsx: Demo page in docs site

The agent uses Claude Sonnet with tool calling to:
1. Search for relevant parameters
2. Create policy reforms
3. Run economic impact analyses
4. Generate markdown reports

Requires Modal secret 'anthropic-api-key' to be configured.
- Replace custom tool-calling agent with actual Claude Code CLI
- Run in Modal sandbox with bun for package management
- Stream output via SSE to frontend chat UI
- Configure MCP server for PolicyEngine API access
- Add pytest-asyncio and 10 tests for Claude invocation
- Switch from mount_http to mount_sse for Claude Code compatibility
- Mount SSE endpoint at /mcp for better UX
- Add POLICYENGINE_API_URL to docker-compose for local testing
- Update policy-chat.tsx to parse stream-json format with:
  - MCP connection status indicator
  - Live tool call tracking with expandable details
  - Proper assistant message rendering
  - Final result display
When DEMO_USE_MODAL=false, run PolicyEngine calculations locally
instead of spawning Modal functions. Enables full local development
without Modal deployment.
- Add font-mono for code-style text rendering
- Add typing animation with green cursor
- Add react-markdown for proper markdown rendering in responses
@nikhilwoodruff nikhilwoodruff merged commit b9caaee into main Dec 28, 2025
1 check passed
@nikhilwoodruff nikhilwoodruff deleted the feat/demo-agent branch December 28, 2025 16:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant