Commit 405cfdc
authored
feat: add structural reform support for AI agent (#67)
* feat: add simulation_modifier field to Policy model
Stores Python code for structural reforms (custom variable formulas).
Includes database migration.
* feat: add structural reform support for AI agent
- 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.
* feat: add execute_python tool for agent to test modifier code
- 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
* test: add tests for structural reform and execute_python functionality
Tests for:
- Creating policies with simulation_modifier
- execute_python_code function (basic, error handling, modifier validation)
- PolicyRead including simulation_modifier field
* test: add integration tests for agent execute_python tool
- 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 modifiers1 parent 75315cc commit 405cfdc
File tree
15 files changed
+859
-53
lines changed- scripts
- src/policyengine_api
- api
- models
- supabase/migrations
- tests
15 files changed
+859
-53
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
223 | 223 | | |
224 | 224 | | |
225 | 225 | | |
226 | | - | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
227 | 229 | | |
228 | 230 | | |
229 | 231 | | |
| |||
626 | 628 | | |
627 | 629 | | |
628 | 630 | | |
629 | | - | |
| 631 | + | |
| 632 | + | |
| 633 | + | |
630 | 634 | | |
631 | 635 | | |
632 | 636 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
79 | 129 | | |
80 | 130 | | |
81 | 131 | | |
| |||
124 | 174 | | |
125 | 175 | | |
126 | 176 | | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
127 | 237 | | |
128 | 238 | | |
129 | 239 | | |
| |||
235 | 345 | | |
236 | 346 | | |
237 | 347 | | |
238 | | - | |
239 | | - | |
| 348 | + | |
240 | 349 | | |
241 | 350 | | |
242 | 351 | | |
| |||
268 | 377 | | |
269 | 378 | | |
270 | 379 | | |
271 | | - | |
272 | | - | |
273 | | - | |
274 | | - | |
275 | | - | |
276 | | - | |
277 | | - | |
278 | | - | |
279 | | - | |
280 | | - | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
281 | 392 | | |
282 | 393 | | |
283 | 394 | | |
| |||
347 | 458 | | |
348 | 459 | | |
349 | 460 | | |
350 | | - | |
| 461 | + | |
| 462 | + | |
| 463 | + | |
351 | 464 | | |
352 | 465 | | |
353 | 466 | | |
| |||
415 | 528 | | |
416 | 529 | | |
417 | 530 | | |
418 | | - | |
419 | | - | |
420 | | - | |
421 | | - | |
| 531 | + | |
| 532 | + | |
422 | 533 | | |
| 534 | + | |
423 | 535 | | |
424 | 536 | | |
425 | 537 | | |
| |||
466 | 578 | | |
467 | 579 | | |
468 | 580 | | |
| 581 | + | |
| 582 | + | |
| 583 | + | |
| 584 | + | |
| 585 | + | |
| 586 | + | |
469 | 587 | | |
470 | 588 | | |
471 | 589 | | |
| |||
477 | 595 | | |
478 | 596 | | |
479 | 597 | | |
480 | | - | |
481 | | - | |
482 | | - | |
483 | | - | |
484 | | - | |
| 598 | + | |
| 599 | + | |
| 600 | + | |
| 601 | + | |
| 602 | + | |
| 603 | + | |
| 604 | + | |
485 | 605 | | |
486 | 606 | | |
487 | 607 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
| |||
35 | 36 | | |
36 | 37 | | |
37 | 38 | | |
| 39 | + | |
38 | 40 | | |
39 | 41 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
| 27 | + | |
27 | 28 | | |
28 | 29 | | |
29 | 30 | | |
| |||
93 | 94 | | |
94 | 95 | | |
95 | 96 | | |
96 | | - | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
97 | 100 | | |
98 | 101 | | |
99 | 102 | | |
| |||
136 | 139 | | |
137 | 140 | | |
138 | 141 | | |
139 | | - | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
140 | 145 | | |
141 | | - | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
142 | 151 | | |
143 | 152 | | |
144 | 153 | | |
| |||
166 | 175 | | |
167 | 176 | | |
168 | 177 | | |
169 | | - | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
170 | 184 | | |
171 | 185 | | |
172 | 186 | | |
| |||
0 commit comments