Running a study#
AgenticRun is the entry point. It reads PROBLEM_STATEMENT.md from the study
directory, builds the agent graph, and runs the loop to a gated deliverable.
adda.AgenticRun
#
Run an agentic loop over a study directory.
The entry point of adda. It reads PROBLEM_STATEMENT.md from the study
directory, builds the agent graph, runs the strategizer's open loop to a
gated deliverable, and returns the final report. Configuration not passed
here is read from <study_dir>/config.yaml; explicit arguments win.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
study_dir
|
Path
|
Root of the study tree. Must contain |
required |
graph
|
Graph
|
Custom agent graph. Defaults to the built-in strategizer-hub graph. |
None
|
model
|
str
|
LLM model identifier. Defaults to |
None
|
budget
|
float
|
Wall-clock budget in seconds, or an |
None
|
budget_usd
|
float
|
Hard USD cost ceiling. Honoured only when the backend reports per-call
cost (the Claude backend); |
None
|
eval_budget
|
int
|
Soft cap on oracle evaluations across all delegations. Nudges the strategizer when approached; never stops a run on its own. |
None
|
interactive
|
bool
|
Whether the pre-run problem-statement review and in-graph FollowUp may prompt on stdin. Forced off automatically when there is no TTY, so a headless run never blocks on input. |
True
|
max_ask
|
int
|
Maximum number of clarifying questions the interactive review may ask. |
1
|
container
|
bool
|
Run the loop inside a container via |
False
|
container_image
|
str
|
Image used when |
"f3dasm-agentic:latest"
|
resume_from
|
Path
|
A prior run directory to resume from (replays the LangGraph checkpoint).
The run must have a |
None
|
review_statement
|
bool
|
Run the advisory pre-run problem-statement review. Never blocks an
autonomous run. |
None
|
runtime
|
dict
|
Explicit run knobs, overriding the study's |
None
|
Examples:
>>> from adda import AgenticRun
>>> report = AgenticRun(study_dir="studies/my_study").execute()
Source code in src/adda/_src/runtime/agent_runtime.py
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 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 | |
_study_runtime: dict = dict(cfg.get('runtime') or {})
class-attribute
instance-attribute
#
_runtime_override: dict = dict(runtime or {})
class-attribute
instance-attribute
#
study_dir = Path(study_dir).resolve()
instance-attribute
#
_base_url = cfg.get('base_url')
instance-attribute
#
_served_base_url: str | None = None
instance-attribute
#
_backend = _backend_cfg
instance-attribute
#
_model = model or cfg.get('model') or (DEFAULT_OLLAMA_MODEL if _backend_cfg == 'ollama' else DEFAULT_MODEL)
instance-attribute
#
_eval_budget = eval_budget if eval_budget is not None else cfg.get('eval_budget')
instance-attribute
#
_mem_cap_bytes = resolve_mem_cap_bytes(cfg.get('mem_cap'))
instance-attribute
#
_required_deliverables = cfg.get('required_deliverables') or []
instance-attribute
#
_budget = budget
instance-attribute
#
_budget_usd = budget_usd if budget_usd is not None else cfg.get('budget_usd')
instance-attribute
#
_graph_spec = graph or _default_graph()
instance-attribute
#
_node_tool_records = apply_node_config(self._graph_spec, cfg.get('nodes'))
instance-attribute
#
_interactive = bool(interactive) and getattr(_sys.stdin, 'isatty', lambda: False)()
instance-attribute
#
_max_ask = max_ask
instance-attribute
#
_container = container
instance-attribute
#
_container_image = container_image
instance-attribute
#
_resume_from = Path(resume_from) if resume_from is not None else None
instance-attribute
#
_review_statement = review_statement if review_statement is not None else cfg.get('review_statement', True)
instance-attribute
#
_run_dir = None
instance-attribute
#
_write_run_status(debug_dir: Path, **payload) -> None
staticmethod
#
Persist debug/run_status.json — the terminal status the §1 analysis
protocol reads FIRST. Written on every close (normal gate outcome, crash,
watchdog kill) so a run's outcome is always on disk, not only in the
notebook metadata + the longitudinal ledger. Best-effort: a status write
must never fail a run.
Source code in src/adda/_src/runtime/agent_runtime.py
351 352 353 354 355 356 357 358 359 360 361 362 363 364 | |
_maybe_start_slurm_llm(full_cfg, debug_dir, log)
#
Optionally own a vLLM server on a SLURM GPU node for this run.
Guarded by the llm_slurm.enabled config block. Submits a
vllm serve job (reusing f3dasm's SlurmCluster + the plain
sbatch submit idiom — a persistent server is not an eval array),
waits for the granted node and a ready server, then publishes
the endpoint on this run (_served_base_url) so the
vllm/openai-compatible adapters reach it over the cluster network. Returns the SLURM job id (for teardown) or None
when disabled.
No silent fallback: if the feature is enabled and the server cannot be brought up, this raises — a run the user asked to serve locally must not quietly fall back to a hosted API. The jobid is persisted to disk so the study watchdog can reap a leaked allocation even if this process dies.
Source code in src/adda/_src/runtime/agent_runtime.py
366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 | |
render_architecture(out_path: Path | str | None = None) -> Path
#
Render this run's agent graph — nodes, roles, tools, descriptions, edges — as a self-contained SVG and write it to disk.
Works before or after execute() (the graph is fixed at
construction). Default location: run_dir/debug/architecture.svg
once a run has started (self._run_dir set), else
study_dir/architecture.svg. Returns the path written.
Source code in src/adda/_src/runtime/agent_runtime.py
434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 | |
serve_viewer(host: str = '127.0.0.1', port: int = 8765, allow_network: bool = False) -> None
#
Launch the live web viewer for this study's runs
(blocking — run in a separate terminal/process from execute(),
the same way render_architecture() is a separate opt-in step,
never called automatically). Requires the viewer
optional-dependency group (pip install adda[viewer]); lazily
imported here so the core package never depends on Starlette.
Passes this run's own live Graph object (self._graph_spec)
straight through — no reconstruction needed, unlike the standalone
python -m adda.viewer <study-dir> CLI, which runs as a
separate process with no in-memory Graph and falls back to
recovering one from the study's own run.py/build_graph() (or
the stock default graph) instead.
Source code in src/adda/_src/runtime/agent_runtime.py
462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 | |
execute() -> str
#
Run the agentic loop; return the final report text.
Reads PROBLEM_STATEMENT.md from the study directory and passes it
as the initial user message to the entry node.
Three phases, in order: establish the run (:meth:_prepare_run — run
directory, canonical store, budgets, the state the graph starts from),
drive it (:meth:_invoke_graph), then record what happened
(:meth:_finalize_run — gate outcome, provenance, KPI row).
Source code in src/adda/_src/runtime/agent_runtime.py
486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 | |
_execute_in_container() -> str
#
Hand the whole run to ContainerRunner instead of running in-process.
Source code in src/adda/_src/runtime/agent_runtime.py
508 509 510 511 512 513 514 515 516 517 518 519 520 | |
_prepare_run() -> _RunContext
#
Everything that must exist before the graph is invoked.
Source code in src/adda/_src/runtime/agent_runtime.py
524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 | |
_resolve_run_dir() -> tuple[str, Path, Path | None]
#
This run's directory: a fresh timestamped one, or the one resumed.
getattr default: some tests build AgenticRun via new.
Source code in src/adda/_src/runtime/agent_runtime.py
649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 | |
_snapshot_problem_statement(debug_dir: Path, problem: str) -> tuple[str, str]
#
Freeze the statement this run answered; return (snapshot, live) hashes.
The live study_dir/PROBLEM_STATEMENT.md drifts between runs (a study is meant to be run once per statement; when it isn't, a human auditing a later run needs to see the statement THAT run actually answered, not whatever the file has since been edited to say). The notebook's Run metadata cell carries only the hash so a reader can confirm which snapshot matches; the snapshot is the recoverable copy.
Write-if-absent: a resumed run must keep its ORIGINAL snapshot, not overwrite it with whatever PROBLEM_STATEMENT.md says at resume time. The snapshot hash is derived from the SNAPSHOT's content, never re-read from the live file, so a resume's stamp always matches what this run actually answered even if PROBLEM_STATEMENT.md has since drifted.
The live hash is taken BEFORE the constraint-snapshot preamble
(budgets, elapsed time — always different between runs) is prepended to
problem, so a resume's "did PROBLEM_STATEMENT.md change" check
compares the same kind of content on both sides instead of always
reporting "changed" (BACKLOG #35).
Source code in src/adda/_src/runtime/agent_runtime.py
678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 | |
_ingest_pool(study_cfg: dict, canonical_cfg: dict) -> tuple[int, str] | None
#
Ingest a precomputed pool as D000 ground-truth rows.
Two sources, one ingestion path — D000 rows are never counted as evaluations (_resolve_delegation_evals runs only for real delegations D001+): evaluator.lookup.pool → pool IS the oracle (queried via LookupDataGenerator) AND training data. training_data → pool is ONLY training data; there is NO live oracle (e.g. surrogate-only studies where new evaluations cannot be run).
Returns a (level, message) pair for the run log, or None when there
is no pool. The log is not open yet at this point in the run.
Source code in src/adda/_src/runtime/agent_runtime.py
712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 | |
_open_run_log(debug_dir: Path, ts: str) -> tuple[logging.Logger, logging.Handler]
#
Open debug/run.log for this run.
Source code in src/adda/_src/runtime/agent_runtime.py
749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 | |
_anchor_start_time(debug_dir: Path, resume: Path | None) -> float
#
The run's wall-clock anchor, persisted in its OWN file.
For exactly the reason thread_id is: run_config.json is rewritten mid-run, so it cannot carry a start time. A resume MUST charge the wall time the run has already spent — re-anchoring to now makes every budget check, every constraint snapshot and the critic's run-adequacy judgement restart from zero, so a run that has been going for a day reports hours.
Source code in src/adda/_src/runtime/agent_runtime.py
766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 | |
_watch_default_node(name: str, adapter: Any, backend: str) -> None
#
Report what a Default node really received (informational only).
Source code in src/adda/_src/runtime/agent_runtime.py
789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 | |
_record_node_models(debug_dir: Path) -> None
#
Record which model/backend each node actually runs on.
The viewer cannot re-derive this: it reconstructs the graph by
re-executing the study's build_graph() in its OWN process, and a
graph whose composition depends on runtime state (an env var naming a
local endpoint, say) then rebuilds DIFFERENTLY there — silently
reporting the study's default model for a node the run actually put on
another one. Same principle as the delegation log and the
problem-statement snapshot: what a run did is a record, not something
recomputed later from inputs that have since changed.
Best-effort: a run must never fail over its own bookkeeping.
Source code in src/adda/_src/runtime/agent_runtime.py
810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 | |
_resolve_thread_id(debug_dir: Path, resume: Path | None) -> str
#
Stable thread_id, persisted so a crashed run can be resumed.
Resume reads it back; a fresh run mints and stores it. Its own file: run_config.json is rewritten mid-run.
Source code in src/adda/_src/runtime/agent_runtime.py
835 836 837 838 839 840 841 842 843 844 845 846 | |
_invoke_graph(ctx: _RunContext) -> dict
#
Build the graph and run it to termination against a disk checkpoint.
Source code in src/adda/_src/runtime/agent_runtime.py
850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 | |
_invoke_abandonable(graph: Any, graph_input: Any, ctx: _RunContext) -> Any
#
graph.invoke on a worker thread, so an interrupt still returns.
LangGraph joins its node threads while an exception unwinds out of
invoke. A node stuck in a call nobody can cancel (the strategizer
in Wait, joined on a delegation inside an LLM read) then held the run
open until that call came back. Here the calling thread only waits,
so Ctrl-C or a timeout reaches it at once.
Source code in src/adda/_src/runtime/agent_runtime.py
943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 | |
_abandon_graph(finished: threading.Event, ctx: _RunContext) -> None
#
Tell every node thread to stop, wait a bounded time, record the rest.
A thread cannot be killed safely. Each one ends itself at its next
tool call or wait loop (RunAbandoned); one stuck inside a model
call ends when that call returns.
Source code in src/adda/_src/runtime/agent_runtime.py
976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 | |
_ask_crashed_run_for_retrospective(ctx: _RunContext) -> bool
#
Resuming a run whose process was lost (its checkpoint is mid-flight):
when runtime.resume_close_with_retrospectives is on, wind the
resumed run down at once instead of continuing it, so the entry node
gives the retrospective the crash cost it. The run closes CRASHED.
Source code in src/adda/_src/runtime/agent_runtime.py
1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 | |
_resumed_graph_input(graph: Any, ctx: _RunContext) -> Any
#
What to feed a resumed graph: None to replay, or fresh input to re-run.
A run that reached a terminal Command(goto=END) — i.e. EVERY normal
close (GATED/UNGATED/FAILED all go through the same terminal branch in
the orchestrating node) — leaves the checkpoint with an empty .next.
LangGraph's invoke(None, config) on such a checkpoint is a genuine
no-op: no node re-runs, no new model call happens, it just hands back
the stale last_report verbatim (confirmed empirically: a minimal
StateGraph reproduction showed the node's own call counter never
incremented on a second invoke(None) against an already-END'd thread).
BACKLOG #34's resume_from guidance was silently useless for exactly the
runs it targeted (externally-stopped, therefore terminal) until this
fix — found because a "resumed" run replayed 19-hour-old cached text
and was mistaken for a live re-test of the same stop condition
(BACKLOG #35).
Only a genuinely mid-flight interruption (crash, kill — .next
non-empty, real pending tasks) should still use the plain invoke(None)
replay-from-checkpoint path. A terminal checkpoint needs FRESH input to
force real re-execution from the entry node (confirmed empirically too:
invoke() with new non-None input on an already-terminal thread DOES
re-run the node). The one case explicitly NOT worth resuming: the run
already closed cleanly (GATED, an accepted Done()) and
PROBLEM_STATEMENT.md hasn't changed since — there is nothing new to do,
so this refuses loudly rather than silently no-op or silently redo
finished work.
Source code in src/adda/_src/runtime/agent_runtime.py
1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 | |
_refresh_resumed_budgets(graph: Any, ctx: _RunContext) -> None
#
Re-seed budgets and start_time into a resumed checkpoint.
On resume, the checkpointed state still carries the OLD budgets and start_time. Re-seed them from this AgenticRun so a run that halted on a budget can actually make progress after the user raises it (cumulative token_totals persist in the checkpoint, so the spend-so-far is still counted against the new ceiling).
Source code in src/adda/_src/runtime/agent_runtime.py
1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 | |
_finalize_run(ctx: _RunContext, result: dict) -> str
#
Persist the run's outcome and provenance; return the report.
Source code in src/adda/_src/runtime/agent_runtime.py
1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 | |
_fallback_retrospective(run_dir: Path, reason: str | None = None) -> None
#
Ensure the graph's entry node has a retrospective, even if it never answered the post-Done exit interview.
feedback.py's _enter_retrospective_round (called on every
UNGATED/FAILED close, and after a critic PASS) sets
node._awaiting_retro and asks for ONE more Done() call carrying a
### Retrospective block — but nothing enforces that the reply
actually arrives. A model that answers in prose instead just ends the
turn, the graph reaches END, and the record is silently lost (run
20260920T005201, studies/tube_buckling_sensitivity: closed UNGATED
with 2 worker retrospectives on disk and none from the strategizer).
The same gap exists on the CRASH path (_invoke_graph's
except BaseException around graph.invoke): a
GraphRecursionError/KeyboardInterrupt/OOM never reaches this method's
normal call site in _finalize_run either, so that path calls this
directly, with its own reason, right before re-raising.
This is the code-level guarantee CLAUDE.md §2 calls for instead of a
prompt rule: capture, don't request. It is idempotent
(write_fallback_retrospective's skip_if_present) so a
compliant close — the real entry lands via
FeedbackTools._capture_retrospective before this ever runs — is a
no-op here, never a duplicate.
Best-effort: never raises, so it can't break a run's close (or mask the exception on the crash path, which wraps this call in its own try/except too, belt-and-suspenders).
Source code in src/adda/_src/runtime/agent_runtime.py
1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 | |
_sweep_open_reviews(run_dir: Path) -> None
#
A small close-time status update for any delegation still OPEN-FOR-REVIEW (spec 12, peer_interaction, edge 2).
The HONEST, durable record is actually written much earlier, at
the review's own OPEN, not here: WorkerSession._open_for_review
appends an OPEN_FOR_REVIEW delegation-log row the instant the
report exists, so a crash or a watchdog kill with no code running
on the way out still leaves that row as the delegation's LAST one
on disk -- exactly what a post-mortem reader needs (see
write_watchdog_retrospective). This method exists only for
the compliant-close case: it appends ONE MORE row (last-wins
collapse, same convention as RUNNING -> DONE) recording that the
run ended before anyone approved it, and notes it in the
delegating node's retrospective too. Done(), the watchdog
(were an in-process one to exist), or a budget/backstop cutoff
can all reach this on the NORMAL close path; the crash path calls
it too (see the except BaseException in _invoke_graph).
Iterates self._live_nodes -- populated by build_graph as
it constructs each Node, an explicit reference this class owns,
not LangGraph's own compiled-graph internals (a prior version of
this method read compiled.nodes[name].bound.func, silently
able to break on any LangGraph upgrade). A node this genuinely
cannot reach is recorded as a diagnostic, not silently skipped.
Source code in src/adda/_src/runtime/agent_runtime.py
1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 | |
_record_sweep_failure(run_dir: Path, node_name: str, exc: Exception) -> None
staticmethod
#
The open-review sweep could not read one node's registry -- recorded as a diagnostic (never silently skipped), so a reader knows the sweep may be incomplete rather than assuming it covered every node.
Source code in src/adda/_src/runtime/agent_runtime.py
1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 | |
_record_unapproved_review(node: Any, delegation_id: str, entry: dict) -> None
staticmethod
#
One OPEN-FOR-REVIEW delegation's honest close-out record.
Source code in src/adda/_src/runtime/agent_runtime.py
1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 | |
_warn_if_externally_stopped(report: str, ctx: _RunContext) -> str | None
#
Name an external stop cause in the log, with resume guidance.
Source code in src/adda/_src/runtime/agent_runtime.py
1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 | |
_ledgered_eval_count(ctx: _RunContext, result: dict) -> int
#
Authoritative eval count = provenance-stamped rows in the ledger.
NOT the run-state counter: evals_used is summed from a registry that clears Done entries on loop-back, so it under-reports (0) on any run that re-prompts (e.g. every UNGATED run). The ledger never loses rows — and it also captures cancelled-but-completed delegations whose evals are real. Summed across the canonical store AND every design namespace (Axis 3a): namespace evals live in sibling stores the canonical-only count missed (run 20260627T013812 reported 100 while 200 real evals ran).
Source code in src/adda/_src/runtime/agent_runtime.py
1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 | |
_run_metadata_markdown(ctx: _RunContext, result: dict, gate_outcome: str, evals: int, tokens: dict, now_ts: str, elapsed: float) -> str
#
Run metadata + token table — provenance appended to the deliverable.
Source code in src/adda/_src/runtime/agent_runtime.py
1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 | |
_stamp_notebook_provenance(ctx: _RunContext, meta_md: str, gate_outcome: str, now_ts: str) -> Path
#
Stamp run provenance into pipeline.ipynb; return its path.
The agent-authored pipeline.ipynb IS the deliverable (its leading markdown cells hold the writeup). There is no solution.md — provenance goes in as a trailing metadata cell + notebook metadata.
Source code in src/adda/_src/runtime/agent_runtime.py
1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 | |
_append_kpi_ledger(ctx: _RunContext) -> None
#
Append a KPI row to the longitudinal ledger (best effort).
The extraction logic lives in studies/run_ledger.py (the one source of truth, writing studies/run_ledger.csv); we invoke it as a subprocess when present so a run is always recorded without a manual step. Absent (e.g. a non-studies install) → silently skipped.
Source code in src/adda/_src/runtime/agent_runtime.py
1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 | |
_review_problem_statement(problem: str, debug_dir: Path, *, adapter=None) -> str
#
Advisory pre-run well-posedness review (Item B).
Always writes debug/problem_statement_review.md. When the run is
interactive and gaps are found, offers a per-gap refine via the same
input() channel the in-graph FollowUp uses, appending accepted
clarifications to the statement (and to a saved addendum). Returns the
(possibly augmented) problem text. NEVER blocks an autonomous run: any
reviewer failure falls back to the original statement unchanged.
Source code in src/adda/_src/runtime/agent_runtime.py
1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 | |
_team_roster(name: str) -> str
#
This run's agents, read off the live graph: one list, the same for
every agent, closed by the one line that differs ("You are
Generated, not typed — the same reason render_tool_catalog is
generated. The static strategizer prompt describes a full cast and
once designated "the general implementer" as the fallback for any
block no specialist matches; run a two-node graph, or an ablation arm
that drops a node, and that fallback names an agent which does not
exist. A campaign logged 15 delegations to an absent 'implementer'.
Lists the nodes REACHABLE from the entry, in edge-declaration order, each with who hands it work and who IT may hand work to. A node declared but wired to nothing is left out: listing it would be a name an agent can see but not reach. Returns "" for a graph of one node, which has no one to name.
Topology, not prose, is what fixes a specific failure (run 20260927T034538, Elvis's diagnosis): a strategizer reasoned "no MATLAB specialist... implementer is for f3dasm pipelines" and did a MATLAB implementation task itself rather than delegating it. The outgoing edge ("delegates to: ...") is GENERATED from the live graph, so it can never go stale the way hand-written prose can.
Deliberately NOT a per-node tool list (an earlier draft added one,
generated via a throwaway Node construction against a stub
adapter — see git history if that mechanism is ever needed again):
Elvis's call was that generality beats exhaustiveness here — a full
tool enumeration is exactly the kind of detail an agent should not
need memorized from a roster to reason about what a peer can do.
description stays short and general on purpose, capability not
domain, and is shown after the objective topology facts, not in
place of them.
Source code in src/adda/_src/runtime/agent_runtime.py
1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 | |
_resource_stanza(run_dir, *, for_worker: bool) -> str
#
The static resource-envelope stanza — "what you HAVE" — injected into a worker/strategizer preamble at delegation start, so the agent stops running-and-hoping. O(1): cpu_count + one statvfs (no directory walk). Empty string on any failure (never fatal).
ROLE-AWARE parallelism (deliberate): the cores/RAM/disk facts are shared, but only the WORKER is primed to parallelize — and only its EVALUATIONS within a campaign (compute speedup, same experiment/budget, epistemically neutral). The strategizer is NOT resource-nudged to fan out experiments: running multiple arms concurrently is an experimental-design decision with epistemic weight (budget splits, comparison validity) that lives in its own guidance — resource-priming it nudges breadth over disciplined comparison (observed run 20260628T224159: a 3-arm, unequal-budget, INCONCLUSIVE run).
Source code in src/adda/_src/runtime/agent_runtime.py
1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 | |
_kb_menu(role, agent=None) -> str
#
Audience-filtered handbook MENU injected at the head of an agent's
prompt — so it always SEES the latent knowledge it can pull (mirroring
how it always sees its tool list), instead of only discovering a chapter
if it already thought to call ConsultHandbook. Cached; empty on failure.
Empty too for a node whose nodes: list withholds ConsultHandbook: a
menu that names a tool the node lacks is a prompt-vs-tool contradiction.
Source code in src/adda/_src/runtime/agent_runtime.py
1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 | |
_resolve_base_url(name: str, agent: Agent, adapter_cls) -> str | None
#
The endpoint a node's adapter uses: node config, then the top-level
config, then this run's SLURM-served server; None leaves the
adapter's own env/default. A node-level URL on a backend with no
endpoint is an error; the run-wide ones apply only where one exists.
Source code in src/adda/_src/runtime/agent_runtime.py
1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 | |
_make_adapter(name: str, agent: Agent)
#
Source code in src/adda/_src/runtime/agent_runtime.py
1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 | |
adda.AgenticRunError
#
Raised when an agentic run fails unrecoverably.
Source code in src/adda/_src/runtime/run_setup.py
74 75 | |
adda.DEFAULT_MODEL = 'claude-haiku-4-5-20251001'
module-attribute
#
Using a run as an f3dasm optimizer#
AgenticOptimizerAdapter wraps a whole agentic run behind the standard
f3dasm Optimizer interface, so it can be dropped in anywhere a regular
optimizer is used.
adda.AgenticOptimizerAdapter
#
Wraps an agentic run AS an f3dasm Optimizer (agentic-as-optimizer adapter).
Backed by :class:~agent_runtime.AgenticRun.
Implements the standard forward(ExperimentData) -> ExperimentData
interface so it can be used anywhere a regular f3dasm Optimizer is
used — including as a subject of ADAS-style meta-search.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
study_dir
|
Path
|
Root of the study tree. Must contain |
required |
**kwargs
|
Any
|
Forwarded to :class: |
{}
|
Source code in src/adda/_src/runtime/optimizer.py
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | |
_run = AgenticRun(study_dir, **kwargs)
instance-attribute
#
forward(data: Any) -> Any
#
Run the agentic loop and return data with updated outputs.
Serialises open jobs in data into the study workspace, calls
:meth:~agent_runtime.AgenticRun.execute, and reads results back
into data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
data
|
ExperimentData
|
f3dasm experiment data containing open (pending) evaluation jobs. |
required |
Returns:
| Type | Description |
|---|---|
ExperimentData
|
The same object with agent-produced outputs filled in. |
Raises:
| Type | Description |
|---|---|
NotImplementedError
|
The serialisation contract (how open jobs are passed to agents and how outputs are read back) is not yet implemented. |
Source code in src/adda/_src/runtime/optimizer.py
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | |