feat: add structural reform support for AI agent#67
Merged
nikhilwoodruff merged 5 commits intomainfrom Jan 8, 2026
Merged
Conversation
Stores Python code for structural reforms (custom variable formulas). Includes database migration.
- Add simulation_modifier field to Policy model (stores Python code) - Update Modal functions to apply modifiers to simulations - Add agent upload endpoints for results (deciles, poverty, inequality) - Update agent system prompt with structural reform workflow - Database migration for policies.simulation_modifier column The agent can now write custom variable formulas via simulation modifiers and run them on UK/US economy simulations.
- Added execute_python tool that runs Python code in a sandbox - Updated system prompt to instruct agent to test modifiers before submitting - Agent can now validate syntax and logic before running expensive simulations
Tests for: - Creating policies with simulation_modifier - execute_python_code function (basic, error handling, modifier validation) - PolicyRead including simulation_modifier field
- Added dotenv loading to conftest.py for API keys - Added test_agent_uses_execute_python_tool - verifies agent can execute Python - Added test_agent_validates_modifier_code - verifies agent can validate modifiers
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 ability for the AI agent to write and run structural reforms (simulation modifiers) on UK/US simulations.
Closes #66
Changes
Data model:
simulation_modifierfield to Policy model for storing Python code defining custom variable formulasModal functions:
_get_pe_policy_*functions to return tuple of (policy, simulation_modifier)_apply_simulation_modifier()helper to execute modifier codeAgent upload endpoints (
/agent/results/*):POST /simulation- mark simulation completed/failedPOST /household- upload household calculation resultsPOST /decile-impact- upload decile impact dataPOST /program-statistics- upload program statisticsPOST /poverty- upload poverty metricsPOST /inequality- upload inequality metricsPOST /report-status- update report statusPOST /policy-with-modifier- create policy with simulation modifierAgent tools:
execute_pythontool so the agent can test modifier code before submittingAgent system prompt:
Example usage
The agent workflow for structural reforms:
Testing
Ran unit tests locally. Integration tests will run on CI.