feat: AI policy analyst demo with Modal Sandbox#24
Merged
nikhilwoodruff merged 18 commits intomainfrom Dec 28, 2025
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 agentdemo_agent.py- Standalone agent for local testingapi/demo.py- FastAPI endpoints (/demo/ask,/demo/status/{job_id})policy-chat.tsx- React chat UI componentdocs/demo/page.tsx- Demo page in docsSetup required
Test plan
/demo/askendpoint with sample questions