Python modules and classes¶
This page is generated from inline docstrings via mkdocstrings. The sections below are grouped by package or client.
packages/mewbo_core (core runtime)¶
mewbo_core.loop.orchestrator
¶
Session orchestration entrypoint.
Orchestrator
¶
Unified tool-use orchestration loop.
Source code in packages/mewbo_core/src/mewbo_core/loop/orchestrator.py
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 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 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 | |
__init__(*, model_name: str | None = None, fallback_models: tuple[str, ...] | None = None, session_store: SessionStoreBase | None = None, tool_registry: ToolRegistry | None = None, permission_policy: PermissionPolicy | None = None, approval_callback: Callable[[ActionStep], bool] | None = None, hook_manager: HookManager | None = None, cwd: str | None = None, session_step_budget: int = 0, system_instructions_store: SystemInstructionsStoreBase | None = None, session_mcp_servers: dict[str, dict] | None = None) -> None
¶
Initialize orchestration dependencies.
session_mcp_servers are MCP servers a caller attaches to THIS run, in
the standard {name: {command|url, …}} config shape. They are merged
into the registry build below alongside the plugin-contributed ones, and
their discovered tool ids are admitted through this run's
allowed_tools (:meth:_session_mcp_tool_ids).
It is deliberately NOT named extra_mcp_servers, even though that is
the parameter it feeds. The two carry different grants, and reusing one
name for both senses is the trap the house rules name outright: a
plugin-contributed server's tools are subject to allowed_tools like
any other registry tool, while a server named HERE is admitted by the act
of naming it — the caller attaching a server for one run IS the grant, and
it has no other way to express one, since a server's tool ids are not
knowable until discovery has run. Widening the existing parameter's
meaning instead would silently admit every plugin server's tools into
every scoped session in the deployment.
Discovery is a network/subprocess cost and it belongs HERE rather than at whichever caller assembled the config: this constructor already runs on the background run thread, which is the offline side of the acceptance/execution boundary. A caller resolving the ids itself would be paying for discovery on its own request path.
Source code in packages/mewbo_core/src/mewbo_core/loop/orchestrator.py
132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 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 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 | |
arun(user_query: str, *, max_iters: int = 3, initial_plan: Plan | None = None, return_state: bool = False, session_id: str | None = None, mode: str | None = None, should_cancel: Callable[[], bool] | None = None, allowed_tools: list[str] | None = None, denied_tools: list[str] | None = None, strict_tool_scope: bool = False, capability_mode: str = 'all', skill_instructions: str | None = None, message_queue: queue.Queue[str] | None = None, interrupt_step: threading.Event | None = None, user_id: str | None = None, source_platform: str | None = None, invocation_id: str | None = None, extra_session_tools: list[SessionTool] | None = None, enable_skills: bool = True, project_autoselect: bool = False, attachments: list[dict] | None = None, user_turn_persisted: bool = False) -> TaskQueue | tuple[TaskQueue, OrchestrationState]
async
¶
Run orchestration asynchronously (async-first entry point).
Awaits the orchestration coroutine directly, so an environment that
already owns a running event loop (browser-hosted Pyodide's WebLoop,
async test harnesses) can drive a query with native await and NO
nested asyncio.run. The sync :meth:run wrapper is the CPython
entry point and delegates here; the two share this single body.
Source code in packages/mewbo_core/src/mewbo_core/loop/orchestrator.py
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 | |
run(user_query: str, *, max_iters: int = 3, initial_plan: Plan | None = None, return_state: bool = False, session_id: str | None = None, mode: str | None = None, should_cancel: Callable[[], bool] | None = None, allowed_tools: list[str] | None = None, denied_tools: list[str] | None = None, strict_tool_scope: bool = False, capability_mode: str = 'all', skill_instructions: str | None = None, message_queue: queue.Queue[str] | None = None, interrupt_step: threading.Event | None = None, user_id: str | None = None, source_platform: str | None = None, invocation_id: str | None = None, extra_session_tools: list[SessionTool] | None = None, enable_skills: bool = True, project_autoselect: bool = False, attachments: list[dict] | None = None, user_turn_persisted: bool = False) -> TaskQueue | tuple[TaskQueue, OrchestrationState]
¶
Run orchestration for a session (sync wrapper around :meth:arun).
Backward-compatible synchronous entry point for CLI / API request
threads / tests. Owns the event-loop lifecycle via asyncio.run, so
every existing sync caller behaves exactly as before. Environments that
already drive an event loop (browser-hosted Pyodide's WebLoop) must call
:meth:arun instead — it awaits the same body with NO nested
asyncio.run (the "WebLoop wall").
Source code in packages/mewbo_core/src/mewbo_core/loop/orchestrator.py
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 | |
mewbo_core.loop.task_master
¶
Task planning and orchestration loop for Mewbo.
generate_action_plan(user_query: str, model_name: str | None = None, tool_registry: ToolRegistry | None = None, session_summary: str | None = None, recent_events: list[EventRecord] | None = None, selected_events: list[EventRecord] | None = None, *, mode: str = 'act', feedback: str | None = None) -> Plan
¶
Generate a plan for a user query.
Source code in packages/mewbo_core/src/mewbo_core/loop/task_master.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | |
orchestrate_session(user_query: str, model_name: str | None = None, fallback_models: tuple[str, ...] | None = None, max_iters: int = 3, initial_plan: Plan | None = None, return_state: bool = False, session_id: str | None = None, session_store: SessionStoreBase | None = None, tool_registry: ToolRegistry | None = None, permission_policy: PermissionPolicy | None = None, approval_callback: Callable[[ActionStep], bool] | None = None, hook_manager: HookManager | None = None, mode: str | None = None, should_cancel: Callable[[], bool] | None = None, allowed_tools: list[str] | None = None, denied_tools: list[str] | None = None, strict_tool_scope: bool = False, capability_mode: str = 'all', skill_instructions: str | None = None, message_queue: queue.Queue[str] | None = None, interrupt_step: threading.Event | None = None, cwd: str | None = None, session_step_budget: int = 0, user_id: str | None = None, source_platform: str | None = None, invocation_id: str | None = None, extra_session_tools: list[SessionTool] | None = None, enable_skills: bool = True, project_autoselect: bool = False, attachments: list[dict] | None = None, user_turn_persisted: bool = False, session_mcp_servers: dict[str, dict] | None = None) -> TaskQueue | tuple[TaskQueue, OrchestrationState]
¶
Run the orchestration loop synchronously.
Thin sync wrapper over :func:orchestrate_session_async — mirrors
Orchestrator.run() = asyncio.run(self.arun(...)) one layer up, so
there is exactly one place (here) that constructs the Orchestrator
and forwards every kwarg for both the sync and async entry points.
Source code in packages/mewbo_core/src/mewbo_core/loop/task_master.py
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 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 | |
orchestrate_session_async(user_query: str, model_name: str | None = None, fallback_models: tuple[str, ...] | None = None, max_iters: int = 3, initial_plan: Plan | None = None, return_state: bool = False, session_id: str | None = None, session_store: SessionStoreBase | None = None, tool_registry: ToolRegistry | None = None, permission_policy: PermissionPolicy | None = None, approval_callback: Callable[[ActionStep], bool] | None = None, hook_manager: HookManager | None = None, mode: str | None = None, should_cancel: Callable[[], bool] | None = None, allowed_tools: list[str] | None = None, denied_tools: list[str] | None = None, strict_tool_scope: bool = False, capability_mode: str = 'all', skill_instructions: str | None = None, message_queue: queue.Queue[str] | None = None, interrupt_step: threading.Event | None = None, cwd: str | None = None, session_step_budget: int = 0, user_id: str | None = None, source_platform: str | None = None, invocation_id: str | None = None, extra_session_tools: list[SessionTool] | None = None, enable_skills: bool = True, project_autoselect: bool = False, attachments: list[dict] | None = None, user_turn_persisted: bool = False, session_mcp_servers: dict[str, dict] | None = None) -> TaskQueue | tuple[TaskQueue, OrchestrationState]
async
¶
Run the orchestration loop on an already-running event loop.
Async mirror of :func:orchestrate_session for environments (Pyodide's
WebLoop, async test harnesses) where asyncio.run cannot be used because
the loop is already active. Same signature and semantics as the sync entry
point — it awaits :meth:Orchestrator.arun instead of calling
:meth:Orchestrator.run, so no nested asyncio.run is created.
Source code in packages/mewbo_core/src/mewbo_core/loop/task_master.py
162 163 164 165 166 167 168 169 170 171 172 173 174 175 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 237 238 | |
mewbo_core.loop.tool_use_loop
¶
Async tool-use conversation loop with sub-agent support.
ResilienceNote
dataclass
¶
Bounded, factual record of this run's LLM retry/fallback events.
The model is otherwise BLIND to its own retries: RetryStrategy.run has
only two outward channels — emit (event log / console / CLI) and
raise — and never touches the message list, so a run that quietly
re-drives a failing model, or escalates down its ladder, never sees any of
it. This note carries the SAME grounded facts the event log already holds —
which model was tried, how many attempts, the error class, whether a switch
occurred — into a dedicated system-prompt slot.
Holds only the most recent max_events records (hot in-process runtime
state — a plain dataclass, no trust boundary). :meth:render returns the
whole note, or "" when nothing has gone wrong yet, so a clean run pays
nothing and the slot stays empty.
Source code in packages/mewbo_core/src/mewbo_core/loop/tool_use_loop.py
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 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 | |
record(event: Event) -> None
¶
Append a compact summary for a retry/fallback event; ignore the rest.
Source code in packages/mewbo_core/src/mewbo_core/loop/tool_use_loop.py
175 176 177 178 179 180 181 182 183 | |
render() -> str
¶
The full note text, or "" when no resilience event has occurred.
Source code in packages/mewbo_core/src/mewbo_core/loop/tool_use_loop.py
199 200 201 202 203 204 | |
ToolBatch
dataclass
¶
A batch of tool calls with shared concurrency mode.
Source code in packages/mewbo_core/src/mewbo_core/loop/tool_use_loop.py
330 331 332 333 334 335 | |
ToolCallResult
dataclass
¶
Result of executing a single tool call.
Source code in packages/mewbo_core/src/mewbo_core/loop/tool_use_loop.py
306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 | |
ToolUseLoop
¶
Async tool-use conversation loop.
Each instance owns one conversation with one LLM. Sub-agents are
created by spawning new ToolUseLoop instances via the
spawn_agent internal tool.
Source code in packages/mewbo_core/src/mewbo_core/loop/tool_use_loop.py
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 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 2945 2946 2947 2948 2949 2950 2951 2952 2953 2954 2955 2956 2957 2958 2959 2960 2961 2962 2963 2964 2965 2966 2967 2968 2969 2970 2971 2972 2973 2974 2975 2976 2977 2978 2979 2980 2981 2982 2983 2984 2985 2986 2987 2988 2989 2990 2991 2992 2993 2994 2995 2996 2997 2998 2999 3000 3001 3002 3003 3004 3005 3006 3007 3008 3009 3010 3011 3012 3013 3014 3015 3016 3017 3018 3019 3020 3021 3022 3023 3024 3025 3026 3027 3028 3029 3030 3031 3032 3033 3034 3035 3036 3037 3038 3039 3040 3041 3042 3043 3044 3045 3046 3047 3048 3049 3050 3051 3052 3053 3054 3055 3056 3057 3058 3059 3060 3061 3062 3063 3064 3065 3066 3067 3068 3069 3070 3071 3072 3073 3074 3075 3076 3077 3078 3079 3080 3081 3082 3083 3084 3085 3086 3087 3088 3089 3090 3091 3092 3093 3094 3095 3096 3097 3098 3099 3100 3101 3102 3103 3104 3105 3106 3107 3108 3109 3110 3111 3112 3113 3114 3115 3116 3117 3118 3119 3120 3121 3122 3123 3124 3125 3126 3127 3128 3129 3130 3131 3132 3133 3134 3135 3136 3137 3138 3139 3140 3141 3142 3143 3144 3145 3146 3147 3148 3149 3150 3151 3152 3153 3154 3155 3156 3157 3158 3159 3160 3161 3162 3163 3164 3165 3166 3167 3168 3169 3170 3171 3172 3173 3174 3175 3176 3177 3178 3179 3180 3181 3182 3183 3184 3185 3186 3187 3188 3189 3190 3191 3192 3193 3194 3195 3196 3197 3198 3199 3200 3201 3202 3203 3204 3205 3206 3207 3208 3209 3210 3211 3212 3213 3214 3215 3216 3217 3218 3219 3220 3221 3222 3223 3224 3225 3226 3227 3228 3229 3230 3231 3232 3233 3234 3235 3236 3237 3238 3239 3240 3241 3242 3243 3244 3245 3246 3247 3248 3249 3250 3251 3252 3253 3254 3255 3256 3257 3258 3259 3260 3261 3262 3263 3264 3265 3266 3267 3268 3269 3270 3271 3272 3273 3274 3275 3276 3277 3278 3279 3280 3281 3282 3283 3284 3285 3286 3287 3288 3289 3290 3291 3292 3293 3294 3295 3296 3297 3298 3299 3300 3301 3302 3303 3304 3305 3306 3307 3308 3309 3310 3311 3312 3313 3314 3315 3316 3317 3318 3319 3320 3321 3322 3323 3324 3325 3326 3327 3328 3329 3330 3331 3332 3333 3334 3335 3336 3337 3338 3339 3340 3341 3342 3343 3344 3345 3346 3347 3348 3349 3350 3351 3352 3353 3354 3355 3356 3357 3358 3359 3360 3361 3362 3363 3364 3365 3366 3367 3368 3369 3370 3371 3372 3373 3374 3375 3376 3377 3378 3379 3380 3381 3382 3383 3384 3385 3386 3387 3388 3389 3390 3391 3392 3393 3394 3395 3396 3397 3398 3399 3400 3401 3402 3403 3404 3405 3406 3407 3408 3409 3410 3411 3412 3413 3414 3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 3498 3499 3500 3501 3502 3503 3504 3505 3506 3507 3508 3509 3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 3586 3587 3588 3589 3590 3591 3592 3593 3594 3595 3596 3597 3598 3599 3600 3601 3602 3603 3604 3605 3606 3607 3608 3609 3610 3611 3612 3613 3614 3615 3616 3617 3618 3619 3620 3621 3622 3623 3624 3625 3626 3627 3628 3629 3630 3631 3632 3633 3634 3635 3636 3637 3638 3639 3640 3641 3642 3643 3644 3645 3646 3647 3648 3649 3650 3651 3652 3653 3654 3655 3656 3657 3658 3659 3660 3661 3662 3663 3664 3665 3666 3667 3668 3669 3670 3671 3672 3673 3674 3675 3676 3677 3678 3679 3680 3681 3682 3683 3684 3685 3686 3687 3688 3689 3690 3691 3692 3693 3694 3695 3696 3697 3698 3699 3700 3701 3702 3703 3704 3705 3706 3707 3708 3709 3710 3711 3712 3713 3714 3715 3716 3717 3718 3719 3720 3721 3722 3723 3724 3725 3726 3727 3728 3729 3730 3731 3732 3733 3734 3735 3736 3737 3738 3739 3740 3741 3742 3743 3744 3745 3746 3747 3748 3749 3750 3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 4245 4246 4247 4248 4249 4250 4251 4252 4253 4254 4255 4256 4257 4258 4259 4260 4261 4262 4263 4264 4265 4266 4267 4268 4269 4270 4271 4272 4273 4274 4275 4276 4277 4278 4279 4280 4281 4282 4283 4284 4285 4286 4287 4288 4289 4290 4291 4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 4311 4312 4313 4314 4315 4316 4317 4318 4319 4320 4321 4322 4323 4324 4325 4326 4327 4328 4329 4330 4331 4332 4333 4334 4335 4336 4337 4338 4339 4340 4341 4342 4343 4344 4345 4346 4347 4348 4349 4350 4351 4352 4353 4354 4355 4356 4357 4358 4359 4360 4361 4362 4363 4364 4365 4366 4367 4368 4369 4370 4371 4372 4373 4374 4375 4376 4377 4378 4379 4380 4381 4382 4383 4384 4385 4386 4387 4388 4389 4390 4391 4392 4393 4394 4395 4396 4397 4398 4399 4400 4401 4402 4403 4404 4405 4406 4407 4408 4409 4410 4411 4412 4413 4414 4415 4416 4417 4418 4419 4420 4421 4422 4423 4424 4425 4426 4427 4428 4429 4430 4431 4432 4433 4434 4435 4436 4437 4438 4439 4440 4441 4442 4443 4444 4445 4446 4447 4448 4449 4450 4451 4452 4453 4454 4455 4456 4457 4458 4459 4460 4461 4462 4463 4464 4465 4466 4467 4468 4469 4470 4471 4472 4473 4474 4475 4476 4477 4478 4479 4480 4481 4482 4483 4484 4485 4486 4487 4488 4489 4490 4491 4492 4493 4494 4495 4496 4497 4498 4499 4500 4501 4502 4503 4504 4505 4506 4507 4508 4509 4510 4511 4512 4513 4514 4515 4516 4517 4518 4519 4520 4521 4522 4523 4524 4525 4526 4527 4528 4529 4530 4531 4532 4533 4534 4535 4536 4537 4538 4539 4540 4541 4542 4543 4544 4545 4546 4547 4548 4549 4550 4551 4552 4553 4554 4555 4556 4557 4558 4559 4560 4561 4562 4563 4564 4565 4566 4567 4568 4569 4570 4571 4572 4573 4574 4575 4576 4577 4578 4579 4580 4581 4582 4583 4584 4585 4586 4587 4588 4589 4590 4591 4592 4593 4594 4595 4596 4597 4598 4599 4600 4601 4602 4603 4604 4605 4606 4607 4608 4609 4610 4611 4612 4613 4614 4615 4616 4617 4618 4619 4620 4621 4622 4623 4624 4625 4626 4627 4628 4629 4630 4631 4632 4633 4634 4635 4636 4637 4638 4639 4640 4641 4642 4643 4644 4645 4646 4647 4648 4649 4650 4651 4652 4653 4654 4655 4656 4657 4658 4659 4660 4661 4662 4663 4664 4665 4666 4667 4668 4669 4670 4671 4672 4673 4674 4675 4676 4677 4678 4679 4680 4681 4682 4683 4684 4685 4686 4687 4688 4689 4690 4691 4692 4693 4694 4695 4696 4697 4698 4699 4700 4701 4702 4703 4704 4705 4706 4707 4708 4709 4710 4711 4712 4713 4714 4715 4716 4717 4718 4719 4720 4721 4722 4723 4724 4725 4726 4727 4728 4729 4730 4731 4732 4733 4734 4735 4736 4737 4738 4739 4740 4741 4742 4743 4744 4745 4746 4747 4748 4749 4750 4751 4752 4753 4754 4755 4756 4757 4758 4759 4760 4761 4762 4763 4764 4765 4766 4767 4768 4769 4770 4771 4772 4773 4774 4775 4776 4777 4778 4779 4780 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 | |
active_model: str
property
¶
The model this loop last generated with — the one that SERVED the run.
Read by the orchestrator, which otherwise builds its failure record from the model frozen at construction: a run that escalated A -> B -> C then died named A, and an operator reading that benches a model that had not been active for minutes. Equal to the configured model until a sticky escalation promotes it, so the ordinary path is unchanged.
__init__(*, agent_context: AgentContext, tool_registry: ToolRegistry, permission_policy: PermissionPolicy, approval_callback: Callable[[ActionStep], bool] | None = None, hook_manager: HookManager, safety_plane: SafetyPlane | None = None, project_instructions: str | None = None, user_instructions: str | None = None, skill_instructions: str | None = None, skill_registry: Any = None, agent_registry: Any = None, session_tool_registry: SessionToolRegistry | None = None, allowed_tools: list[str] | None = None, denied_tools: list[str] | None = None, strict_tool_scope: bool = False, cwd: str | None = None, session_id: str | None = None, session_capabilities: tuple[str, ...] = (), extra_session_tools: list[SessionTool] | None = None, enable_skills: bool = True, project_autoselect: bool = False, project_catalog: ProjectCatalog | None = None, session_context_reader: Callable[[], dict[str, object]] | None = None, contract: DelegationContract | None = None, verification: CommandVerification | None = None, verifier_runner: VerifierRunner | None = None, watchdog_sleeper: Callable[[float], Awaitable[None]] | None = None) -> None
¶
Initialize the tool-use loop.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agent_context
|
AgentContext
|
Required — carries model, cancel, logger, registry. |
required |
tool_registry
|
ToolRegistry
|
Registered tools available to this agent. |
required |
permission_policy
|
PermissionPolicy
|
Permission rules for tool execution. |
required |
approval_callback
|
Callable[[ActionStep], bool] | None
|
Optional callback for ASK decisions (None for sub-agents). |
None
|
hook_manager
|
HookManager
|
Lifecycle hooks. |
required |
safety_plane
|
SafetyPlane | None
|
Operator-owned tool-call gate and session observer,
built once by the orchestrator from config + |
None
|
project_instructions
|
str | None
|
CLAUDE.md / AGENTS.md content discovered at session start. |
None
|
user_instructions
|
str | None
|
Operator-authored custom instructions, ALREADY RENDERED
by |
None
|
skill_instructions
|
str | None
|
Pre-rendered skill body (from user /skill invocation). |
None
|
skill_registry
|
Any
|
SkillRegistry for auto-invocation catalog + activate_skill handling. |
None
|
agent_registry
|
Any
|
AgentRegistry for agent type catalog + spawn_agent type lookup. |
None
|
session_tool_registry
|
SessionToolRegistry | None
|
Registry of plugin-contributed session-tool
factories. Each matching factory (filtered by |
None
|
allowed_tools
|
list[str] | None
|
The agent's allowlist used to filter which session
tools the plugin registry should build for this agent. |
None
|
denied_tools
|
list[str] | None
|
Session-tool ids withheld regardless of which gate in
|
None
|
strict_tool_scope
|
bool
|
Whether |
False
|
cwd
|
str | None
|
Working directory for this agent (project root). |
None
|
session_id
|
str | None
|
Session identifier — used for plan-mode path scoping. |
None
|
session_capabilities
|
tuple[str, ...]
|
Client-advertised capability tuple from the
|
()
|
extra_session_tools
|
list[SessionTool] | None
|
Caller-injected |
None
|
enable_skills
|
bool
|
When |
True
|
project_autoselect
|
bool
|
When |
False
|
project_catalog
|
ProjectCatalog | None
|
The catalog those two tools read and resolve
through, built by the caller ( |
None
|
session_context_reader
|
Callable[[], dict[str, object]] | None
|
Reads back the session's CURRENT effective
context — the most-recent |
None
|
contract
|
DelegationContract | None
|
The spawner's declared |
None
|
verification
|
CommandVerification | None
|
The spawner's declared ground-truth completion check
for THIS agent — |
None
|
verifier_runner
|
VerifierRunner | None
|
Injected |
None
|
watchdog_sleeper
|
Callable[[float], Awaitable[None]] | None
|
Injected wait between watchdog sweeps (defaults
to |
None
|
Source code in packages/mewbo_core/src/mewbo_core/loop/tool_use_loop.py
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 | |
llm_call_stall_age(now: float) -> float | None
¶
Seconds the in-flight LLM call has been outstanding, else None.
Pure read over (_llm_call_started_at, now) with no clock of its own,
so the liveness rule is exercisable at any age without waiting for one
— the watchdog supplies time.monotonic(), a test supplies a number.
Source code in packages/mewbo_core/src/mewbo_core/loop/tool_use_loop.py
1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 | |
rebind_workspace(entry: ProjectEntry) -> dict[str, object]
¶
Re-point this loop at entry's directory. THE one mutation seam.
Everything derived from the working directory moves together here,
because a partial switch is worse than none: the agent believes it moved
and half the machinery did not. Returns the facts switch_project
renders back to the model.
The step that is easiest to miss is the SPAWN seam.
:class:~mewbo_core.agents.spawn_agent.SpawnAgentTool holds its OWN copy of the
workspace and forwards it verbatim to every child loop it builds, so a
switch that updates only self._cwd leaves every sub-agent spawned
afterwards working in the OLD project — silently, and with results that
look plausible right up until they are applied to the wrong tree.
Two deliberate limits, stated so nobody reads them as bugs:
- The spec set NARROWS to what this run already held. A switch must
never widen the tool ceiling the caller granted at run start, so a new
project's own MCP servers are not admitted mid-run; a fresh run
against that project resolves them normally, and the
contextevent written here is what makes that fresh run land in the right place. - Skills ACCUMULATE rather than being replaced. The registry also holds plugin-contributed and user-level skills that a fresh scan of the new directory alone would drop, and losing those costs more than carrying the previous project's.
Source code in packages/mewbo_core/src/mewbo_core/loop/tool_use_loop.py
1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 | |
run(user_query: str, *, tool_specs: list[ToolSpec], context: ContextSnapshot | None = None, plan: Plan | None = None, mode: str = 'act') -> tuple[TaskQueue, OrchestrationState]
async
¶
Run the async tool-use loop and return TaskQueue + OrchestrationState.
Source code in packages/mewbo_core/src/mewbo_core/loop/tool_use_loop.py
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 | |
mewbo_core.agents.agent_context
¶
Immutable agent context propagated through the agent hierarchy.
AgentContext is the per-agent state carried by every ToolUseLoop
instance. The root agent creates one via AgentContext.root(); child
agents receive one via parent_ctx.child().
The hypervisor control plane (AgentHypervisor, AgentHandle) lives
in :mod:mewbo_core.agents.hypervisor.
AgentContext
dataclass
¶
Immutable context propagated through the agent hierarchy.
Every ToolUseLoop instance requires an AgentContext. The root agent
creates one via AgentContext.root(). Child agents receive one
via parent_ctx.child().
Source code in packages/mewbo_core/src/mewbo_core/agents/agent_context.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 66 67 68 69 70 71 72 73 74 75 76 77 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 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 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 237 238 239 240 241 242 243 244 245 246 247 248 249 | |
can_spawn: bool
property
¶
True if this agent is allowed to create children.
remaining_depth: int
property
¶
Number of spawn levels remaining below this agent.
child(*, model_name: str | None = None, capability_mode: str = 'all', workspace_mode: str = 'full_access', atomic: bool = False) -> AgentContext
¶
Create a child context with depth+1.
capability_mode is the child's REQUESTED delegation privilege
ceiling; the stored value is the narrower of it and this (parent)
agent's own capability_mode — a child can only restrict, so
an unset request (default "all") simply inherits the parent's mode.
workspace_mode is the SAME story on the filesystem-containment
axis: the child's requested tier is narrowed min-wins against this
agent's own, so an unset request (default "full_access") inherits the
parent's tier and a grandchild under a read_only ancestor stays
read_only.
atomic is this child's OWN requested firebreak (from
its DelegationContract); the stored value is self.atomic or
atomic — a simple OR, never narrower — so an atomic ancestor's
descendants can never climb back to open_ended.
model_name falls back to self.model_name, which the inheriting
child then runs on. That fallback is only correct while this context's
model_name is the parent's LIVE model, and a parent that heals down
its fallback ladder promotes a new one mid-run — on the loop, since this
context is frozen. So the loop re-seats the spawn seam's context (via
dataclasses.replace) whenever it escalates: without that, a parent
that had just escaped a dead model would fan every un-overridden child
straight back onto it, and the children would die at step 0 while the
parent ran healthy.
Raises:
| Type | Description |
|---|---|
AgentDepthExceeded
|
If |
Source code in packages/mewbo_core/src/mewbo_core/agents/agent_context.py
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 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 | |
root(*, model_name: str, max_depth: int = 5, fallback_models: tuple[str, ...] = (), should_cancel: Callable[[], bool] | None = None, event_logger: Callable[[Event], None] | None = None, registry: AgentHypervisor | None = None, message_queue: queue.Queue[str] | None = None, interrupt_step: threading.Event | None = None, workspace_mode: str = 'full_access', capability_mode: str = 'all') -> AgentContext
staticmethod
¶
Create the root agent context.
workspace_mode seeds the root of the filesystem-containment
axis from agent.default_workspace_mode (default "full_access");
every child narrows from here. Left at the default, the whole tree is
unrestricted.
capability_mode seeds the root of the delegation-privilege axis the
same way (default "all" — no filtering). A caller resolving a
principal's role ceiling passes a narrower tier (read_only for a
viewer) so the ROOT agent — not only its spawned children — is capped;
every child then narrows monotonically from here via :meth:child. Left
at "all" the whole tree is unrestricted.
Source code in packages/mewbo_core/src/mewbo_core/agents/agent_context.py
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 | |
AgentDepthExceeded
¶
Bases: Exception
Raised when attempting to spawn beyond max_depth.
Source code in packages/mewbo_core/src/mewbo_core/agents/agent_context.py
27 28 29 30 31 32 33 34 | |
__init__(attempted: int, maximum: int) -> None
¶
Initialize with the attempted and maximum depth values.
Source code in packages/mewbo_core/src/mewbo_core/agents/agent_context.py
30 31 32 33 34 | |
AgentHandle
dataclass
¶
Mutable runtime state for a single agent — lives in the hypervisor.
Created when an agent registers and updated throughout its lifecycle. Fields are read by the CLI agent tree display and the hypervisor's query/cancellation methods.
Handle starts as submitted, transitions to
running when the loop begins, then to a terminal state.
last_step_at enables tool-call-granularity
stall detection without destroying accumulated context.
message_queue enables bidirectional
adaptive coordination — the hypervisor injects NL feedback.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
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 | |
AgentHypervisor
¶
Hypervisor control plane — manages the full agent tree for a session.
Thread-safe via asyncio.Lock. A single instance is shared across all
agents in the hierarchy through AgentContext.registry.
Responsibilities
- Admission control:
accept()/accept_batch()/release()gate concurrency through an injected :class:AgentQueue(default 20 running slots) that QUEUES over-cap work instead of dropping it. - Registration:
register()/unregister()track agent handles keyed byagent_id. - Status:
update_step()/mark_done()record execution progress and terminal state. - Queries:
list_children()/list_descendants()/list_all()expose the live tree for display and introspection. - Cancellation:
cancel_agent()cancels a single agent;cleanup()tears down the entire tree on session exit.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
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 | |
free_slots: int
property
¶
Slots a spawn could be dispatched into right now.
pending_dispatch: int
property
¶
Accepted spawns not yet started.
NOT a status: those agents are submitted like any other, and this
is only the scheduler's count of how many are still waiting on a slot.
total_steps: int
property
¶
Total tool steps executed across all agents in the session.
__init__(*, max_concurrent: int = 20, session_step_budget: int = 0, attestation: AttestationChain | None = None, queue: AgentQueue | None = None) -> None
¶
Initialize hypervisor with concurrency and budget limits.
Session-wide budget with graduated enforcement.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_concurrent
|
int
|
Maximum number of concurrently RUNNING agents. |
20
|
session_step_budget
|
int
|
Total tool steps allowed across all agents in the session. 0 means unlimited. |
0
|
attestation
|
AttestationChain | None
|
optional provenance hash chain for
this session's agent tree. The hypervisor never constructs one
itself (it has no session_id, no store) — the orchestrator
injects it, seeded from the store's last persisted record, when
the feature is config-enabled. |
None
|
queue
|
AgentQueue | None
|
the admission scheduler. Injected so a deployment (or a
test) can seat a differently-sized or differently-ordered one
without the hypervisor learning how scheduling works; the
default is an :class: |
None
|
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
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 | |
accept(unit: SpawnUnit) -> bool
async
¶
Admit ONE spawn: True = dispatched now, False = deferred.
Never refuses for capacity — that is the whole point of the queue.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
721 722 723 724 725 726 | |
accept_batch(units: Sequence[SpawnUnit]) -> list[bool]
async
¶
Admit a whole fan-out at once — see :meth:AgentQueue.accept_batch.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
728 729 730 | |
agent_step_state(agent_id: str) -> str
async
¶
Per-contract step-budget state for one agent.
"ok" for an unregistered agent or one whose contract carries no
step bound — the same inert default as a disabled contract.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
948 949 950 951 952 953 954 955 956 957 958 | |
agent_token_state(agent_id: str) -> str
async
¶
Per-contract advisory token state for one agent.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
960 961 962 963 964 965 966 | |
budget_exhausted() -> bool
¶
Check if the session step budget is exhausted (0 = unlimited).
Graduated enforcement — this is the trigger check. The response (NL warning injection) happens in ToolUseLoop.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
912 913 914 915 916 917 918 | |
budget_remaining() -> int
¶
Steps remaining in the session budget (0 = unlimited).
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
920 921 922 923 924 | |
budget_warning(*, headroom: int = 5) -> bool
¶
True when within headroom steps of the session budget (0 = off).
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
926 927 928 929 930 | |
cancel_agent(agent_id: str) -> str | None
async
¶
Cancel an agent, whether it has started or is still waiting for a slot.
Returns None on success, or a diagnostic string on failure.
The waiting case is checked FIRST and it is not an optimization.
asyncio_task is populated by the child driver, which runs only
AFTER dispatch — so a capacity-deferred agent has no task, the
task-cancellation path reported no asyncio task, and the agent then
STARTED anyway the moment a sibling freed a slot. Refusing to cancel
something and then running it is the worst of both answers, and it is
reachable the instant a fan-out exceeds the concurrency limit.
Dropping it from the scheduler is what makes the cancel real.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
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 | |
cancel_pending() -> list[str]
async
¶
Drop every accepted-but-undispatched spawn, settling each as cancelled.
A waiting agent holds no slot and owns no asyncio.Task, so neither
cancel_agent nor the cleanup sweep's task cancellation can reach
it — it would sit submitted forever and read as live. Returns the
ids dropped. Called before teardown so a manager settling on the way
out cannot pump a brand-new child into a run that is already ending.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 | |
cleanup(timeout: float = 5.0) -> None
async
¶
Cancel all agents with graceful escalation.
Requests cancellation on all active asyncio tasks, waits up to timeout seconds for them to finish, then force-marks any still pending as cancelled.
Covers every :data:ACTIVE_STATUSES agent, not just running: one
still at submitted never had a loop task to cancel — and one still
waiting for a slot never had a task at all — which is exactly why
either would otherwise survive shutdown unmarked. Waiting units are
dropped from the scheduler FIRST, so a manager settling during the
wait window cannot pump a fresh child into a hypervisor that is being
torn down.
Marking here is deliberately IN-MEMORY only — the hypervisor holds no event logger, and wiring one in would invert the layering (the session owns the transcript, the hypervisor owns the tree). The durable terminal is written by whichever peer can still reach the log:
- While the task is still alive (during the request or the wait):
cancelling it raises
CancelledErrorinside the agent's own lifecycle handler, which writes the terminalstopbefore unwinding. That is the normal path. - Once the wait times out, at the final force-mark sweep (the task is wedged, or the process is being torn down mid-flight): nothing in-process can still write, so the durable terminal comes from the startup sweep on the NEXT boot, which settles agent spans left open under a run that has since ended.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
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 | |
collect_completed(parent_id: str) -> list[AgentHandle]
async
¶
Return children that reached a terminal state with a stored result.
Async CU retrieval — parent reads results when ready, not when child finishes.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 | |
collect_running(parent_id: str) -> list[AgentHandle]
async
¶
Return children of parent_id that are still active.
Reads :data:ACTIVE_STATUSES rather than re-listing the states. That
matters beyond tidiness: this method is the promise-as-completion
gate's ownership index AND what check_agents reports, so a
capacity-deferred child — submitted, registered, not yet started —
must appear here. A refused unit was registered nowhere, which is
exactly why a parent that over-subscribed the fleet was told all its
work was done.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 | |
get(agent_id: str) -> AgentHandle | None
async
¶
Return a single agent handle, or None.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
870 871 872 873 | |
list_all() -> list[AgentHandle]
async
¶
Full tree view — for CLI/API user visibility.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
893 894 895 896 | |
list_children(parent_id: str) -> list[AgentHandle]
async
¶
List direct children of a parent. Enforces isolation.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
875 876 877 878 | |
list_descendants(ancestor_id: str) -> list[AgentHandle]
async
¶
List all descendants recursively.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
880 881 882 883 884 885 886 887 888 889 890 891 | |
list_visible(exclude_agent_id: str | None = None) -> list[AgentHandle]
async
¶
Snapshot of agents excluding the caller — used by check_agents.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
898 899 900 901 | |
mark_done(agent_id: str, status: AgentStatus, error: str | AgentError | None = None) -> None
async
¶
Mark an agent as done with a terminal status.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
851 852 853 854 855 856 857 858 859 860 861 862 863 864 | |
mark_tool_start(agent_id: str, tool_id: str | None) -> None
async
¶
Stamp (or clear) the tool actually in flight for stall attribution.
update_step only stamps last_tool_id on
COMPLETION, so a watchdog check firing mid-call would misattribute the
stall to the previous, already-finished tool. Call this at dispatch
start with the tool name, and again with None once the call
resolves (success, timeout, or exception) so active_tool_id never
lingers stale once the agent moves on.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
836 837 838 839 840 841 842 843 844 845 846 847 848 849 | |
over_wall_deadline_agents(now: float | None = None) -> list[tuple[AgentHandle, str]]
async
¶
Running agents whose contract wall-clock deadline is warn/over.
Mirrors :meth:stalled_agents — a per-contract cousin of the stall
sweep, keyed on started_at rather than last-progress. now
arrives as a clock ARG (never read internally), so a caller can drive
this deterministically without sleeping a real clock.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 | |
record_compaction(agent_id: str) -> None
async
¶
Record that an agent compacted its context.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
1031 1032 1033 1034 1035 1036 1037 | |
register(handle: AgentHandle) -> None
async
¶
Register a new agent in the hypervisor.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
803 804 805 806 | |
release() -> None
async
¶
Settle one running agent's slot, dispatching whatever waits on it.
Async because it is the DISPATCH PUMP, not a bare counter decrement:
the freed slot is handed to the next waiting unit, which means starting
it. This is deliberately the completion path every settling agent
already calls, and exactly-once is already guaranteed there — a pump
hung off on_agent_stop instead would fire while the slot is still
held and find the queue full every time.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
732 733 734 735 736 737 738 739 740 741 742 | |
render_agent_tree(*, exclude_agent_id: str | None = None) -> str
async
¶
Render a concise text summary of the agent tree for the root's system prompt.
Structural transparency — the root agent (the hypervisor's "brain") gets a live view of all agents so it can reason about the delegation state and intervene if needed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
exclude_agent_id
|
str | None
|
If provided, omit this agent from the rendered tree. Used so the calling agent does not see itself listed. |
None
|
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
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 | |
send_message(agent_id: str, message: str) -> str | None
async
¶
Send a steering message to a running agent.
Returns None on success, or a diagnostic string on failure.
Adaptive coordination — the hypervisor injects NL feedback (budget warnings, stall nudges) into the agent's message queue. The ToolUseLoop drains this queue between steps. Bidirectional system↔agent feedback loop.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 | |
send_to_parent(child_agent_id: str, message: str) -> str | None
async
¶
Route a message from a child agent to its parent's queue.
Returns None on success, or a diagnostic string on failure.
Bidirectional message passing — enables lifecycle manager to notify parent on child completion.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 | |
stalled_agents(threshold: float = 120.0) -> list[AgentHandle]
async
¶
Return agents not making progress within threshold seconds.
Internal trigger: delegatee unresponsive → diagnose → evaluate → intervene.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 | |
unregister(agent_id: str) -> AgentHandle | None
async
¶
Remove an agent from the hypervisor.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
808 809 810 811 812 813 814 815 | |
update_step(agent_id: str, tool_id: str) -> None
async
¶
Record a completed tool execution step.
Track at tool-call granularity, not agent granularity. Updates last_step_at for stall detection and total_steps for session budget enforcement.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
821 822 823 824 825 826 827 828 829 830 831 832 833 834 | |
mewbo_core.agents.hypervisor
¶
Agent hypervisor — active governor for multi-agent delegation.
The hypervisor is the centralized control plane that manages the full agent tree for a session. It acts as an active governor (not just a registry), mediating every delegation decision and result handoff.
Scientific grounding: - Adaptive coordination cycle — the hypervisor monitors agents and intervenes via NL feedback when triggers fire. - Structural transparency — configurable monitoring with lifecycle events at each phase transition. - Graduated enforcement — warn, throttle, feedback (never kill first; killing destroys 31-48% of accumulated context). - Task state machine — agents progress through submitted → running → completed/failed/cancelled/rejected. - Communication Units — structured AgentResult with compressed summary field enables inter-agent context passing.
Responsibilities: - Admission control — bounding concurrent agents via semaphore. - Lifecycle tracking — AgentHandle with delegation phase awareness. - Active monitoring — budget tracking, stall detection, NL interventions. - Global eye — render_agent_tree() gives the root agent a live view. - Bidirectional messaging — send_message() enables parent→child steering. - Structured results — AgentResult carries Communication Units between agents. - Graceful shutdown — 3-phase escalation: cancel → wait → force-mark.
AgentHandle
dataclass
¶
Mutable runtime state for a single agent — lives in the hypervisor.
Created when an agent registers and updated throughout its lifecycle. Fields are read by the CLI agent tree display and the hypervisor's query/cancellation methods.
Handle starts as submitted, transitions to
running when the loop begins, then to a terminal state.
last_step_at enables tool-call-granularity
stall detection without destroying accumulated context.
message_queue enables bidirectional
adaptive coordination — the hypervisor injects NL feedback.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
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 | |
AgentHypervisor
¶
Hypervisor control plane — manages the full agent tree for a session.
Thread-safe via asyncio.Lock. A single instance is shared across all
agents in the hierarchy through AgentContext.registry.
Responsibilities
- Admission control:
accept()/accept_batch()/release()gate concurrency through an injected :class:AgentQueue(default 20 running slots) that QUEUES over-cap work instead of dropping it. - Registration:
register()/unregister()track agent handles keyed byagent_id. - Status:
update_step()/mark_done()record execution progress and terminal state. - Queries:
list_children()/list_descendants()/list_all()expose the live tree for display and introspection. - Cancellation:
cancel_agent()cancels a single agent;cleanup()tears down the entire tree on session exit.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
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 | |
free_slots: int
property
¶
Slots a spawn could be dispatched into right now.
pending_dispatch: int
property
¶
Accepted spawns not yet started.
NOT a status: those agents are submitted like any other, and this
is only the scheduler's count of how many are still waiting on a slot.
total_steps: int
property
¶
Total tool steps executed across all agents in the session.
__init__(*, max_concurrent: int = 20, session_step_budget: int = 0, attestation: AttestationChain | None = None, queue: AgentQueue | None = None) -> None
¶
Initialize hypervisor with concurrency and budget limits.
Session-wide budget with graduated enforcement.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
max_concurrent
|
int
|
Maximum number of concurrently RUNNING agents. |
20
|
session_step_budget
|
int
|
Total tool steps allowed across all agents in the session. 0 means unlimited. |
0
|
attestation
|
AttestationChain | None
|
optional provenance hash chain for
this session's agent tree. The hypervisor never constructs one
itself (it has no session_id, no store) — the orchestrator
injects it, seeded from the store's last persisted record, when
the feature is config-enabled. |
None
|
queue
|
AgentQueue | None
|
the admission scheduler. Injected so a deployment (or a
test) can seat a differently-sized or differently-ordered one
without the hypervisor learning how scheduling works; the
default is an :class: |
None
|
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
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 | |
accept(unit: SpawnUnit) -> bool
async
¶
Admit ONE spawn: True = dispatched now, False = deferred.
Never refuses for capacity — that is the whole point of the queue.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
721 722 723 724 725 726 | |
accept_batch(units: Sequence[SpawnUnit]) -> list[bool]
async
¶
Admit a whole fan-out at once — see :meth:AgentQueue.accept_batch.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
728 729 730 | |
agent_step_state(agent_id: str) -> str
async
¶
Per-contract step-budget state for one agent.
"ok" for an unregistered agent or one whose contract carries no
step bound — the same inert default as a disabled contract.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
948 949 950 951 952 953 954 955 956 957 958 | |
agent_token_state(agent_id: str) -> str
async
¶
Per-contract advisory token state for one agent.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
960 961 962 963 964 965 966 | |
budget_exhausted() -> bool
¶
Check if the session step budget is exhausted (0 = unlimited).
Graduated enforcement — this is the trigger check. The response (NL warning injection) happens in ToolUseLoop.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
912 913 914 915 916 917 918 | |
budget_remaining() -> int
¶
Steps remaining in the session budget (0 = unlimited).
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
920 921 922 923 924 | |
budget_warning(*, headroom: int = 5) -> bool
¶
True when within headroom steps of the session budget (0 = off).
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
926 927 928 929 930 | |
cancel_agent(agent_id: str) -> str | None
async
¶
Cancel an agent, whether it has started or is still waiting for a slot.
Returns None on success, or a diagnostic string on failure.
The waiting case is checked FIRST and it is not an optimization.
asyncio_task is populated by the child driver, which runs only
AFTER dispatch — so a capacity-deferred agent has no task, the
task-cancellation path reported no asyncio task, and the agent then
STARTED anyway the moment a sibling freed a slot. Refusing to cancel
something and then running it is the worst of both answers, and it is
reachable the instant a fan-out exceeds the concurrency limit.
Dropping it from the scheduler is what makes the cancel real.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
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 | |
cancel_pending() -> list[str]
async
¶
Drop every accepted-but-undispatched spawn, settling each as cancelled.
A waiting agent holds no slot and owns no asyncio.Task, so neither
cancel_agent nor the cleanup sweep's task cancellation can reach
it — it would sit submitted forever and read as live. Returns the
ids dropped. Called before teardown so a manager settling on the way
out cannot pump a brand-new child into a run that is already ending.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 | |
cleanup(timeout: float = 5.0) -> None
async
¶
Cancel all agents with graceful escalation.
Requests cancellation on all active asyncio tasks, waits up to timeout seconds for them to finish, then force-marks any still pending as cancelled.
Covers every :data:ACTIVE_STATUSES agent, not just running: one
still at submitted never had a loop task to cancel — and one still
waiting for a slot never had a task at all — which is exactly why
either would otherwise survive shutdown unmarked. Waiting units are
dropped from the scheduler FIRST, so a manager settling during the
wait window cannot pump a fresh child into a hypervisor that is being
torn down.
Marking here is deliberately IN-MEMORY only — the hypervisor holds no event logger, and wiring one in would invert the layering (the session owns the transcript, the hypervisor owns the tree). The durable terminal is written by whichever peer can still reach the log:
- While the task is still alive (during the request or the wait):
cancelling it raises
CancelledErrorinside the agent's own lifecycle handler, which writes the terminalstopbefore unwinding. That is the normal path. - Once the wait times out, at the final force-mark sweep (the task is wedged, or the process is being torn down mid-flight): nothing in-process can still write, so the durable terminal comes from the startup sweep on the NEXT boot, which settles agent spans left open under a run that has since ended.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
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 | |
collect_completed(parent_id: str) -> list[AgentHandle]
async
¶
Return children that reached a terminal state with a stored result.
Async CU retrieval — parent reads results when ready, not when child finishes.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 | |
collect_running(parent_id: str) -> list[AgentHandle]
async
¶
Return children of parent_id that are still active.
Reads :data:ACTIVE_STATUSES rather than re-listing the states. That
matters beyond tidiness: this method is the promise-as-completion
gate's ownership index AND what check_agents reports, so a
capacity-deferred child — submitted, registered, not yet started —
must appear here. A refused unit was registered nowhere, which is
exactly why a parent that over-subscribed the fleet was told all its
work was done.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 | |
get(agent_id: str) -> AgentHandle | None
async
¶
Return a single agent handle, or None.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
870 871 872 873 | |
list_all() -> list[AgentHandle]
async
¶
Full tree view — for CLI/API user visibility.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
893 894 895 896 | |
list_children(parent_id: str) -> list[AgentHandle]
async
¶
List direct children of a parent. Enforces isolation.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
875 876 877 878 | |
list_descendants(ancestor_id: str) -> list[AgentHandle]
async
¶
List all descendants recursively.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
880 881 882 883 884 885 886 887 888 889 890 891 | |
list_visible(exclude_agent_id: str | None = None) -> list[AgentHandle]
async
¶
Snapshot of agents excluding the caller — used by check_agents.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
898 899 900 901 | |
mark_done(agent_id: str, status: AgentStatus, error: str | AgentError | None = None) -> None
async
¶
Mark an agent as done with a terminal status.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
851 852 853 854 855 856 857 858 859 860 861 862 863 864 | |
mark_tool_start(agent_id: str, tool_id: str | None) -> None
async
¶
Stamp (or clear) the tool actually in flight for stall attribution.
update_step only stamps last_tool_id on
COMPLETION, so a watchdog check firing mid-call would misattribute the
stall to the previous, already-finished tool. Call this at dispatch
start with the tool name, and again with None once the call
resolves (success, timeout, or exception) so active_tool_id never
lingers stale once the agent moves on.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
836 837 838 839 840 841 842 843 844 845 846 847 848 849 | |
over_wall_deadline_agents(now: float | None = None) -> list[tuple[AgentHandle, str]]
async
¶
Running agents whose contract wall-clock deadline is warn/over.
Mirrors :meth:stalled_agents — a per-contract cousin of the stall
sweep, keyed on started_at rather than last-progress. now
arrives as a clock ARG (never read internally), so a caller can drive
this deterministically without sleeping a real clock.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 | |
record_compaction(agent_id: str) -> None
async
¶
Record that an agent compacted its context.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
1031 1032 1033 1034 1035 1036 1037 | |
register(handle: AgentHandle) -> None
async
¶
Register a new agent in the hypervisor.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
803 804 805 806 | |
release() -> None
async
¶
Settle one running agent's slot, dispatching whatever waits on it.
Async because it is the DISPATCH PUMP, not a bare counter decrement:
the freed slot is handed to the next waiting unit, which means starting
it. This is deliberately the completion path every settling agent
already calls, and exactly-once is already guaranteed there — a pump
hung off on_agent_stop instead would fire while the slot is still
held and find the queue full every time.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
732 733 734 735 736 737 738 739 740 741 742 | |
render_agent_tree(*, exclude_agent_id: str | None = None) -> str
async
¶
Render a concise text summary of the agent tree for the root's system prompt.
Structural transparency — the root agent (the hypervisor's "brain") gets a live view of all agents so it can reason about the delegation state and intervene if needed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
exclude_agent_id
|
str | None
|
If provided, omit this agent from the rendered tree. Used so the calling agent does not see itself listed. |
None
|
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
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 | |
send_message(agent_id: str, message: str) -> str | None
async
¶
Send a steering message to a running agent.
Returns None on success, or a diagnostic string on failure.
Adaptive coordination — the hypervisor injects NL feedback (budget warnings, stall nudges) into the agent's message queue. The ToolUseLoop drains this queue between steps. Bidirectional system↔agent feedback loop.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 | |
send_to_parent(child_agent_id: str, message: str) -> str | None
async
¶
Route a message from a child agent to its parent's queue.
Returns None on success, or a diagnostic string on failure.
Bidirectional message passing — enables lifecycle manager to notify parent on child completion.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 | |
stalled_agents(threshold: float = 120.0) -> list[AgentHandle]
async
¶
Return agents not making progress within threshold seconds.
Internal trigger: delegatee unresponsive → diagnose → evaluate → intervene.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 | |
unregister(agent_id: str) -> AgentHandle | None
async
¶
Remove an agent from the hypervisor.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
808 809 810 811 812 813 814 815 | |
update_step(agent_id: str, tool_id: str) -> None
async
¶
Record a completed tool execution step.
Track at tool-call granularity, not agent granularity. Updates last_step_at for stall detection and total_steps for session budget enforcement.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
821 822 823 824 825 826 827 828 829 830 831 832 833 834 | |
AgentQueue
¶
Admission scheduler — bounds concurrency WITHOUT dropping work.
Admission is not a two-outcome question. Take-a-slot-or-be-refused makes "the fleet is busy" indistinguishable from "this task was impossible", and silently loses a wide fan-out's surplus. There is a third answer, and it is the one a scheduler owes its caller: accept now, dispatch later.
THE LAW: waiting is free; only RUNNING consumes a slot. A unit sitting
in :attr:waiting holds nothing, so a parent blocked on a child can never
be part of a capacity cycle — which is what makes deferred admission safe
here where it would otherwise deadlock a tree of nested delegations.
Note the vocabulary: units here are waiting or dispatched, never
"queued". The agent-facing lifecycle has no such state, and it must not
grow one — a waiting unit is submitted like any other accepted agent.
No lock, and none is needed: every capacity decision below is a synchronous read-modify-write on the event-loop thread, with awaits confined to the launch calls that follow them. Bounded concurrency is enforcement, and enforcement that discards work is not graduated, it is a kill.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
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 | |
capacity: int
property
¶
Maximum number of simultaneously RUNNING agents.
free_slots: int
property
¶
Slots a unit could be dispatched into right now.
running: int
property
¶
Units dispatched and not yet settled.
waiting: int
property
¶
Units accepted and waiting for a slot.
__init__(*, capacity: int = 20) -> None
¶
Initialize with the number of agents that may RUN at once.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
497 498 499 500 501 502 503 504 505 506 507 508 | |
accept(unit: SpawnUnit) -> bool
async
¶
Accept ONE unit. True = dispatched now, False = deferred.
Never refuses — see :meth:accept_batch, whose single-entry case this
is (one implementation, so a single spawn and a batch entry can never
be admitted under different rules).
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
530 531 532 533 534 535 536 537 | |
accept_batch(units: Sequence[SpawnUnit]) -> list[bool]
async
¶
Accept EVERY unit; dispatch what fits, queue the rest.
Returns one flag per unit, positionally aligned: True dispatched,
False deferred. Atomic in acceptance, staggered in dispatch — the
capacity decisions run as one synchronous pass with no await between
them, so a settle landing mid-batch can only add dispatches and can
never split the batch or refuse part of it. Every unit is accepted
either way; the return value says only which ones started immediately.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
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 | |
clear() -> list[ScheduledSpawn]
¶
Drop every waiting unit, returning the records so a caller settles them.
A waiting unit holds no slot and owns no task, so nothing else can end
it: teardown has to reach in here or those agents stay submitted
forever and read as live to every liveness consumer.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
614 615 616 617 618 619 620 621 622 623 | |
discard(agent_id: str) -> ScheduledSpawn | None
¶
Remove ONE waiting unit, returning its record — None if not waiting.
The cancellation seam for a unit that has not been dispatched. Such a
unit owns no asyncio.Task, so task cancellation cannot touch it and
it would otherwise start minutes later on a slot a sibling freed —
after its canceller was told the cancel had failed.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
601 602 603 604 605 606 607 608 609 610 611 612 | |
release() -> None
async
¶
Settle one dispatched unit — and pump the queue. THE DISPATCH PUMP.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
573 574 575 | |
AgentResult
dataclass
¶
Structured result from a sub-agent — the Communication Unit.
Each agent produces a CU that grows with relevant info
and drops irrelevant content, preventing context explosion in chains.
cannot_solve status enables explicit failure
admission as a first-class outcome, saving downstream waste.
summary serves as a checkpoint
snapshot — even on failure, partial work survives for retry.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 | |
DelegationContract
dataclass
¶
Per-spawn delegation bounds a caller can put on ONE child.
Every field's zero/off value leaves the child unbounded, so a spawn that
never declares a contract is constrained by nothing here — this is an
opt-in ceiling, never a default constraint. Distinct from the
hypervisor's SESSION-wide session_step_budget: that is a shared pool
across the whole agent tree; this is one caller's bound on one child,
checked in addition to (never instead of) the session budget.
Privilege attenuation — autonomy is
the hard delegation firebreak (an atomic child can never itself spawn,
and the bit only ever narrows down the tree, see AgentContext.child).
Graduated enforcement — step_state/
wall_state/token_state each expose a warn tier before the hard
stop, mirroring the session budget's own warn-then-halt shape.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
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 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 | |
atomic: bool
property
¶
True when this contract strips the child's own delegation rights.
enabled: bool
property
¶
True when the contract carries at least one real constraint.
from_value(value: object) -> DelegationContract
classmethod
¶
Parse + validate the schema contract object. Unset/invalid → OFF.
Validation is total (never raises), mirroring RetryPolicy.from_value:
a malformed field degrades to the safe default rather than failing a
spawn, since contract is an optional caller-declared ceiling, not a
correctness contract. Unknown keys are dropped after ONE warning per
parse (never per-key) so a typo'd field doesn't spam the log.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
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 | |
resolve_model_override(explicit: str | None, tier_map: Mapping[str, str], allowed: Any = None) -> str | None
¶
Resolve model_tier against a deployment's tier→model map.
Returns None (fall through to the caller's existing resolution)
when: an explicit model was already given (it always wins — this
is the LOWEST-priority model source); no model_tier is declared;
the tier has no map entry; or the mapped model is excluded by
allowed (when non-empty). Otherwise returns the mapped model id.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 | |
snapshot() -> dict[str, Any]
¶
Bounded-scalar serialization.
The ONE shared shape read by check_agents and by attestation
provenance.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
333 334 335 336 337 338 339 | |
step_state(steps_completed: int) -> Literal['ok', 'warn', 'over']
¶
Graduated step-budget state — ok when unset (0 = unlimited).
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
274 275 276 277 278 279 280 281 282 | |
token_state(total_tokens: int) -> Literal['ok', 'warn', 'over']
¶
Feature-detected advisory token state — best-effort, never a hard promise.
total_tokens <= 0 means the caller has no usage signal at all (a
model/proxy that never surfaced usage_metadata), so absence of
data reads as ok, never over — the same feature-detection
posture as _UsageNormalizingLiteLLM. Likewise a contract with no
max_tokens declared is always ok: this axis is advisory only,
cost accounting is out of scope.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
294 295 296 297 298 299 300 301 302 303 304 305 306 | |
wall_state(elapsed_s: float) -> Literal['ok', 'warn', 'over']
¶
Graduated wall-clock state — warn at 80%, over at 100% of the bound.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
284 285 286 287 288 289 290 291 292 | |
ScheduledSpawn
¶
Bases: BaseModel
One accepted sub-agent, as the admission scheduler sees it.
The agent_id is minted at ACCEPTANCE, not at dispatch: a unit waiting
for a slot is already a real agent, registered and submitted, which is
what lets collect_running and check_agents see it and what makes
"accepted" a promise the scheduler must keep rather than a hope. A refused
unit registered nowhere at all would leave a parent asking
check_agents(wait=true) told everything was done — that blindness, not
the refusal itself, is what makes a loss silent.
Ordering lives ON the record (:meth:ordering_key) rather than in a
comparator beside the queue — a scheduling policy kept apart from the data
it orders drifts from it the moment a field is added, the same reason
TriggerSpec owns its own due-ness. Clocks arrive as VALUES too:
enqueued_at is stamped by the caller that owns one and
:meth:waited_for takes now as an argument, so nothing here reads a
clock and a test needs no patching to drive it.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
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 | |
ordering_key() -> tuple[int, float, int]
¶
Sort key: priority first, then arrival, then declared batch order.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
451 452 453 454 | |
waited_for(now: float) -> float
¶
Seconds spent waiting, measured against a caller-supplied clock.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
456 457 458 | |
SpawnUnit
dataclass
¶
A scheduled spawn paired with the callable that starts it.
The record is a validated contract; the launcher is a live closure over
in-process spawn state that crosses no trust boundary — the same split the
package already draws between a persisted spec and a hot RunHandle.
Source code in packages/mewbo_core/src/mewbo_core/agents/hypervisor.py
461 462 463 464 465 466 467 468 469 470 471 | |
mewbo_core.agents.spawn_agent
¶
Sub-agent spawning tool for the agent hypervisor.
SpawnAgentTool creates a child ToolUseLoop instance, registers it
in the AgentHypervisor, runs it to completion, and returns the result.
Tool scoping follows the "filter before binding" pattern: denied
tools are removed from the child's bind_tools() list so the child LLM
never sees them.
AgentError
dataclass
¶
Structured error context from a failed sub-agent.
Source code in packages/mewbo_core/src/mewbo_core/agents/spawn_agent.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | |
ChildWorkspace
dataclass
¶
The directory ONE child runs in, paired with the rules that govern it.
The two are ONE fact, so they travel as one value: a child pointed at another project must read THAT project's instruction files, and a pair free to drift is how a fleet ends up working in one repository under another's rules — a miss that produces plausible work rather than an error.
Resolved ONCE per spawn, at admission, rather than read off the tool at each
attempt: :meth:SpawnAgentTool.rebind_cwd may move the workspace between a
child's retry attempts, and a child must finish where it started.
Source code in packages/mewbo_core/src/mewbo_core/agents/spawn_agent.py
199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 | |
RetryPolicy
dataclass
¶
Bounded auto-retry / re-delegation policy for a spawned sub-agent.
Opt-in via the retry spawn-schema field; DEFAULT OFF (max == 0)
so an unset/absent retry runs the child exactly once. On a retryable
terminal failure the spawn bridge
re-delegates the same task on the same handle (retaining the one already
held semaphore slot for the whole sequence) up to max extra attempts,
sleeping :meth:backoff_for with exponential growth between them.
Model-level causes are deliberately NOT re-escalated here: every child
ToolUseLoop run already drives the fallback ladder internally, so a
fresh attempt gets a fresh ladder — this layer only re-runs a whole child
whose loop died. rejected (declined at admission, before the loop) and
cancelled (parent-cancelled → CancelledError, re-raised, never
retried) are structurally unreachable by the retry loop.
Source code in packages/mewbo_core/src/mewbo_core/agents/spawn_agent.py
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 | |
enabled: bool
property
¶
True when at least one retry is permitted.
backoff_for(attempt: int) -> float
¶
Exponential backoff (seconds) before the next attempt.
attempt is the failed attempt's index (1-based), so the first retry
waits backoff, the second 2 * backoff, etc.
Source code in packages/mewbo_core/src/mewbo_core/agents/spawn_agent.py
393 394 395 396 397 398 399 | |
classify_cause(exc: BaseException) -> str
staticmethod
¶
Map a child-loop exception to a coarse retry cause.
Reuses the RetryStrategy classifier's reason taxonomy (DRY — the
delegation layer never re-derives provider/timeout semantics): a
timeout/deadline-flavoured failure is "timeout"; everything else
(transient or otherwise) collapses to the generic "failed".
Source code in packages/mewbo_core/src/mewbo_core/agents/spawn_agent.py
401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 | |
from_value(value: object) -> RetryPolicy
classmethod
¶
Parse + validate the schema retry object. Unset/invalid → OFF.
Validation is total (never raises): a malformed field degrades to the
safe default rather than failing a spawn, since retry is an optional
resilience hint, not a correctness contract.
Source code in packages/mewbo_core/src/mewbo_core/agents/spawn_agent.py
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 | |
should_retry(cause: str, attempt: int) -> bool
¶
True when another attempt is allowed for this failure cause.
attempt is the number of attempts made so far (the one that just
failed). Total attempts are bounded at max + 1.
Source code in packages/mewbo_core/src/mewbo_core/agents/spawn_agent.py
385 386 387 388 389 390 391 | |
SpawnAgentTask
¶
Bases: BaseModel
One entry in a spawn_agents batch.
Carries the SAME per-task fields as the single spawn_agent schema, but
validated at definition: extra="forbid" rejects stray keys so a
malformed fan-out fails fast instead of silently dropping a field, and a
blank task is refused (an empty delegation is never intentional).
Source code in packages/mewbo_core/src/mewbo_core/agents/spawn_agent.py
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 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 | |
to_args() -> dict[str, Any]
¶
Project to the args dict the single-spawn path consumes.
Unset (None) fields are dropped so the downstream args.get(...)
defaults apply exactly as they do for an ad-hoc spawn_agent call —
keeping the batch a thin reuse of _spawn_one rather than a fork.
Source code in packages/mewbo_core/src/mewbo_core/agents/spawn_agent.py
189 190 191 192 193 194 195 196 | |
SpawnAgentTool
¶
Spawns a child ToolUseLoop as a sub-agent.
Source code in packages/mewbo_core/src/mewbo_core/agents/spawn_agent.py
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 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 | |
__init__(*, agent_context: AgentContext, tool_registry: ToolRegistry, permission_policy: PermissionPolicy, approval_callback: Callable[[ActionStep], bool] | None = None, hook_manager: HookManager, safety_plane: SafetyPlane | None = None, project_instructions: str | None = None, user_instructions: str | None = None, cwd: str | None = None, agent_registry: Any = None, session_tool_registry: SessionToolRegistry | None = None, session_capabilities: tuple[str, ...] = (), enable_skills: bool = True, catalog: ProjectCatalog | None = None) -> None
¶
Initialize with parent context and shared registries.
Source code in packages/mewbo_core/src/mewbo_core/agents/spawn_agent.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 | |
await_lifecycle_managers(timeout: float = 3.0) -> None
async
¶
Settle every background lifecycle manager before the run tears down.
Called from ToolUseLoop.run()'s finally block. Collect-or-cancel:
managers get timeout to finish on their own, then the stragglers are
cancelled — and, crucially, AWAITED.
Cancelling without awaiting is what leaked children. cancel() only
schedules the CancelledError; the handler that marks the child done
and writes its ONE terminal stop runs on a later turn of the event
loop, which never comes if the loop tears down first. The child was then
settled by nothing in this process — its span stayed open until a boot
sweep reaped it days later, or forever. Awaiting here is what makes
settlement in-process rather than next-boot.
Exceptions are swallowed by return_exceptions: these tasks own their
own terminal reporting, and a manager that fails while being torn down
must not take down the run that is already ending.
The set to await is not fixed at entry. Every manager that settles hands its slot to a QUEUED child through the dispatch pump, which creates a new manager — so this DRAINS in rounds against one deadline rather than awaiting a snapshot. Cancelling waiting units up front would be the simpler code and the wrong behaviour: it would discard, at teardown, exactly the work this scheduler exists to stop discarding. Only once the budget is spent are the still-waiting units dropped — after that nothing will ever dispatch them, so they must be settled rather than left reading as live.
Source code in packages/mewbo_core/src/mewbo_core/agents/spawn_agent.py
2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915 2916 | |
handle_check_agents(action_step: ActionStep) -> MockSpeaker
async
¶
Return agent tree state with completed results and progress.
Emits a JSON payload with kind: "agent_tree". The text field
carries the rendered ASCII tree the LLM consumes; the agents list
is the structured snapshot the console uses to render CheckAgentsCard.
Source code in packages/mewbo_core/src/mewbo_core/agents/spawn_agent.py
2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 | |
handle_steer_agent(action_step: ActionStep) -> MockSpeaker
async
¶
Send a steering message to or cancel a running agent.
Source code in packages/mewbo_core/src/mewbo_core/agents/spawn_agent.py
2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 | |
has_live_owned_runs() -> bool
async
¶
True while any agent this session owns is still non-terminal.
The ownership index behind the promise-as-completion gate: a clean terminal declared while owned work is live is a promise, not a completion. Exposed here because the hypervisor is the only thing that knows, and the seam that must ask is the one accepting a completion claim.
Source code in packages/mewbo_core/src/mewbo_core/agents/spawn_agent.py
2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 | |
rebind_active_model(model_name: str) -> None
¶
Re-seat this tool's parent context onto an escalated model.
The public seam for the loop's sticky model escalation. A parent that
healed itself onto a rescue model must not keep spawning children onto
the dead one: :meth:_resolve_model falls back to the parent context's
model_name, and each child's own context is derived from it, so a
stale value here re-infects the whole subtree.
AgentContext is frozen, so this REPLACES rather than mutates — and
that is exactly why the seam is a method and not an attribute write.
Knowing the context is a frozen dataclass is this class's business, not
the loop's; reaching in to do the replace from outside couples the
caller to a representation it should never have to know. Idempotent, so
the loop may call it on every turn.
Source code in packages/mewbo_core/src/mewbo_core/agents/spawn_agent.py
1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 | |
rebind_cwd(cwd: str, *, project_instructions: str | None) -> None
¶
Re-point the workspace every FUTURE child inherits.
The seam a session-level project switch drives: from here on, a spawn
that names no project of its own lands in cwd and reads
project_instructions instead of the ones this tool was built with.
Already-running children are deliberately untouched. A live child's loop
captured its own directory when it was built and has been resolving
paths against it ever since; moving that out from under it would be a
race no one owns — its containment root, its verifier's working
directory and its half-finished edits would disagree about where it is.
A child finishes where it started; the switch applies to the next one.
That is also why a spawn resolves its :class:ChildWorkspace once at
admission rather than re-reading these fields on each retry attempt.
Source code in packages/mewbo_core/src/mewbo_core/agents/spawn_agent.py
1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 | |
run_async(action_step: ActionStep) -> MockSpeaker
async
¶
Execute a single sub-agent. Returns the result as a MockSpeaker.
Thin wrapper over :meth:_spawn_one — the batch path
(:meth:run_batch_async) shares the same core. The outcome is
projected through :meth:_SpawnOutcome.report, not read off
content: reading the string would throw away the refusal's status
and typed cause, handing the model a bare sentence for five different
failures.
Source code in packages/mewbo_core/src/mewbo_core/agents/spawn_agent.py
1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 | |
run_batch_async(action_step: ActionStep) -> MockSpeaker
async
¶
Fan out a batch of independent sub-agents from ONE tool call.
Pure composition over :meth:_spawn_one, in two phases. Each entry is
RESOLVED first (its workspace, agent type and model settled, its handle
registered, its id minted), then the whole batch is handed to the
scheduler in ONE atomic acceptance: every entry that resolved is
accepted, and the scheduler decides only which start now and which
wait. A batch is therefore throttled by concurrency, never truncated by
it. Marking the surplus rejected and discarding it would read to
the caller as N agents when only max_concurrent existed.
Returns the ordered agent_ids; the model collects results via the
existing check_agents. The orchestration loop is untouched.
Source code in packages/mewbo_core/src/mewbo_core/agents/spawn_agent.py
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 | |
substitute_agent_body(body: str, subs: Mapping[str, str], env: Mapping[str, str] | None = None) -> str
staticmethod
¶
Render an agent's body with plugin-generic variable substitution.
Three passes, in order:
${KEY}literal substitution from subs. Core passesSESSION_IDandCLAUDE_PLUGIN_ROOT; plugins author their prompts against these names.- Bash-style
${VAR:-default}— ifVARis unset in env, the text expands todefault. IfVARis set, it expands to the env value. This keeps plugin prompts self-documenting (operator override path is obvious in the source). - Plain
$VARexpansion as a final pass, matching :func:os.path.expandvarssemantics. Unset variables remain literal so authors can spot typos at glance.
A staticmethod on this class rather than a loose module function:
this tool is the only production caller, and subs/env arrive as
ARGS so the renderer stays testable with a fake environment. The
module-level substitute_agent_body name is a thin alias over it, so
the import path plugins and tests already use is unchanged.
Source code in packages/mewbo_core/src/mewbo_core/agents/spawn_agent.py
2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 | |
mewbo_core.loop.planning
¶
Prompt construction and planning helpers.
Planner
¶
Generate action plans via LLM.
Source code in packages/mewbo_core/src/mewbo_core/loop/planning.py
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 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 | |
__init__(tool_registry: ToolRegistry | None) -> None
¶
Initialize the planner.
Source code in packages/mewbo_core/src/mewbo_core/loop/planning.py
181 182 183 184 | |
generate(user_query: str, model_name: str, context: ContextSnapshot | None = None, *, tool_specs: list[ToolSpec] | None = None, mode: str = 'act', feedback: str | None = None, project_instructions: str | None = None) -> Plan
¶
Generate a plan from the user query.
Source code in packages/mewbo_core/src/mewbo_core/loop/planning.py
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 | |
PromptBuilder
¶
Build system prompts with contextual sections.
Source code in packages/mewbo_core/src/mewbo_core/loop/planning.py
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 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 | |
__init__(tool_registry: ToolRegistry | None) -> None
¶
Initialize prompt builder dependencies.
Source code in packages/mewbo_core/src/mewbo_core/loop/planning.py
91 92 93 | |
build(base_prompt: str, context: ContextSnapshot | None, component_status: Iterable[ComponentStatus] | None = None, *, mode: str = 'act', tool_specs=None, include_tool_guidance: bool = True, project_instructions: str | None = None) -> str
¶
Build an augmented system prompt string.
Source code in packages/mewbo_core/src/mewbo_core/loop/planning.py
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 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 | |
mewbo_core.loop.session_runtime
¶
Shared session runtime utilities for CLI and API.
GoalRetryGate
¶
Re-invoke a session ONCE when it ended without meeting its stated goal.
The escalation that begins where the in-band gates stop. A run that claims a
clean terminal while a declared obligation is unmet is nudged inside the
turn, with the context still warm and bounded to three attempts; that is
strictly the cheaper correction and it stays the first line. This gate is
what remains when the nudges are spent and the session has already ended
unmet_goal — the case a human otherwise fixes by clicking Continue,
which routinely produces the missing result in ONE further step.
Exactly one automatic attempt, ever. The ledger is the recovery
transcript event the recovery path already writes: this gate stamps it with
trigger="auto_goal_unmet", and refuses whenever a marker carrying that
trigger is already present. Durable, restart-proof, and no new store field.
Cost ceiling — state it plainly, because nothing else in the system bounds a
session's token spend (TokenBudget is compaction accounting, not a wallet):
one additional run per session, whose own cost is bounded only by that
run's step/wall budget. Worst case a session costs twice what it otherwise
would. That is the entire price, and it cannot compound: the second run's
terminal reaches this gate too, finds its own marker, and refuses.
action="continue" is load-bearing, not a preference. retry truncates
the transcript back past the failed turn, which would delete the marker and
make the one-shot guard structurally impossible to enforce.
Cost class: O(one record) — one digest fold plus one transcript read for
the marker scan, on a terminal path, once per run.
Source code in packages/mewbo_core/src/mewbo_core/loop/session_runtime.py
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 | |
__init__(*, runtime: SessionRuntime) -> None
¶
Bind the gate to the runtime that owns the session it re-drives.
Source code in packages/mewbo_core/src/mewbo_core/loop/session_runtime.py
413 414 415 | |
maybe_retry(session_id: str, relaunch: Callable[[str], str]) -> bool
¶
Re-drive session_id once if its run ended with an unmet goal.
relaunch starts a fresh run on the session with the given query,
carrying the ORIGINAL run's collaborators (tool registry, hooks,
capability mode, cwd …) unchanged, and returns its run id — "" when
the registry refused. Returns True only when a retry was actually
started.
Total by construction: a best-effort correction must never break the completion of the run that triggered it, so every failure is logged and swallowed. It is called from the run's own thread after that run's registry slot has been released.
Source code in packages/mewbo_core/src/mewbo_core/loop/session_runtime.py
417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 | |
RunHandle
dataclass
¶
Active orchestration tracking.
A run is backed by EITHER a daemon thread (CPython sync-wrapper path) or an
event-loop task (Pyodide WebLoop / async harnesses). Exactly one of
thread / loop_active reflects liveness; every other field applies
uniformly. is_alive() is the backend-agnostic liveness check.
task holds the loop-backed run's asyncio.Task (mirrors
AgentHandle.asyncio_task in hypervisor.py / _lifecycle_tasks in
spawn_agent.py): register_loop_run mints the handle before the
coroutine exists, so task starts None and is attached via
:meth:RunRegistry.attach_loop_task right after loop.create_task(...).
Holding this strong reference on the registry-owned handle is what keeps
asyncio from garbage-collecting the fire-and-forget task mid-run — a bare
local task = loop.create_task(...) with no held reference is eligible
for GC as soon as the enclosing function returns.
Source code in packages/mewbo_core/src/mewbo_core/loop/session_runtime.py
168 169 170 171 172 173 174 175 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 | |
is_alive() -> bool
¶
Return whether the underlying run is still in progress.
Source code in packages/mewbo_core/src/mewbo_core/loop/session_runtime.py
196 197 198 199 200 | |
RunRegistry
¶
Track active orchestration runs (thread- or loop-backed) per session.
Source code in packages/mewbo_core/src/mewbo_core/loop/session_runtime.py
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 | |
__init__() -> None
¶
Initialize the run registry.
Source code in packages/mewbo_core/src/mewbo_core/loop/session_runtime.py
206 207 208 209 | |
attach_loop_task(session_id: str, task: asyncio.Task) -> None
¶
Attach a loop-backed run's asyncio.Task to its handle.
register_loop_run reserves the run's slot before the coroutine —
and thus the task — exists, so the task is attached here right after
the caller's loop.create_task(...). From that point on the
registry (via the handle) holds a strong reference for the run's
lifetime, preventing the fire-and-forget task from being garbage
collected mid-run. A no-op if the handle is already gone (e.g. the
task finished and its done-callback finalized the run before this
call — not expected in practice but harmless).
Source code in packages/mewbo_core/src/mewbo_core/loop/session_runtime.py
277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 | |
cancel(session_id: str) -> bool
¶
Request cancellation for an active session run.
Source code in packages/mewbo_core/src/mewbo_core/loop/session_runtime.py
329 330 331 332 333 334 335 336 | |
finalize_loop_run(session_id: str) -> None
¶
Mark a loop-backed run as completed and drop its handle.
Source code in packages/mewbo_core/src/mewbo_core/loop/session_runtime.py
294 295 296 297 298 299 | |
get_cancel_event(session_id: str) -> threading.Event | None
¶
Return the cancel event for a session, if present.
Source code in packages/mewbo_core/src/mewbo_core/loop/session_runtime.py
344 345 346 347 348 | |
get_handle(session_id: str) -> RunHandle | None
¶
Return the run handle for a session, if present.
Source code in packages/mewbo_core/src/mewbo_core/loop/session_runtime.py
350 351 352 353 | |
is_running(session_id: str) -> bool
¶
Return True if the session has an active run.
Source code in packages/mewbo_core/src/mewbo_core/loop/session_runtime.py
338 339 340 341 342 | |
register_loop_run(session_id: str, *, cancel_event: threading.Event, message_queue: queue.Queue[str] | None = None, interrupt_step: threading.Event | None = None) -> bool
¶
Register a loop-backed run (no thread). Mirror of :meth:start.
Used when the caller is already inside a running event loop (Pyodide's
WebLoop) and drives the orchestration as an asyncio task rather than
a daemon thread. Returns False if a live run already exists for the
session. The caller must invoke :meth:finalize_loop_run from the
task's done-callback so the registry stays consistent.
Source code in packages/mewbo_core/src/mewbo_core/loop/session_runtime.py
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 | |
start(session_id: str, target: Callable[[threading.Event], None], *, message_queue: queue.Queue[str] | None = None, interrupt_step: threading.Event | None = None, on_release: Callable[[], None] | None = None) -> bool
¶
Start a new thread-backed run for the session if not already active.
on_release fires once, on the run's own thread, AFTER the handle has
been dropped — so the session's slot is genuinely free and a callback
may start a follow-up run on it. Firing it any earlier (from the run's
own finally, say) cannot work: this registry still holds the slot
there, so a same-session start_async refuses and returns "".
Source code in packages/mewbo_core/src/mewbo_core/loop/session_runtime.py
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 | |
SessionRuntime
¶
Shared orchestration runtime surface for CLI and API.
Source code in packages/mewbo_core/src/mewbo_core/loop/session_runtime.py
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 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 | |
session_store: SessionStoreBase
property
¶
Expose the underlying session store.
__init__(*, session_store: SessionStoreBase | None = None, run_registry: RunRegistry | None = None, goal_retry_gate: GoalRetryGate | None = None) -> None
¶
Initialize the runtime with session storage and optional run registry.
Source code in packages/mewbo_core/src/mewbo_core/loop/session_runtime.py
536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 | |
active_run_handle(session_id: str) -> RunHandle | None
¶
The live :class:RunHandle for session_id, if a run is active.
Read-only steering-signal access for in-run collaborators — the
ask-user question dispatcher polls the handle's cancel_event /
interrupt_step / message_queue while blocked so a steer or
interrupt supersedes a pending question instead of deadlocking behind
it. Callers must treat the handle as read-only.
Source code in packages/mewbo_core/src/mewbo_core/loop/session_runtime.py
1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 | |
append_context_event(session_id: str, context: dict[str, object]) -> None
¶
Append a context event to the session transcript.
Source code in packages/mewbo_core/src/mewbo_core/loop/session_runtime.py
615 616 617 618 619 | |
append_event(session_id: str, event: dict[str, object]) -> None
¶
Append a raw transcript event verbatim.
Unlike :meth:append_context_event (which wraps payloads as
{"type": "context", ...}), this writes the event as-is, so a
completion event reaches :meth:summarize_session — the single
status authority — instead of being hidden inside a context payload.
Source code in packages/mewbo_core/src/mewbo_core/loop/session_runtime.py
632 633 634 635 636 637 638 639 640 | |
approve_plan(session_id: str) -> bool
¶
Approve a pending plan proposal episodically.
Emits a plan_approved event to the transcript. Does NOT start
a new run — the caller (API endpoint) is responsible for starting
the act-mode run via start_async.
Returns False if no pending plan proposal exists or a run is already active.
Source code in packages/mewbo_core/src/mewbo_core/loop/session_runtime.py
1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 | |
arun(*, user_query: str, session_id: str, model_name: str | None = None, fallback_models: tuple[str, ...] | None = None, max_iters: int = 3, initial_plan: Plan | None = None, tool_registry=None, permission_policy=None, approval_callback=None, hook_manager=None, mode: str | None = None, should_cancel: Callable[[], bool] | None = None, allowed_tools: list[str] | None = None, denied_tools: list[str] | None = None, strict_tool_scope: bool = False, capability_mode: str = 'all', skill_instructions: str | None = None, message_queue: queue.Queue[str] | None = None, interrupt_step: threading.Event | None = None, cwd: str | None = None, session_step_budget: int = 0, user_id: str | None = None, source_platform: str | None = None, invocation_id: str | None = None, extra_session_tools: list[SessionTool] | None = None, enable_skills: bool = True, project_autoselect: bool = False, attachments: list[dict] | None = None, user_turn_persisted: bool = False, session_mcp_servers: dict[str, dict] | None = None) -> TaskQueue
async
¶
Run an orchestration request inside an existing event loop.
Async counterpart of :meth:run_sync. Use this when the caller is
itself a coroutine (e.g. an in-browser Flask handler running on
Pyodide's WebLoop) so the orchestration can await without
asyncio.run. Same signature and semantics as :meth:run_sync.
Source code in packages/mewbo_core/src/mewbo_core/loop/session_runtime.py
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 | |
cancel(session_id: str) -> bool
¶
Cancel an active run if present.
Source code in packages/mewbo_core/src/mewbo_core/loop/session_runtime.py
1560 1561 1562 | |
enqueue_message(session_id: str, text: str) -> bool
¶
Enqueue a steering message for the root agent of a running session.
The message is also persisted as a "user" event so it appears in
the session transcript (console timeline, CLI history, Langfuse).
Returns False if no active run or no message queue.
Source code in packages/mewbo_core/src/mewbo_core/loop/session_runtime.py
1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 | |
ensure_session(session_id: str) -> None
¶
Idempotently materialise a session record for a pre-minted id.
Thin delegate to the store's ensure_session. A caller that minted a
session_id outside resolve_session (e.g. the realtime recorder,
which pre-mints to open a Langfuse trace before any store write) calls
this so the session is a real RECORD — visible to list_sessions and
every read surface — not an orphan transcript.
Source code in packages/mewbo_core/src/mewbo_core/loop/session_runtime.py
604 605 606 607 608 609 610 611 612 613 | |
interrupt_step(session_id: str) -> bool
¶
Interrupt the current tool execution step.
The loop continues after the interrupted step with error results. Returns False if no active run or no interrupt event.
Source code in packages/mewbo_core/src/mewbo_core/loop/session_runtime.py
1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 | |
is_running(session_id: str) -> bool
¶
Return True if session has an active run.
Source code in packages/mewbo_core/src/mewbo_core/loop/session_runtime.py
1564 1565 1566 | |
is_terminated(session_id: str) -> bool
¶
Return True iff the session was permanently terminated.
The ONE choke point every entry-point guard reads — a thin read-through
to the store so there is zero duplicated status derivation. An unknown
session reads False (no stamp).
Source code in packages/mewbo_core/src/mewbo_core/loop/session_runtime.py
1579 1580 1581 1582 1583 1584 1585 1586 | |
list_sessions(query: SessionQuery | None = None, *, limit: int | None = None, offset: int = 0) -> list[dict[str, object]]
¶
List sessions with summary metadata, narrowed by query.
O(collection) in rows, and never O(all history) in reads. TWO
batched store calls serve the whole page, and neither scales with how
much any session has recorded:
- :meth:
~SessionStoreBase.list_session_digestsreturns each session's transcript reduced to the events a summary folds. A per-idload_transcripthere would make a listing read every event ever stored, and degrade monotonically forever. load_session_recordsreturns the metadata that is stored ON the session rather than folded from events (title, archived, terminated, owner, tags,pinned_at,projects) in one call for the page instead of per-row reads.
query narrows the digest fetch itself, and that ORDER is what makes
it compose with a page. The whole query goes to
list_session_digests (still called EXACTLY ONCE per listing, which a
test pins), so every predicate answerable from the session record —
owner/archived/pinned/projects — is applied by the store
before it decides which candidates to page, and a session the query
rejects is never opened. Filtering afterwards instead would be worse
than merely slower once limit exists: paging first and filtering the
page would make pinned=True return only the pinned sessions inside
the newest N candidates, which is usually none of them.
The fold itself is unchanged and still single-sourced.
summarize_session sees a smaller event list, not a different
derivation — re-deriving a row's fields with a store-side aggregation
would be a second implementation, free to drift until a row disagrees
with the session it names.
limit/offset bound how many CANDIDATES this call examines, not
how many rows it is guaranteed to return. They page
list_session_digests after query has narrowed the candidate set but
before the two VISIBILITY rules below run, which is what lets a
Mongo-backed store scope its expensive read to the page instead of the
whole collection (see that method's docstring for the measured saving) —
but a candidate dropped below (no visible event and not running, or no
created_at) shrinks the page rather than being backfilled from the
next one. Those two rules stay here because they are the only ones that
need the transcript's EVENTS, so no store query can decide them; they
are hygiene rather than user filters, which is why shrinkage is
acceptable for them and would not have been for pinned.
limit=None (the default) is an unpaginated call.
Ordering is pinned first, then newest first. Two stable sorts rather than one composite key: the second pass only has to move pinned rows to the front, and stability preserves the recency order the first pass established within each group. Pinning is applied HERE, as an ordering over what the query already admitted — never as a way around it. A caller that hides an origin keeps hiding it when the row is pinned, because filtering a sorted list preserves relative order. That is what makes "a mobile surface shows only its own pinned sessions" true by construction, with no surface-specific branch anywhere in this method.
Source code in packages/mewbo_core/src/mewbo_core/loop/session_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 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 | |
load_events(session_id: str, after: str | None = None) -> list[EventRecord]
¶
Load a session's events, narrowed to those newer than after.
O(matched events) on a driver that can range-read, O(one session's
events) on one that cannot — the store decides, which is the point.
Materialising the whole transcript and filtering it in Python would
make after narrow the RESPONSE while the read stayed the record's
entire history: a cursor in name only. Measure the TIME, not the
payload — a shrinking response hides constant work.
An unparseable after returns everything, unchanged: an in-process
caller has no channel to be refused on, and most of them pass no cursor
at all. That widening is a DEFENSIVE default and nothing may rely on it
— the refusal belongs to the surface that accepted the value from a
client, and the /events route 400s before reaching here.
Source code in packages/mewbo_core/src/mewbo_core/loop/session_runtime.py
1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 | |
register_on_terminate(callback: Callable[[str], int | None]) -> None
¶
Register a callback fired once when a session is terminated.
The Wave-2 cascade-cancel seam: the callback receives the terminated
session_id and MAY return an int count of downstream artifacts it
cancelled (e.g. scheduled triggers), which :meth:terminate_session
sums into cancelled_triggers. Best-effort — a raising callback is
logged and skipped, never blocking termination.
Source code in packages/mewbo_core/src/mewbo_core/loop/session_runtime.py
1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 | |
reinject_recovery_context(session_id: str) -> None
¶
Re-emit capability-gating fields so a recovered run keeps them.
The orchestrator reads the most-recent context event when it
builds the system prompt and resolves capability-gated AgentDefs.
After a recovery turn the latest context event may be a plain
mode/model update that does NOT carry the original
client_capabilities / structured_workspace — so a recovered
wiki/QA/structured session would silently lose its capability and
spawn_agent lookups for the gated AgentDefs would fail.
This scans the transcript for the latest value of each gating key
(preserving exactly what the session already had — no origin→capability
map) and appends a single fresh context event carrying them, so the
most-recent context event after recovery still gates correctly. A no-op
when the session never declared any gating field.
Shared by BOTH the API recover endpoint and the CLI recovery command — the single source of truth for recovery capability re-injection.
Source code in packages/mewbo_core/src/mewbo_core/loop/session_runtime.py
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 | |
reject_plan(session_id: str) -> bool
¶
Reject a pending plan proposal.
Emits a plan_rejected event. The session stays dormant —
the user can type refinement guidance as a new message, which
starts a fresh plan-mode run.
Returns False if no pending plan proposal exists or a run is already active.
Source code in packages/mewbo_core/src/mewbo_core/loop/session_runtime.py
1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 | |
resolve_recovery_query(session_id: str, action: RecoveryAction, *, from_ts: str | None = None, replacement_text: str | None = None, trigger: RecoveryTrigger | None = None) -> str
¶
Resolve the user query text for a retry/continue recovery action.
Appends a recovery audit event to the transcript and returns the
query text the caller should pass to :meth:start_async. The
orchestrator automatically picks up prior events via
:class:ContextBuilder, so the caller does not need to trim the
transcript.
replacement_text substitutes the query this method would otherwise
build: for retry the original user message (enabling "edit and
regenerate"), for continue the generic resume prompt. An automatic
re-drive supplies its own deterministic prompt that way rather than
appending a second turn of its own.
trigger names a NON-HUMAN originator on the recovery marker (see
:data:RecoveryTrigger); omitted for every operator-driven recovery.
It is what an automatic re-drive reads back to know it has already
fired.
Raises :class:ValueError when action is unrecognised, there is
no prior user message to recover from, or (for retry) the last
user message is empty.
Raises :class:RuntimeError if a run is already active for the
session — cancel it first.
Source code in packages/mewbo_core/src/mewbo_core/loop/session_runtime.py
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 | |
resolve_session(*, session_id: str | None = None, session_tag: str | None = None, fork_from: str | None = None, fork_at_ts: str | None = None, owner: str | None = None) -> str
¶
Resolve session identifiers, tags, and forks to a session id.
When fork_at_ts is provided alongside fork_from, only events up to (and including) that timestamp are copied into the new session.
owner stamps whichever NEW session this call mints — a fresh one or a
fork. It is an opaque subject string; core never learns what a principal
is (see SessionStoreBase.create_session). Resolving to an EXISTING
session ignores it: ownership is established once, at creation, so
re-engaging someone else's session can never quietly re-stamp it.
Source code in packages/mewbo_core/src/mewbo_core/loop/session_runtime.py
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 | |
run_sync(*, user_query: str, session_id: str, model_name: str | None = None, fallback_models: tuple[str, ...] | None = None, max_iters: int = 3, initial_plan: Plan | None = None, tool_registry=None, permission_policy=None, approval_callback=None, hook_manager=None, mode: str | None = None, should_cancel: Callable[[], bool] | None = None, allowed_tools: list[str] | None = None, denied_tools: list[str] | None = None, strict_tool_scope: bool = False, capability_mode: str = 'all', skill_instructions: str | None = None, message_queue: queue.Queue[str] | None = None, interrupt_step: threading.Event | None = None, cwd: str | None = None, session_step_budget: int = 0, user_id: str | None = None, source_platform: str | None = None, invocation_id: str | None = None, extra_session_tools: list[SessionTool] | None = None, enable_skills: bool = True, project_autoselect: bool = False, attachments: list[dict] | None = None, user_turn_persisted: bool = False, session_mcp_servers: dict[str, dict] | None = None) -> TaskQueue
¶
Run an orchestration request synchronously.
enable_skills=False opts a headless product drive (search/wiki) out
of auto-skill injection so the agent never burns its first step
activating a host ~/.claude skill (default True — CLI/channel
behavior unchanged). capability_mode is the root delegation-privilege
ceiling (default "all" — no filtering); see :meth:start_async.
project_autoselect=True binds list_projects / switch_project
on the ROOT agent so the run chooses its own workspace; default
False binds neither.
user_turn_persisted=True says an upstream seam already wrote this
turn's user event, so the orchestration body must not write a second
one. Default False — a direct caller (the CLI turn engine, the
structured runners) still owns the append.
Source code in packages/mewbo_core/src/mewbo_core/loop/session_runtime.py
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 | |
set_session_pinned(session_id: str, pinned: bool) -> str | None
¶
Pin or unpin a session, returning the resulting pinned_at stamp.
Lives on the runtime for the same reason archive/rename/fork do: it is the ONE place a session's record is mutated, so every surface reaches the store through it rather than around it.
Source code in packages/mewbo_core/src/mewbo_core/loop/session_runtime.py
1076 1077 1078 1079 1080 1081 1082 1083 1084 | |
start_async(*, session_id: str, user_query: str, model_name: str | None = None, fallback_models: tuple[str, ...] | None = None, max_iters: int = 3, initial_plan: Plan | None = None, tool_registry=None, permission_policy=None, approval_callback=None, hook_manager=None, mode: str | None = None, allowed_tools: list[str] | None = None, denied_tools: list[str] | None = None, strict_tool_scope: bool = False, capability_mode: str = 'all', skill_instructions: str | None = None, cwd: str | None = None, session_step_budget: int = 0, user_id: str | None = None, source_platform: str | None = None, invocation_id: str | None = None, extra_session_tools: list[SessionTool] | None = None, enable_skills: bool = True, project_autoselect: bool = False, attachments: list[dict] | None = None, session_mcp_servers: dict[str, dict] | None = None) -> str
¶
Start an asynchronous orchestration run for the session.
capability_mode is the ROOT delegation-privilege ceiling (default
"all" — no filtering). A caller that resolved a
principal's role into a narrower tier (read_only for a viewer)
passes it here so the session's own tools — not only spawned children —
are capped; it travels unchanged into AgentContext.root alongside
workspace_mode.
fallback_models (when provided) opts this run into cross-model
fallback; None defers to the resolved config policy.
Returns a storeless per-run handle run_id of the form
"<session_id>:r<seq>" where seq is the 1-based count of runs
started on this session so far (so one session can host many runs).
The run_id is resolvable back to the session id by splitting on the
first : — no new store or index is required. When the run
registry refuses the start (a run is already active for this
session), an empty string is returned so existing if not started
callers still detect the refusal.
Accepting a turn PERSISTS it: the user event is written here, before
the run is handed off, so a caller that got a run_id can rely on the
transcript already holding the turn. See the block below for why the
executor's own append is suppressed rather than deduplicated.
When the run ends without meeting an explicit goal, :class:GoalRetryGate
re-drives the session ONCE from the post-release seam below. That retry
replays THIS call's arguments unchanged, so it inherits the same tool
registry, hooks, capability ceiling and workspace the operator's run had.
Source code in packages/mewbo_core/src/mewbo_core/loop/session_runtime.py
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 | |
start_command(session_id: str, target: Callable[[threading.Event], None]) -> bool
¶
Start a non-orchestration background run for a slash command.
Reuses the same RunRegistry as start_async so is_running()
and the events-polling pipeline treat command runs identically to
query runs. The FE drives all in-flight UI off the same
authoritative server state — no browser-side patching required.
Source code in packages/mewbo_core/src/mewbo_core/loop/session_runtime.py
1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 | |
summarize_session(session_id: str, *, events: list[EventRecord] | None = None, record: SessionRecord | None = None) -> dict[str, object]
¶
Return a summarized view of a session.
record supplies the session's stored metadata (title, archived,
terminated, owner, tags) when the caller has already batch-loaded it for
a whole page — see :meth:list_sessions. Omitting it reads the same
five facts one at a time, which is what every single-session caller
does and what this method has always done, so the derived summary is
identical either way; only the number of store reads differs.
With no events, the fold's input is the store's DIGEST of the session rather than its whole transcript — the same projection a listing row gets, and identical in result. It matters most on the poll path, which re-derives status once a second per open client: on the largest live session that read was 0.211 s of a 0.470 s poll, for a status that had not changed.
Source code in packages/mewbo_core/src/mewbo_core/loop/session_runtime.py
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 | |
tag_session(session_id: str, tag: str) -> None
¶
Associate a provenance/lookup tag with a session.
Thin delegate to the store so callers that already hold a resolved
session_id (e.g. a structured/realtime run stamping its origin tag)
don't reach into session_store directly. resolve_session remains
the seam for tag-keyed resolution; this is the write-only sibling for
tagging a session you've already created.
Source code in packages/mewbo_core/src/mewbo_core/loop/session_runtime.py
621 622 623 624 625 626 627 628 629 630 | |
terminate_session(session_id: str) -> dict[str, object]
¶
Permanently terminate a session — idempotent and irreversible.
First call: stamps terminated_at, cancels any live run (cooperative,
via the run registry's cancel event), fires the on_terminate
callbacks (summing any returned cancelled-artifact counts), and appends
a session_terminated transcript event — which rides the standard
append_event → SessionEventBus → SSE choke-point, so a live
stream observes the termination with no new transport. A repeat call is
a no-op that returns the SAME shape with the ORIGINAL terminated_at
and cancelled_triggers: 0 (the side effects never re-fire).
Side effects fire exactly once, arbitrated by the store's set-once
write: SessionStoreBase.terminate_session returns True only to
the call that newly stamped the timestamp, so two concurrent FIRST
calls (Flask is threaded even at --workers 1) can't both pass an
unlocked read and duplicate the event + callback fan-out — exactly one
of them wins the race and runs the block below.
Callers guard unknown-session (404) upstream; this assumes the session
exists. Returns {session_id, status:"terminated", terminated_at,
cancelled_triggers}.
Source code in packages/mewbo_core/src/mewbo_core/loop/session_runtime.py
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 | |
SessionTerminatedError
¶
Bases: ValueError
Raised when an operation targets a permanently terminated session.
Termination is a kill switch: a dead session must not be runnable, steerable, recoverable, or fork-resurrectable — copying a terminated transcript into a fresh session would let an agent launder its way around the kill. Raised at the core seam so every caller inherits enforcement; HTTP surfaces map it to 410 Gone.
Source code in packages/mewbo_core/src/mewbo_core/loop/session_runtime.py
137 138 139 140 141 142 143 144 145 | |
parse_core_command(text: str) -> str | None
¶
Return the core command token if present.
Source code in packages/mewbo_core/src/mewbo_core/loop/session_runtime.py
160 161 162 163 164 165 | |
mewbo_core.session.session_store
¶
Session transcript storage and management.
Provides a SessionStoreBase ABC, a filesystem-backed SessionStore
implementation, and a create_session_store() factory that returns the
configured driver (json or mongodb).
SessionPaths
dataclass
¶
Resolved filesystem paths for a session.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
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 | |
SessionRecord
dataclass
¶
The per-session metadata a summary row needs, minus the transcript.
Everything here is stored ON the session record rather than derived by folding events, which is exactly why it can be batch-loaded: a listing needs all of it for every row and none of it depends on reading a transcript.
A plain frozen dataclass, not a Pydantic model: it never crosses a trust boundary — the store builds it from data it just read out of its own backend — so validating each field would buy nothing on a path whose entire purpose is to be cheap.
tags is the reverse tag index for this session (the same list
tags_for_session returns), carried here so a batch resolves the index
once instead of per row.
pinned_at/projects are the two filterable facets
(session/CLAUDE.md → "Filterable facets") and belong here for the same
reason as every other field: both are stored ON the record rather than
folded from events, so a caller reading them one session at a time is
paying the exact per-row round-trip cost this class exists to collapse.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
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 66 67 68 | |
SessionStore
¶
Bases: SessionStoreBase
Filesystem-backed storage for session transcripts and summaries.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
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 | |
__init__(root_dir: str | None = None) -> None
¶
Initialize the store and ensure the root directory exists.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
818 819 820 821 822 823 824 | |
archive_session(session_id: str) -> None
¶
Mark a session as archived.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
1081 1082 1083 1084 1085 1086 | |
create_session(owner: str | None = None) -> str
¶
Create a new session directory and return its identifier.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
857 858 859 860 861 | |
ensure_session(session_id: str, owner: str | None = None) -> None
¶
Idempotently create the session directory for a known id.
For the filesystem driver a session "record" IS its directory (that's
what :meth:list_sessions enumerates), so materialisation is a
makedirs — exist_ok=True makes it a safe no-op on replay.
The owner lands in its own index bucket beside archived/terminated
rather than in a per-session file, so the list filter costs one index read
instead of one stat per session.
The stamp is written ONLY when this call is the one that materialised the
record — the filesystem analogue of the Mongo driver's $setOnInsert,
and the reason the directory's prior existence is checked before creating
it. Stamping on any call would make an ALREADY-UNOWNED session claimable
by whoever touched it next, and since an unowned session is visible to
every lister, that is not necessarily its creator. An unowned call never
writes at all, so a deployment with no identity configured leaves the
index exactly as it was.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
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 | |
get_owner(session_id: str) -> str | None
¶
Return the stamped owning subject, or None if unowned.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
892 893 894 | |
get_pinned_at(session_id: str) -> str | None
¶
Return the stored pinned timestamp, or None.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
1039 1040 1041 1042 1043 | |
get_terminated_at(session_id: str) -> str | None
¶
Return the stored terminated_at timestamp, or None.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
1119 1120 1121 1122 | |
is_archived(session_id: str) -> bool
¶
Return True if a session is archived.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
1097 1098 1099 1100 1101 | |
list_tags() -> dict[str, str]
¶
Return a mapping of tags to session IDs.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
1076 1077 1078 1079 | |
load_summary(session_id: str) -> str | None
¶
Load a previously saved summary, if present.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
965 966 967 968 969 970 971 972 | |
load_title(session_id: str) -> str | None
¶
Load a previously saved title, if present.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
981 982 983 984 985 986 987 988 989 | |
load_transcript(session_id: str) -> list[EventRecord]
¶
Load all transcript events for a session. O(one session's events).
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
913 914 915 | |
projects_for_session(session_id: str) -> list[str]
¶
Return every project identity recorded for a session.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
1060 1061 1062 1063 | |
query_sessions(query: SessionQuery) -> list[str]
¶
List session IDs in the root directory, narrowed by query.
Reads the index ONCE for the whole listing rather than once per
predicate per session — the filesystem driver's every index-backed fact
is a full read-and-parse of index.json, so a per-session lookup would
turn one file read into four times the session count.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
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 | |
record_project(session_id: str, project: str) -> None
¶
Append project to the session's recorded set, if new.
Returns without writing when the project is already recorded, which is the common case: every turn of a bound session re-emits the same context.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 | |
resolve_tag(tag: str) -> str | None
¶
Resolve a tag to a session ID, if present.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
1071 1072 1073 1074 | |
save_summary(session_id: str, summary: str) -> None
¶
Persist a summary for a session.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
958 959 960 961 962 963 | |
save_title(session_id: str, title: str) -> None
¶
Persist a display title for a session.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
974 975 976 977 978 979 | |
session_dir(session_id: str) -> str
¶
Return the directory path for a session.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
900 901 902 | |
set_pinned(session_id: str, pinned: bool) -> None
¶
Stamp or clear pinned for a session in the index.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 | |
stream_transcript(session_id: str) -> Iterator[EventRecord]
¶
Yield transcript events one parsed line at a time.
O(1) in memory, which is what makes the base
:meth:~SessionStoreBase.list_session_digests template usable here: a
listing folds each session's file as it reads and retains only the
relevant events, instead of holding a whole transcript to produce one
row. The PARSE still costs O(one session's events) — a JSONL file
carries no index, so there is no honest way to find a session's
completion event without reading past everything before it, and this
driver's listing therefore stays O(all history) in CPU. That is the
floor for the default driver, and the reason MongoDB is the recommended
backend for a store that has accumulated real history.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
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 | |
tag_session(session_id: str, tag: str) -> None
¶
Associate a tag with a session ID for quick lookup.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
1065 1066 1067 1068 1069 | |
terminate_session(session_id: str) -> bool
¶
Stamp terminated_at in the index once (never overwrites).
Returns whether THIS call inserted the stamp — checked before the
write so a repeat call reports False without touching the file.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 | |
truncate_after(session_id: str, cutoff_ts: str) -> int
¶
Rewrite the transcript keeping only events with ts <= cutoff_ts.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
944 945 946 947 948 949 950 951 952 953 954 955 956 | |
unarchive_session(session_id: str) -> None
¶
Remove archived status from a session.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
1088 1089 1090 1091 1092 1093 1094 1095 | |
SessionStoreBase
¶
Bases: ABC
Abstract interface for session storage backends.
Each driver implements the 13 abstract storage primitives. Higher-level
operations (fork_session, load_recent_events, compact_session)
are concrete template methods built on top of those primitives.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
71 72 73 74 75 76 77 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 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 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 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 | |
__init__() -> None
¶
Initialise the in-memory termination cache shared by every backend.
Populated by :meth:_mark_terminated_cached (called from each
backend's terminate_session) and consulted by
:meth:_guard_append, so a hot-path append never pays a Mongo
round-trip / index-file read to learn whether its own session was
just terminated. Best-effort and per-process only: a session
terminated by a DIFFERENT process/worker is still caught by the
durable terminated_at stamp at every other termination-aware seam
(resolve_session, recovery) — this cache only shortcuts the
common same-process race between a live run and a concurrent
/terminate call.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 | |
append_event(session_id: str, event: Event) -> None
¶
Append a single event record to the session transcript.
No-ops (after a dropped-event log, once per session) once
:meth:terminate_session has stamped this session terminated — see
:meth:_guard_append. The ONE deliberate exception is
:meth:append_terminal_event, used for the termination tombstone
itself.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
161 162 163 164 165 166 167 168 169 170 171 172 173 | |
append_terminal_event(session_id: str, event: Event) -> None
¶
Append an event exempt from the termination guard.
SessionRuntime.terminate_session writes the session_terminated
tombstone through this seam immediately after the store's own
terminate_session has already cached the session as terminated —
an ordinary :meth:append_event call would otherwise drop its own
closing event. No other caller should use this.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
233 234 235 236 237 238 239 240 241 242 | |
append_user_turn(session_id: str, text: str, attachments: list[dict] | None = None) -> None
¶
Append the user event that records ONE accepted turn.
The single builder of that payload, because two seams write it: the
acceptance seam (SessionRuntime.start_async, so the turn is durable
before the executor's cold start) and the orchestration body itself (for
every caller that reaches Orchestrator directly). A second
hand-rolled {"type": "user", ...} literal in either place is free to
drift from this one — silently, since both would still write a
transcript event the readers accept.
attachments is written only when non-empty, mirroring
:class:~mewbo_core.contracts.types.UserPayload's NotRequired key,
so a turn without attachments carries no such key. It additively
duplicates the sibling context event's
descriptors so a client can render attachment cards above the user turn
without joining across events.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
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 | |
archive_session(session_id: str) -> None
abstractmethod
¶
Mark a session as archived.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
407 408 409 | |
compact_session(session_id: str, mode: CompactionMode | None = None, **kwargs: Any) -> CompactionResult
async
¶
Compact a session's transcript using structured summarization.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 | |
create_session(owner: str | None = None) -> str
abstractmethod
¶
Create a new session and return its identifier.
owner is an OPAQUE subject string, never an identity object: core sits
below the identity kernel in the dependency DAG and must not learn what a
principal is. The caller that HAS one resolves it to a string first.
None means unowned, which is what every session created without an
authenticated caller is — see :meth:list_sessions for what that implies
on the read side.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
118 119 120 121 122 123 124 125 126 127 128 | |
ensure_session(session_id: str, owner: str | None = None) -> None
abstractmethod
¶
Idempotently materialise a session RECORD for a known id.
create_session mints its own uuid; some callers (the realtime
write-behind recorder) need to back a session whose id was pre-minted
elsewhere — e.g. for an in-flight Langfuse trace opened before any store
write. Without a record, list_sessions (and every read surface built
on it) never sees the id, so the transcript is an orphan: events exist,
the session is invisible.
This is the seam that closes that gap. It is idempotent — calling it on
an existing session is a no-op (never resets created_at / archived state).
create_session is implemented on top of it (mint id → materialise).
The owner stamp is SET-ONCE at materialisation, like created_at and
unlike archived_at: a replay must not be able to re-point an existing
session at a different subject, which would be an ownership takeover
written through an idempotent no-op path.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 | |
fork_session(source_session_id: str, owner: str | None = None) -> str
¶
Create a new session by copying events, summary, and title from another.
The fork is stamped for whoever asked for it, NOT for the source's owner: a fork is a new session that happens to start with a copy of a transcript. Leaving it unstamped would be worse than either — an unowned fork of an owned session is visible to every lister, so forking would launder a session out of its owner's scope.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 | |
fork_session_at(source_session_id: str, cutoff_ts: str, owner: str | None = None) -> str
¶
Fork a session, keeping only events with ts <= cutoff_ts.
Composes :meth:fork_session + :meth:truncate_after and clears the
copied summary (which may reference events beyond the cutoff).
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
568 569 570 571 572 573 574 575 576 577 578 579 | |
get_owner(session_id: str) -> str | None
abstractmethod
¶
Return the owning subject, or None if the session is unowned.
The read-through sibling of the stamp ensure_session writes, mirroring
how is_archived reads archive_session's write.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
269 270 271 272 273 274 275 | |
get_pinned_at(session_id: str) -> str | None
abstractmethod
¶
Return the stored pinned_at stamp, or None if unpinned.
The read-through sibling of :meth:set_pinned, mirroring how
is_archived reads archive_session's write.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
352 353 354 355 356 357 358 | |
get_terminated_at(session_id: str) -> str | None
abstractmethod
¶
Return the ISO terminated_at timestamp, or None if live.
The read-through sibling of :meth:terminate_session (mirrors how
is_archived reads archive_session's write).
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
437 438 439 440 441 442 443 | |
is_archived(session_id: str) -> bool
abstractmethod
¶
Return True if a session is archived.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
415 416 417 | |
is_terminated(session_id: str) -> bool
¶
Return True iff a session was permanently terminated.
Concrete over :meth:get_terminated_at so both backends share one
implementation — the single derivation every termination guard reads.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
445 446 447 448 449 450 451 | |
last_attestation_hash(session_id: str) -> str
¶
Return the attestation chain's head to re-seed on recovery.
Concrete default over :meth:load_transcript: scans for the most
recent type == "attestation" event and returns its persisted
record_hash, else the chain's genesis hash — mirrors the
tags_for_session concrete-default idiom so every backend shares
one scan; MongoSessionStore overrides with a targeted query.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 | |
latest_context(session_id: str) -> dict[str, object]
¶
Return the session's merged context (most-recent context event wins).
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
522 523 524 | |
latest_event_of_type(session_id: str, event_type: str, *, payload_key: str | None = None) -> EventRecord | None
¶
Return the NEWEST event of event_type, or None when there is none.
O(one session's events) here and O(1) on a driver that can walk
an index backwards (MongoSessionStore overrides). Same honest split
as :meth:load_events_after and :meth:load_recent_events: the base
has no cheap reverse read, so it streams and keeps the last match — a
caller must not read this primitive as cheap on every backend. Memory
stays O(1): it holds one event, never the transcript.
Bounded by the TYPE, never by a count. Tailing the last N events is the tempting cheap answer and it is a wrong one — the newest event of a sparse type sits arbitrarily far back in a session with a long run since the last one, so a window that misses it reports "no such event". That is a wrong ANSWER, not a slow one, and a caller turns it into a refusal.
payload_key narrows further, to events whose payload satisfies
:meth:payload_key_is_set. It exists because "the newest event of this
type" and "the newest event of this type that CARRIES the field I came
for" are different questions, and a caller answering the second with the
first is wrong whenever a later event of the same type omits the field.
Context events are exactly that shape: they are merged key-by-key
(:meth:merge_context_events), so a session can write a project
and then several context events that say nothing about one. Measured on
the deployed store, 15 of the 204 sessions carrying a project
anywhere in context had a NEWER context event without it.
Returns the EVENT, not a field off it, so a second caller wanting a different key out of the same event is served by the same read.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
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 | |
list_session_digests(query: SessionQuery | None = None, *, limit: int | None = None, offset: int = 0) -> list[SessionDigest]
¶
Return one listing digest per session matching query.
The seam a LISTING reads instead of calling :meth:load_transcript per
id. One digest per session, in the order :meth:query_sessions returns
them when limit is None; a session with no events yields an empty
digest rather than being dropped, because whether it belongs on a
listing is the caller's rule (a running session has no events until its
first append). None means an unnarrowed call — every session,
archived included — leaving a caller that filters for itself to do so.
Cost is per DRIVER, and the base template is the expensive one.
This default folds every transcript, so it is O(all history) —
honest, correct, and the reason MongoSessionStore overrides it with
a projection that is O(collection) in rows plus O(summary-relevant
events) in reads. A backend that gains an index owes an override; a
backend that cannot must say so here rather than let a caller assume the
listing is cheap.
What the default still buys: the fold STREAMS, so peak memory is the RELEVANT events rather than the whole transcript — a 10,266-event session never has to be resident to contribute one row.
limit/offset page the RESULT of the fold this driver already pays
for — the file backend has no cheap way to learn a session's first
timestamp without opening it, so paging here narrows what is RETURNED,
not what is READ. MongoSessionStore overrides this to narrow the
read too; see its docstring for why that split is real. Sort key is
each digest's first event's ts (== the eventual created_at for
every row that survives the caller's own visibility filter — see
SessionRuntime.list_sessions), descending, so a page here orders the
same way the final listing does.
The page is cut from what query already admitted. Even on a driver
where paging cannot narrow the read, the two must compose in that order:
filtering a page instead of paging the filtered set would make
pinned=True with a limit return only the pinned sessions inside
the newest N candidates, which is usually none of them.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
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 | |
list_sessions(owner: str | None = None) -> list[str]
¶
List session IDs, optionally narrowed to what owner may see.
Concrete delegate over :meth:query_sessions, kept because it is the
established call shape. include_archived=True is the contract: this
method returns archived sessions too, and the archived filter is applied
by the caller.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
397 398 399 400 401 402 403 404 405 | |
list_tags() -> dict[str, str]
abstractmethod
¶
Return a mapping of tags to session IDs.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
289 290 291 | |
load_events_after(session_id: str, cursor: EventCursor | None) -> list[EventRecord]
¶
Return the events strictly newer than cursor (all of them if None).
O(one session's events) here, and that is the point of the seam
rather than an acceptance of it: the base has no index to narrow with,
so it streams and tests, but a driver that CAN turn the cursor into a
range read overrides this and becomes O(matched events). Filtering a
fully-materialised transcript in Python is a cursor in name only — the
response shrinks and the work does not.
A None cursor means "everything". It never means "the cursor was
bad": an unparseable value is refused at the boundary that received it,
because a filter that cannot be applied must not widen to the whole
collection.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 | |
load_recent_events(session_id: str, limit: int = 8, include_types: set[str] | None = None) -> list[EventRecord]
¶
Load the most recent events, optionally filtered by type.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
689 690 691 692 693 694 695 696 697 698 699 700 701 | |
load_session_records(session_ids: list[str]) -> dict[str, SessionRecord]
¶
Batch-load the per-session metadata one summary row needs.
A LISTING derives every row's title, archived flag, termination stamp, owner, tags, pin stamp and project set. Fetching them one session at a time is seven store reads per row — on a networked driver, seven ROUND TRIPS per row, so the cost of listing scales with the session count times a per-call latency that has nothing to do with how much data is involved. This is the seam that collapses them: one call for the whole page.
This default is the CORRECT-everywhere implementation, not the fast one.
It still reads per session, but it already removes the worst repetition
by resolving the reverse tag index ONCE for the whole batch instead of
rescanning it per row. A driver that can answer the whole batch in a
single query overrides this (see MongoSessionStore); a driver that
cannot inherits behaviour identical to what the caller did by hand, so
adding a driver can never silently produce a WRONG row — only a slower
one.
Unknown ids are returned with an empty record rather than omitted, so a caller can index the result without a membership test.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
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 | |
load_summary(session_id: str) -> str | None
abstractmethod
¶
Load a previously saved summary, if present.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
257 258 259 | |
load_title(session_id: str) -> str | None
abstractmethod
¶
Load a previously saved title, if present.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
265 266 267 | |
load_transcript(session_id: str) -> list[EventRecord]
abstractmethod
¶
Load all transcript events for a session. O(one session's events).
A PER-SESSION read. It must never be called in a loop over sessions —
that is O(all history) wearing a listing's clothes, and it is exactly
the shape :meth:list_session_digests exists to replace.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
244 245 246 247 248 249 250 251 | |
merge_context_events(events: list[EventRecord]) -> dict[str, object]
staticmethod
¶
Reduce a transcript to its current context (most-recent payload wins).
One reducer shared by :meth:latest_context (the trace-provenance path)
and SessionRuntime.summarize_session (the origin/recovery path) so the
rule for "what context is this session running under" lives in exactly one
place. context events are sparse, so a full scan is cheap.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 | |
payload_key_is_set(event: EventRecord, key: str) -> bool
staticmethod
¶
Is key present on this event's payload with a value worth reading?
The ONE spelling of the narrowing :meth:latest_event_of_type applies
for payload_key, published here so MongoSessionStore can push an
equivalent query down rather than restate the rule. Present, not
None, not the empty string — deliberately no further judgement: what
counts as a USABLE value belongs to the caller that knows what the key
means, and a store that guessed would silently skip an event a caller
would have accepted.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 | |
projects_for_session(session_id: str) -> list[str]
abstractmethod
¶
Return every project identity recorded for a session.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
370 371 372 | |
query_sessions(query: SessionQuery) -> list[str]
abstractmethod
¶
Return the session IDs matching query, narrowed at the STORE.
The point of narrowing here rather than at the caller is that the caller
builds each row by loading that session's whole transcript — so a
session rejected by the query is one that is never opened. Every field of
:class:SessionQuery is answerable from the session record alone,
precisely so this can be a single indexed read.
query.owner=None lists EVERYTHING — what a caller holding a
read-all authority (or no identity at all) gets.
A non-None owner narrows to that subject's own sessions PLUS every
UNOWNED one. Unowned is not a hole in the filter, it is the migration
semantic: sessions predating the owner stamp carry no subject, and no
subject can be reconstructed for them after the fact. Hiding them would
make a user's existing work vanish from their own list, which is a worse
failure than showing a pre-existing session to someone who could already
list it before the stamp existed. The unowned set is closed and shrinking
— every session created by an authenticated caller from here on is
stamped — so this is a fading allowance, not a permanent widening.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 | |
record_project(session_id: str, project: str) -> None
abstractmethod
¶
Add project to the set this session has worked in (idempotent).
A SET, not a field, because a session can move: an auto-select session starts with no project and the agent may switch several times, and a filter has to find it under every one of them. Recording is additive and order-free, so a replayed context event is a no-op.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
360 361 362 363 364 365 366 367 368 | |
resolve_tag(tag: str) -> str | None
abstractmethod
¶
Resolve a tag to a session ID, if present.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
285 286 287 | |
save_summary(session_id: str, summary: str) -> None
abstractmethod
¶
Persist a summary for a session.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
253 254 255 | |
save_title(session_id: str, title: str) -> None
abstractmethod
¶
Persist a display title for a session.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
261 262 263 | |
session_digest(session_id: str) -> SessionDigest
¶
Return ONE session's listing digest — the single-session sibling above.
O(one session's summary-relevant events) for a driver that projects,
O(one session's events) for one that folds. Exists because a
summary is not only a listing concern: the poll path re-derives status
for a single session on every tick, and doing that from the full
transcript is the same defect at a different scale — 0.211 s per poll on
the largest live session, once a second, per open client.
Deliberately NOT expressed as list_session_digests narrowed to one
id: that route pays the listing's own setup (enumerating sessions) to
answer a question about one.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 | |
session_dir(session_id: str) -> str
abstractmethod
¶
Return the local directory path for a session (used for attachments).
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
277 278 279 | |
set_pinned(session_id: str, pinned: bool) -> None
abstractmethod
¶
Pin or unpin a session, stamping pinned_at on the record.
Stored as a TIMESTAMP rather than a bool, matching archived_at and
terminated_at, because it doubles as the ordering key: a surface
shows most-recently-pinned first without a second field. Unlike those
two the stamp is REVERSIBLE by design — a pin is a user's assertion
about their own list, not a lifecycle terminal.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
341 342 343 344 345 346 347 348 349 350 | |
stamp(event: Event) -> EventRecord
staticmethod
¶
Build the durable record for event, stamping or canonicalising ts.
The ONE place a stored timestamp is spelled, called by every backend's
_write_event. An event that carries no ts — everything the engine
appends — gets the clock's. One that DOES is normalised to the same UTC
spelling rather than stored verbatim: the mirror-ingest endpoint accepts
a client's own timestamps, and a differing UTC offset would order
differently as TEXT than as an instant. Every ts comparison in this
package is textual (load_transcript's sort, truncate_after's
range, the cursor floor a store pushes down), so a single foreign
spelling would sort a real event into the wrong place — silently, since
text comparison never raises. The INSTANT is preserved; only its
spelling is fixed.
A value that cannot be parsed is kept exactly as sent. It is still evidence of what a client claimed, and replacing it with the clock would forge a timestamp for an event that already has one.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 | |
stream_transcript(session_id: str) -> Iterator[EventRecord]
¶
Yield a session's events in ts order without materialising them.
O(one session's events) in time, O(1) in memory for a driver that
overrides it. The default just iterates :meth:load_transcript, so it
buys nothing on its own — it exists so :meth:list_session_digests has
one seam a line-oriented backend can make genuinely streaming.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
679 680 681 682 683 684 685 686 687 | |
tag_session(session_id: str, tag: str) -> None
abstractmethod
¶
Associate a tag with a session ID for quick lookup.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
281 282 283 | |
tags_for_session(session_id: str) -> list[str]
¶
Return every tag pointing at session_id (reverse of resolve_tag).
Concrete default over list_tags so all backends share one
implementation; the tag set is small. Provenance classification reads
this to recover a session's origin (see session_provenance).
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
293 294 295 296 297 298 299 300 | |
terminate_session(session_id: str) -> bool
abstractmethod
¶
Permanently mark a session terminated (irreversible).
Stamps terminated_at once — a repeat call never moves the
original timestamp. There is deliberately NO un-terminate primitive:
termination is a one-way door. Mirrors
archive_session but without the reverse operation.
Returns True iff THIS call was the one that newly stamped the
timestamp, False if the session was already terminated. This is
the arbitration signal SessionRuntime.terminate_session reads to
run its side effects (cancel + callbacks + event) exactly once even
under concurrent callers — the store's set-once write is the only
thing racing safely, so the runtime must never decide on its own
unlocked read.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 | |
truncate_after(session_id: str, cutoff_ts: str) -> int
abstractmethod
¶
Delete all events with ts > cutoff_ts.
Returns the number of deleted events. Used by the recovery pipeline to clean up a failed run before re-driving.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
453 454 455 456 457 458 459 | |
unarchive_session(session_id: str) -> None
abstractmethod
¶
Remove archived status from a session.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
411 412 413 | |
create_session_store(root_dir: str | None = None) -> SessionStoreBase
¶
Return the configured session store driver.
Reads storage.driver from the app config. Defaults to "json"
(filesystem). Set to "mongodb" to use MongoDB.
Source code in packages/mewbo_core/src/mewbo_core/session/session_store.py
1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 | |
mewbo_core.session.context
¶
Context selection and rendering helpers.
ContextBuilder
¶
Build short-term and selected context for a session.
Source code in packages/mewbo_core/src/mewbo_core/session/context.py
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 | |
__init__(session_store: SessionStoreBase) -> None
¶
Initialize the context builder.
Source code in packages/mewbo_core/src/mewbo_core/session/context.py
197 198 199 | |
build(session_id: str, user_query: str, model_name: str | None) -> ContextSnapshot
¶
Build a context snapshot for planning and synthesis.
Source code in packages/mewbo_core/src/mewbo_core/session/context.py
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 | |
ContextSelection
¶
Bases: BaseModel
Model output for selecting context events.
Source code in packages/mewbo_core/src/mewbo_core/session/context.py
31 32 33 34 35 | |
ContextSnapshot
dataclass
¶
Context snapshot for planning and synthesis.
Source code in packages/mewbo_core/src/mewbo_core/session/context.py
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | |
event_payload_text(event: EventRecord) -> str
¶
Return a readable payload string for an event.
Source code in packages/mewbo_core/src/mewbo_core/session/context.py
55 56 57 58 59 60 61 62 63 64 65 | |
render_event_lines(events: list[EventRecord]) -> str
¶
Render events into bullet lines for prompts.
Source code in packages/mewbo_core/src/mewbo_core/session/context.py
68 69 70 71 72 73 74 75 76 | |
mewbo_core.session.compaction
¶
Lossless pre-compaction utilities.
This module intentionally contains only one thing: a pre_compact hook
that strips ANSI escapes and truncates huge tool outputs before the LLM
summarizer sees them. Zero tokens, zero risk.
Prior versions also shipped should_compact (an event-count heuristic)
and summarize_events (a fallback "summary" that concatenated raw
event text). Both were deleted: compaction decisions are now driven
purely by the API-reported usage_metadata.input_tokens, and failed
structured compaction must not be masked with raw-text noise.
micro_compact_events(events: list[EventRecord]) -> list[EventRecord]
¶
Lossless pre-compaction: strip ANSI escapes and truncate large tool outputs.
Intended for use as a pre_compact hook — no LLM call, zero cost.
The two jobs are INDEPENDENT and applied as such. They used to be one branch, so an escape-laden result under the cap kept every escape — and raising the cap silently widened that band. Stripping is unconditional; only the truncation consults the cap.
Source code in packages/mewbo_core/src/mewbo_core/session/compaction.py
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 | |
mewbo_core.session.token_budget
¶
Token budgeting anchored on LiteLLM-authoritative model metadata.
Philosophy: trust the API, not estimates. LiteLLM's get_model_info is
the source of truth for each model's max_input_tokens; LangChain's
response.usage_metadata.input_tokens is the source of truth for what
the current prompt actually consumed. No char-count heuristics, no fake
overhead additions, no regex guessing from the model name.
TokenBudget
dataclass
¶
Token accounting snapshot used to decide compaction.
Source code in packages/mewbo_core/src/mewbo_core/session/token_budget.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | |
needs_compact: bool
property
¶
Return True when utilization meets or exceeds the configured threshold.
build_usage_numbers(events: list[EventRecord], root_model: str | None) -> dict[str, Any]
¶
Walk a transcript once and return raw usage numbers.
Split by depth so clients can render root (hypervisor) vs sub-agents without conflation. Numbers only — no formatting, no color states, no labels. Clients format what they need.
Returned keys (input has two semantics, output only one):
Context-pressure (peak) — what matters for compaction / window math.
input_tokens on an llm_call_end event is the prompt size for
that call. Within a turn the prompt GROWS as tool results accumulate
(step 1: ~13K baseline, step 11: ~27K), so summing gives a nonsense
number that double-counts the baseline once per call. The peak (max
across root calls) is the real context pressure:
- root_peak_input_tokens: max input_tokens seen on any depth==0 call.
- sub_peak_input_tokens: sum of per-sub-agent peaks (each sub-agent
runs in an isolated context, so summing their peaks — not their sum
inputs — represents "combined peak pressure of parallel sub-contexts").
Cumulative (billable) — what the provider charges for.
Sum across all calls. Useful for cost dashboards. Named with
_billed_in suffix to make the semantic explicit:
- root_input_tokens_billed, sub_input_tokens_billed.
Output is additive everywhere. Each output token is produced once;
summing is correct:
- root_output_tokens, sub_output_tokens.
Other keys: root_model, root_max_input_tokens,
root_last_input_tokens, root_utilization,
tokens_until_compact, compact_threshold,
root_llm_calls, sub_llm_calls, sub_agent_count,
total_input_tokens_billed, total_output_tokens,
compaction_count, compaction_tokens_saved,
models_used (distinct model IDs in first-seen order, collected from
context.model, sub_agent.model, and llm_fallback.to_model).
Source code in packages/mewbo_core/src/mewbo_core/session/token_budget.py
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 | |
estimate_event_tokens(events: Iterable[EventRecord]) -> int
¶
Estimate total tokens for a sequence of events (fallback only).
Used only when no real usage_metadata is available (e.g. a fresh
session before the first LLM call). After the first response lands,
last_input_tokens from the API is the authoritative signal.
Source code in packages/mewbo_core/src/mewbo_core/session/token_budget.py
180 181 182 183 184 185 186 187 188 189 190 191 | |
estimate_summary_tokens(summary: str | None) -> int
¶
Estimate token usage for the stored summary.
Source code in packages/mewbo_core/src/mewbo_core/session/token_budget.py
194 195 196 197 198 | |
forget_cached_context_windows() -> None
¶
Drop memoized catalogue answers after the catalogue changes.
_litellm_max_input_tokens memoizes a MISS as readily as a hit, so a
lookup that ran before the proxy bridge hydrated the catalogue would pin
the pre-hydration answer for the life of the process — and the API serves
usage reads that resolve a window without ever constructing a client.
Registration is the only event that invalidates those answers.
Source code in packages/mewbo_core/src/mewbo_core/session/token_budget.py
151 152 153 154 155 156 157 158 159 160 | |
get_model_max_input_tokens(model_name: str | None) -> int
¶
Resolve the maximum input tokens for a model.
Priority: user override -> LiteLLM catalogue -> config default.
Source code in packages/mewbo_core/src/mewbo_core/session/token_budget.py
123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 | |
get_token_budget(events: Iterable[EventRecord], summary: str | None, model_name: str | None, threshold: float | None = None, *, last_input_tokens: int | None = None) -> TokenBudget
¶
Calculate token utilization and remaining context budget.
When last_input_tokens is supplied (from a real
response.usage_metadata read), it is used as the authoritative
total. Otherwise we fall back to estimating from events + summary.
Source code in packages/mewbo_core/src/mewbo_core/session/token_budget.py
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 | |
read_last_input_tokens(events: list[EventRecord]) -> int | None
¶
Return the most recent llm_call_end event's input_tokens.
Session-store counterpart to the in-memory _last_input_tokens field
on ToolUseLoop. Lets callers outside the loop (e.g. the orchestrator's
compaction check) read the authoritative per-call token count that was
already persisted.
Source code in packages/mewbo_core/src/mewbo_core/session/token_budget.py
401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 | |
mewbo_core.tooling.tool_registry
¶
Tool registry and manifest loading for Mewbo.
ToolRegistry
¶
Registry of configured tools and their instantiated runners.
Source code in packages/mewbo_core/src/mewbo_core/tooling/tool_registry.py
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 | |
__init__() -> None
¶
Initialize an empty registry.
Source code in packages/mewbo_core/src/mewbo_core/tooling/tool_registry.py
208 209 210 211 | |
disable(tool_id: str, reason: str) -> None
¶
Disable a tool and store a reason for later reporting.
Source code in packages/mewbo_core/src/mewbo_core/tooling/tool_registry.py
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 | |
get(tool_id: str) -> ToolRunner | None
¶
Return an enabled tool runner, instantiating it if needed.
Source code in packages/mewbo_core/src/mewbo_core/tooling/tool_registry.py
251 252 253 254 255 256 257 258 259 260 261 262 263 264 | |
get_spec(tool_id: str) -> ToolSpec | None
¶
Return the tool specification, even if disabled.
Source code in packages/mewbo_core/src/mewbo_core/tooling/tool_registry.py
266 267 268 | |
list_specs(include_disabled: bool = False) -> list[ToolSpec]
¶
List tool specifications, optionally including disabled tools.
Source code in packages/mewbo_core/src/mewbo_core/tooling/tool_registry.py
270 271 272 273 274 275 | |
register(spec: ToolSpec) -> None
¶
Register a tool specification and update action validation.
Source code in packages/mewbo_core/src/mewbo_core/tooling/tool_registry.py
244 245 246 247 248 249 | |
tool_catalog() -> list[dict[str, str]]
¶
Return a serialized catalog of registered tool metadata.
Source code in packages/mewbo_core/src/mewbo_core/tooling/tool_registry.py
277 278 279 280 281 282 283 284 285 286 | |
ToolRegistryCache
¶
Process-wide reuse of built ToolRegistry objects, keyed by build inputs.
Orchestrator.__init__ builds the tool registry on every run (per-query),
paying load_registry's cost — reading the MCP manifest, constructing every
ToolSpec, probing Home-Assistant/LSP status — before the run emits its
first event. That work is identical across runs whose inputs are identical, so
the result is cached and the SAME registry handed back on the next run within a
session (kill the blank-shell wait).
The key is exactly the set of inputs that change what load_registry
produces: the project cwd, any plugin-contributed extra_mcp_servers,
and the resolved MCP-config fingerprint (so an edit to mcp.json still forces
a rebuild — the same signal that gates the manifest rebuild in
_ensure_auto_manifest). Allowed-tools scoping is applied per-run downstream
(filter_specs over list_specs), never at build time, so it is
deliberately NOT part of the key.
Source code in packages/mewbo_core/src/mewbo_core/tooling/tool_registry.py
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 | |
__init__() -> None
¶
Initialize an empty, lock-guarded cache.
Source code in packages/mewbo_core/src/mewbo_core/tooling/tool_registry.py
1519 1520 1521 1522 | |
clear() -> None
¶
Drop every cached registry.
Source code in packages/mewbo_core/src/mewbo_core/tooling/tool_registry.py
1573 1574 1575 1576 | |
get_or_build(*, cwd: str | None = None, extra_mcp_servers: dict[str, dict] | None = None, trust_cwd: bool = True) -> ToolRegistry
¶
Return a cached registry for these inputs, building exactly once.
Source code in packages/mewbo_core/src/mewbo_core/tooling/tool_registry.py
1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 | |
ToolRunner
¶
Bases: Protocol
Source code in packages/mewbo_core/src/mewbo_core/tooling/tool_registry.py
79 80 81 82 83 84 85 86 87 88 | |
run(action_step: ActionStep) -> MockSpeaker
¶
Execute an action step and return a speaker response.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
action_step
|
ActionStep
|
Action step payload to execute. |
required |
Returns:
| Type | Description |
|---|---|
MockSpeaker
|
MockSpeaker response from the tool. |
Source code in packages/mewbo_core/src/mewbo_core/tooling/tool_registry.py
80 81 82 83 84 85 86 87 88 | |
ToolSpec
dataclass
¶
Metadata describing a tool available to the assistant.
Source code in packages/mewbo_core/src/mewbo_core/tooling/tool_registry.py
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 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 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 | |
capability_tier() -> str | None
¶
Resolve this tool's privilege tier for capability_mode filtering.
Returns "read" / "write" / "execute", or None when the
tool makes no declaration. A read_only tool is read-tier by
construction (no side effects), so the fallback keeps read_only and
capability in lockstep — a new read-only tool is correctly admitted
under read_only mode without a second annotation, and the failure
mode for a forgotten declaration is safe-deny, not silent grant.
None is deliberately NOT treated as read: an undeclared tool is
withheld from a read_only child.
Source code in packages/mewbo_core/src/mewbo_core/tooling/tool_registry.py
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 | |
knob_mismatches(declared: ToolSpec) -> dict[str, tuple[object, object]]
¶
Fields where THIS spec disagrees with its declared counterpart.
Maps each differing field to (mine, declared). Pure comparison, no
I/O — the two specs arrive as values so a caller can compare a
manifest-loaded spec against the built-in registration that authored it.
This exists because the defect class is cached data outliving the declaration, which nothing else can see: a manifest written before a field existed carries no key for it, the reader defaults it, and the result is a spec that is internally consistent, loads clean, and is wrong. Only a comparison against the declaration catches that.
Source code in packages/mewbo_core/src/mewbo_core/tooling/tool_registry.py
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 | |
with_declared_knobs(declared: ToolSpec) -> ToolSpec
¶
Return this spec with declared's knob values overlaid.
The built-in registration is the AUTHORITY for these fields and the manifest entry is a cache of it, so the declaration wins — which is what lets an already-written manifest self-heal on the next load with no operator step and no regeneration. Everything else on the manifest entry (identity, schema, enablement, MCP wiring) is untouched.
Source code in packages/mewbo_core/src/mewbo_core/tooling/tool_registry.py
173 174 175 176 177 178 179 180 181 182 183 184 | |
capability_mode_admits(capability_mode: str, tier: str | None) -> bool
¶
True if a tool of privilege tier survives capability_mode.
The ONE home of the mode→tier law, shared by the registry filter
(:func:filter_specs) AND the session-tool build
(SessionToolRegistry.ids_for) so the two enforcement surfaces can never
drift (the two-surface trap). all — and any unrecognised mode, since
the authoritative validation is the Literal at the SpawnAgentTask
boundary — admits everything (the gate is skipped). An undeclared tier
(None) is admitted ONLY by all: safe-deny under any restrictive mode.
Source code in packages/mewbo_core/src/mewbo_core/tooling/tool_registry.py
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | |
classify_tool_scope(spec: ToolSpec, *, global_servers: set[str], plugin_servers: set[str]) -> str
¶
Classify a tool spec into its deployment scope.
The four real scope categories:
builtin— a core built-in Python tool (spec.kind != "mcp"), not an MCP server at all.system— an MCP tool whose server is configured in the shared, deployed-instancemcp.json(global_servers).plugin— an MCP tool contributed by an installed plugin (plugin_servers).project— an MCP tool whose server is configured only in the current project's local MCP config (neither of the above).
A genuine user tier — a personal ~/.mewbo config distinct from
the deployed $MEWBO_HOME system instance — is deliberately NOT
implemented: no current infra distinguishes the two in a way worth
surfacing yet.
Source code in packages/mewbo_core/src/mewbo_core/tooling/tool_registry.py
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 | |
filter_specs(specs: list[ToolSpec], *, allowed: list[str] | None = None, denied: list[str] | None = None, capability_mode: str = 'all') -> list[ToolSpec]
¶
Filter tool specs by allowlist, capability mode, and/or denylist.
allowed is THREE-STATE and tested with is None, never truthiness:
None is unrestricted (no allowlist gate), [] grants NOTHING, and a
non-empty list grants exactly those ids. Collapsing [] into None
would turn "this principal gets no tools" into "this principal gets every
tool" — the fail-open direction, on the gate that binds an agent's whole
tool surface.
When the gate applies, only specs whose tool_id is in the list are
kept — EXCEPT always_load specs (the tool_search tool),
which are exempt from the allowlist gate so a scoped sub-agent never
loses the means to fetch its deferred MCP tools.
capability_mode is a coarse privilege pre-filter
applied AFTER the allowlist and layered UNDER it: it can only remove more
tools, never resurrect one the allowlist dropped. Only specs whose
:meth:ToolSpec.capability_tier is admitted by the mode survive — see
CapabilityMode for the tier law. always_load is exempt here too
(harmless discovery), mirroring the allowlist gate; "all" (the default)
and any unrecognised mode skip the gate entirely.
Then any spec whose tool_id appears in denied (merged with the config
agent.default_denied_tools) is removed. Deny always takes precedence
over allow AND capability_mode — an explicit deny removes even an
always_load tool.
Source code in packages/mewbo_core/src/mewbo_core/tooling/tool_registry.py
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 | |
get_or_build_registry(*, cwd: str | None = None, extra_mcp_servers: dict[str, dict] | None = None, trust_cwd: bool = True) -> ToolRegistry
¶
Return a cached ToolRegistry for these inputs, building once per scope.
The single seam Orchestrator uses to avoid rebuilding the registry on
every run in a session. Falls through to :func:load_registry on a cache
miss. See :class:ToolRegistryCache for the keying contract.
Pass trust_cwd=False when cwd holds content this deployment did not
author. A caller that does not know can leave it alone and register the
directory with :data:mewbo_core.config.register_untrusted_cwd instead —
that is read here too, and overrides an affirmative argument.
Source code in packages/mewbo_core/src/mewbo_core/tooling/tool_registry.py
1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 | |
is_always_load(spec: ToolSpec) -> bool
¶
Return True if the tool's full schema must always be in the bound list.
Marked via metadata.always_load=True. An opt-out from deferral —
used by tools that the model needs immediately
(the search tool itself, or any tool whose absence would block the
model from making progress).
Source code in packages/mewbo_core/src/mewbo_core/tooling/tool_registry.py
406 407 408 409 410 411 412 413 414 | |
is_deferred(spec: ToolSpec) -> bool
¶
Return True if the tool's schema should be omitted from the initial bind.
Deferred tools surface as names only via <available-deferred-tools> —
the model fetches their schemas on demand via tool_search. The
deferral rule: always_load wins, the search tool
itself never defers, all MCP tools defer, and other tools opt-in via
metadata.deferred=True.
Source code in packages/mewbo_core/src/mewbo_core/tooling/tool_registry.py
417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 | |
load_registry(manifest_path: str | None = None, *, cwd: str | None = None, extra_mcp_servers: dict[str, dict] | None = None, trust_cwd: bool = True) -> ToolRegistry
¶
Load tool registry, auto-discovering MCP tools when configured.
trust_cwd is the caller's explicit statement about cwd: False means
the directory holds content this deployment did not author, so neither its
own .mcp.json nor any beneath it may name a server. The decision is
carried onto every MCPToolRunner built here, because a runner
re-resolves the config at invocation time — covering the boundary at build
time alone would leak at call time.
Source code in packages/mewbo_core/src/mewbo_core/tooling/tool_registry.py
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 | |
mcp_tool_id(server_name: str, tool_name: str) -> str
¶
Public alias for the canonical mcp_<server>_<tool> id convention.
Anything that must NAME an executable MCP tool outside the registry (the
SCG route projection emitting a probe's allowed_tools, allowlist
builders, trace labels) must derive the id HERE — never by string-mangling
a source_key. A graph source_key (<source>#<Capability>) is a
graph address, not a tool id; passing it to allowed_tools silently
grants nothing (the run-c52e9597 probe failure).
Source code in packages/mewbo_core/src/mewbo_core/tooling/tool_registry.py
889 890 891 892 893 894 895 896 897 898 899 | |
reset_registry_cache() -> None
¶
Drop all cached registries (tests; an explicit /mcp refresh).
Source code in packages/mewbo_core/src/mewbo_core/tooling/tool_registry.py
1604 1605 1606 | |
mewbo_core.classes
¶
Core data models and tool abstractions for Mewbo orchestration.
AbstractTool
¶
Bases: ABC
Base tool with shared initialization helpers.
Source code in packages/mewbo_core/src/mewbo_core/classes.py
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 | |
__init__(name: str, description: str, model_name: str | None = None, use_llm: bool = True) -> None
¶
Initialize tool configuration.
Source code in packages/mewbo_core/src/mewbo_core/classes.py
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 | |
get_state(action_step: ActionStep | None = None) -> MockSpeaker
¶
Perform a read-only action.
Source code in packages/mewbo_core/src/mewbo_core/classes.py
375 376 377 378 | |
run(action_step: ActionStep) -> MockSpeaker
¶
Execute the action based on the operation.
Source code in packages/mewbo_core/src/mewbo_core/classes.py
380 381 382 383 384 385 386 | |
set_state(action_step: ActionStep | None = None) -> MockSpeaker
¶
Perform a state-changing action.
Source code in packages/mewbo_core/src/mewbo_core/classes.py
370 371 372 373 | |
ActionStep
¶
Bases: BaseModel
Action step with validation metadata.
Source code in packages/mewbo_core/src/mewbo_core/classes.py
68 69 70 71 72 73 74 75 76 77 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 | |
OrchestrationState
¶
Bases: BaseModel
State for the orchestration loop.
Source code in packages/mewbo_core/src/mewbo_core/classes.py
175 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 237 238 239 240 241 242 243 244 245 246 247 248 249 | |
terminal_status() -> Literal['completed', 'failed', 'cancelled']
¶
Project this settled state onto the terminal a spawner is told.
done answers "did the loop stop", never "did the task succeed", and
reading it as the latter is what let a doom-looped or budget-spent child
report completed to its parent. A run that stopped short is
failed; only a genuine natural completion whose ground-truth check
did not fail is completed.
verified is False is checked in its own right rather than trusted to
the reason: it is the authoritative record that a ground-truth check ran
and did not pass, and a claim contradicted by ground truth must not
depend on a second field spelling it the same way. It is checked BEFORE
cancellation because a contradicted claim is a substantive failure,
whereas a stop is only a stop.
A cancelled run is neither: nobody claimed the goal was reached and
nothing contradicted a claim, so folding it into failed would report
an error that never happened while completed reports a success that
never happened. It gets the AgentStatus member that means what
occurred. A completed/failed projection cannot express the one
terminal a user causes directly, which is why there is a third member.
The returned values are members of the hypervisor's AgentStatus
vocabulary — this is a NARROWING of that authority, not a vocabulary of
its own, and it is exactly SettledStatus. A halt reports as
failed because AgentStatus has no "stopped short" arm; the
precise reason is not lost — it rides the stop event's detail
and the attestation's done_reason.
Lives on the model rather than on whichever service happens to settle a run: the projection reads nothing but this state's own fields, so a second copy at another call site could only ever drift from this one.
Source code in packages/mewbo_core/src/mewbo_core/classes.py
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 | |
Plan
¶
Bases: BaseModel
Plan with human-readable steps.
Source code in packages/mewbo_core/src/mewbo_core/classes.py
116 117 118 119 120 121 122 123 124 | |
PlanStep
¶
Bases: BaseModel
High-level plan step produced by the planner.
Source code in packages/mewbo_core/src/mewbo_core/classes.py
109 110 111 112 113 | |
TaskQueue
¶
Bases: BaseModel
Queue of executed tool steps and results.
Source code in packages/mewbo_core/src/mewbo_core/classes.py
127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 | |
validate_actions(field: list[ActionStep]) -> list[ActionStep]
classmethod
¶
Normalize and validate action steps.
Source code in packages/mewbo_core/src/mewbo_core/classes.py
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 | |
ToolResult
dataclass
¶
Structured tool execution result.
Source code in packages/mewbo_core/src/mewbo_core/classes.py
51 52 53 54 55 56 57 58 59 | |
create_plan(step_data: list[dict[str, str]] | None = None, is_example: bool = True) -> Plan
¶
Create a Plan from serialized step data.
Source code in packages/mewbo_core/src/mewbo_core/classes.py
404 405 406 407 408 409 410 411 412 413 414 415 | |
create_task_queue(action_data: list[ActionStepPayload] | None = None, is_example: bool = True) -> TaskQueue
¶
Create a TaskQueue from serialized action data.
Source code in packages/mewbo_core/src/mewbo_core/classes.py
389 390 391 392 393 394 395 396 397 398 399 400 401 | |
get_task_master_examples(example_id: int = 0, available_tools: Sequence[str] | None = None) -> str
¶
Return serialized example plan data.
Source code in packages/mewbo_core/src/mewbo_core/classes.py
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 | |
set_available_tools(tool_ids: list[str]) -> None
¶
Update available tool IDs for validation.
Source code in packages/mewbo_core/src/mewbo_core/classes.py
62 63 64 65 | |
mewbo_core.contracts.types
¶
Shared type definitions for core components.
ActionPlanPayload
¶
Bases: TypedDict
Payload describing an action plan.
Source code in packages/mewbo_core/src/mewbo_core/contracts/types.py
21 22 23 24 | |
ActionStepPayload
¶
Bases: TypedDict
Serialized tool call data sent to/from execution.
Source code in packages/mewbo_core/src/mewbo_core/contracts/types.py
27 28 29 30 31 32 33 34 35 36 | |
AgentMessagePayload
¶
Bases: TypedDict
Payload describing an intermediate agent text message.
Source code in packages/mewbo_core/src/mewbo_core/contracts/types.py
161 162 163 164 165 166 | |
AssistantPayload
¶
Bases: TypedDict
Payload describing an assistant response.
Source code in packages/mewbo_core/src/mewbo_core/contracts/types.py
95 96 97 98 | |
CompletionPayload
¶
Bases: TypedDict
Payload describing overall completion state.
Source code in packages/mewbo_core/src/mewbo_core/contracts/types.py
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 | |
DeviceToolCallPayload
¶
Bases: TypedDict
Payload for a client-declared device-tool invocation (device_tool_call).
Emitted when a session-bound ClientDeclaredTool (see client_tools.py)
is invoked; delivered to the client over the session's existing SSE stream.
The client fulfils the call by POSTing its result back, presenting
call_token (single-use, hmac.compare_digest-compared). Honest
threat model: this proves the responder had SESSION-STREAM READ ACCESS
(received the SSE event) and prevents replay (single-use, consumed-once)
— it does NOT prove the response came from the physical device the call
was dispatched to. Any concurrent viewer of the same session's stream
(e.g. a console tab) receives the same token and could answer on the
device's behalf; this is the accepted threat model, distinct from the
session's own API key.
expires_at is an epoch-seconds deadline after which the server gives
up waiting and resolves the tool call with a device_timeout error.
Source code in packages/mewbo_core/src/mewbo_core/contracts/types.py
297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 | |
Event
¶
Bases: TypedDict
Base event payload stored in transcripts.
Source code in packages/mewbo_core/src/mewbo_core/contracts/types.py
443 444 445 446 447 | |
EventRecord
¶
Bases: Event
Event payload with a persisted timestamp.
Source code in packages/mewbo_core/src/mewbo_core/contracts/types.py
450 451 452 453 | |
LlmCallEndPayload
¶
Bases: TypedDict
Payload emitted for a SUCCESSFUL llm_call_end event.
Brackets the whole RetryStrategy logical call — retries and fallback
attempts included, not just the final attempt — so duration_ms is the
wall time a caller actually waited, not the cheapest leg of it. The failed
variant of this event (success: False) carries error_type/reason
instead and is a separate, untyped payload — it never reaches this arm.
Source code in packages/mewbo_core/src/mewbo_core/contracts/types.py
233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 | |
LlmFallbackPayload
¶
Bases: TypedDict
Payload emitted when the run advances to another model (llm_fallback).
reason is either a classifier reason (quota_exhausted,
no_deployments, context_window, auth) for a switch_model
decision, or retries_exhausted when the per-model retry cap tripped on a
transient error. sticky is true when the destination model is pinned for
the rest of the run (always true under the escalation policy).
Source code in packages/mewbo_core/src/mewbo_core/contracts/types.py
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 | |
LlmRetryPayload
¶
Bases: TypedDict
Payload emitted before a same-model LLM retry (llm_retry event).
Source code in packages/mewbo_core/src/mewbo_core/contracts/types.py
198 199 200 201 202 203 204 205 206 207 208 209 210 | |
PermissionPayload
¶
Bases: TypedDict
Payload emitted for permission decisions.
Source code in packages/mewbo_core/src/mewbo_core/contracts/types.py
39 40 41 42 43 44 45 | |
PlanApprovedPayload
¶
Bases: TypedDict
Payload emitted when the user approves a proposed plan.
Source code in packages/mewbo_core/src/mewbo_core/contracts/types.py
178 179 180 181 182 | |
PlanProposedPayload
¶
Bases: TypedDict
Payload emitted when the LLM calls exit_plan_mode.
Source code in packages/mewbo_core/src/mewbo_core/contracts/types.py
169 170 171 172 173 174 175 | |
PlanRejectedPayload
¶
Bases: TypedDict
Payload emitted when the user rejects a proposed plan.
Source code in packages/mewbo_core/src/mewbo_core/contracts/types.py
185 186 187 188 189 | |
PlanStepPayload
¶
Bases: TypedDict
Payload describing a single plan step.
Source code in packages/mewbo_core/src/mewbo_core/contracts/types.py
14 15 16 17 18 | |
RecoveryHaltPayload
¶
Bases: TypedDict
Payload emitted when the doom-loop guard halts a no-progress run.
The recovery event with action == "halt_no_progress" — distinct from
:class:RecoveryPayload (user-triggered retry/continue).
Source code in packages/mewbo_core/src/mewbo_core/contracts/types.py
258 259 260 261 262 263 264 265 266 267 268 269 | |
RecoveryPayload
¶
Bases: TypedDict
Payload emitted when the user triggers retry/continue after a failure.
Source code in packages/mewbo_core/src/mewbo_core/contracts/types.py
192 193 194 195 | |
SubAgentPayload
¶
Bases: TypedDict
Payload describing a sub-agent lifecycle event.
Source code in packages/mewbo_core/src/mewbo_core/contracts/types.py
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 | |
TodoItemPayload
¶
Bases: TypedDict
One authoritative todo item: a label plus its lifecycle status.
status is one of pending / in_progress / completed (see
update_todos.TODO_STATUSES).
Source code in packages/mewbo_core/src/mewbo_core/contracts/types.py
272 273 274 275 276 277 278 279 280 | |
TodosPayload
¶
Bases: TypedDict
Payload for the authoritative live todo list (todos event).
Re-emitted in FULL on every update_todos call (compaction-resilient).
source discriminates the agent's live working set (agent) from an
approved plan's roadmap (plan); agent_id attributes it to the
emitting agent (the root, in practice).
Source code in packages/mewbo_core/src/mewbo_core/contracts/types.py
283 284 285 286 287 288 289 290 291 292 293 294 | |
ToolCallPayload
¶
Bases: TypedDict
Payload describing a tool invocation that is about to be dispatched.
The initiation half of a tool call, emitted BEFORE the tool is awaited so a
client can show the step while it runs rather than only once it finished.
tool_call_id is the provider's call id and the only correlation key to the
matching :class:ToolResultPayload; it is "" when the provider supplied
none, which means "not correlatable" and never "shares a key with the others".
Source code in packages/mewbo_core/src/mewbo_core/contracts/types.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | |
ToolResultPayload
¶
Bases: TypedDict
Payload describing the outcome of a tool invocation.
Source code in packages/mewbo_core/src/mewbo_core/contracts/types.py
67 68 69 70 71 72 73 74 75 76 77 78 79 80 | |
UserPayload
¶
Bases: TypedDict
Payload describing a user message.
Source code in packages/mewbo_core/src/mewbo_core/contracts/types.py
83 84 85 86 87 88 89 90 91 92 | |
UserQuestionAnswerItemPayload
¶
Bases: TypedDict
One delivered answer (indexes XOR text) on the answered event.
Source code in packages/mewbo_core/src/mewbo_core/contracts/types.py
365 366 367 368 369 | |
UserQuestionAnsweredPayload
¶
Bases: TypedDict
Resolution record for a question group (user_question_answered).
outcome is answered / declined (user sent a message instead)
/ interrupted / cancelled / timed_out; answers and
notes are present only when answered. Every surface — not just the one
that answered — folds this onto its pending card.
Only answered settles a card. The other four record that the RUN
stopped waiting, which is not the same as the question being resolved: the
user may still answer, and that answer reaches the session as a new turn.
A surface that greys out its card on any terminal outcome would be hiding
the affordance precisely when the user finally came back to use it.
delivery distinguishes the two landing paths for an answered
outcome — run (the blocked tool call took it) vs message (the run
had moved on, so it arrived as a new turn).
Source code in packages/mewbo_core/src/mewbo_core/contracts/types.py
372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 | |
UserQuestionItemPayload
¶
Bases: TypedDict
One question in a user_question event's group.
Source code in packages/mewbo_core/src/mewbo_core/contracts/types.py
329 330 331 332 333 334 335 | |
UserQuestionOptionPayload
¶
Bases: TypedDict
One selectable option on a user_question event.
Source code in packages/mewbo_core/src/mewbo_core/contracts/types.py
322 323 324 325 326 | |
UserQuestionPayload
¶
Bases: TypedDict
Payload announcing a pending ask-user question group (user_question).
Emitted by the api's question dispatcher when the root agent calls
ask_user_question (see ask_user.py); rides the session's SSE
stream + backlog replay so every attached surface renders the card.
call_token follows the device_tool_call threat model verbatim:
it proves session-stream read access and prevents replay — not which
surface answered.
This event is the DURABLE record of the question, and that is what makes
a late answer possible. The in-process waiter registry is a rendezvous,
not a store; it dies with the run. A client rendering this card long after
the run moved on can still answer, because the answer route recovers the
questions and the token from THIS payload. So the two additive fields are
not decoration: timeout_seconds is what a surface needs to show how
long the run will wait, and notes_placeholder is what makes it render
the free-text box at all. Both are None when the run declared neither.
Source code in packages/mewbo_core/src/mewbo_core/contracts/types.py
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 | |
VerificationPayload
¶
Bases: TypedDict
One verifier-gate check verdict (verification event).
Bounded scalars ONLY: the grounded verifier stdout/stderr is injected into
the model's own context (a SystemMessage), never onto the wire — so a
chatty command can't bloat transcripts. attempt is 1-based; passed
is the interpreted verdict; exit_code/timed_out explain a failure.
Source code in packages/mewbo_core/src/mewbo_core/contracts/types.py
398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 | |
mewbo_core.config
¶
Central JSON configuration for Mewbo.
APIAuthConfig
¶
Bases: BaseModel
Identity & access management for the REST API (opt-in).
Off by default: with no auth block — or enabled: false — every
request resolves to the built-in full-power identity and the server behaves
exactly as it did before IAM existed. The union-shaped fields
(authenticators, the group mappings, bootstrap) are carried here as
open objects and validated in full against the identity kernel's typed models
at server startup, which refuses to boot on an invalid block. These settings
are documented in full in docs/authentication.md.
Source code in packages/mewbo_core/src/mewbo_core/config.py
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 | |
APIAuthScimConfig
¶
Bases: BaseModel
SCIM 2.0 provisioning settings.
Source code in packages/mewbo_core/src/mewbo_core/config.py
1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 | |
APIAuthSessionConfig
¶
Bases: BaseModel
Browser session/cookie settings for federated logins.
Source code in packages/mewbo_core/src/mewbo_core/config.py
1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 | |
APIConfig
¶
Bases: BaseModel
REST API authentication.
Source code in packages/mewbo_core/src/mewbo_core/config.py
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 | |
AgentConfig
¶
Bases: EnvOverridable
Sub-agent hypervisor settings.
Source code in packages/mewbo_core/src/mewbo_core/config.py
2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 2840 2841 2842 2843 2844 2845 2846 2847 2848 2849 2850 2851 2852 2853 2854 2855 2856 2857 2858 2859 2860 2861 2862 2863 2864 2865 2866 2867 2868 2869 2870 2871 2872 2873 2874 2875 2876 2877 2878 2879 2880 2881 2882 2883 2884 2885 2886 2887 2888 2889 2890 2891 2892 2893 2894 2895 2896 2897 2898 2899 2900 2901 2902 2903 2904 2905 2906 2907 | |
ladder_budget_seconds(fallback_count: int) -> float
¶
Worst-case seconds the configured model ladder can spend in one turn.
The primary rung may spend llm_call_timeout x llm_call_retries; every
fallback rung may spend llm_call_timeout x retry.fallback_retries.
The rung count arrives as an ARGUMENT because the ladder is declared
under llm, not here — this model must never reach across the config
tree to read it.
Source code in packages/mewbo_core/src/mewbo_core/config.py
2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 | |
unreachable_rung(fallback_count: int) -> tuple[float, float] | None
¶
(needed, deadline) when the ladder cannot fit, else None.
THE BUDGET LAW. retry.turn_deadline bounds ONE logical LLM call
across every retry and every fallback, and it is checked between
attempts. So rungs that can together consume the whole budget leave
every rung below them unreachable — the chain advances, finds the
deadline spent, and stops. Cross-model fallback then silently never
runs, which reads as a provider-wide outage rather than as the tuning
mistake it is.
Source code in packages/mewbo_core/src/mewbo_core/config.py
2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 | |
AppConfig
¶
Bases: BaseModel
Typed configuration for the Mewbo runtime.
Source code in packages/mewbo_core/src/mewbo_core/config.py
3751 3752 3753 3754 3755 3756 3757 3758 3759 3760 3761 3762 3763 3764 3765 3766 3767 3768 3769 3770 3771 3772 3773 3774 3775 3776 3777 3778 3779 3780 3781 3782 3783 3784 3785 3786 3787 3788 3789 3790 3791 3792 3793 3794 3795 3796 3797 3798 3799 3800 3801 3802 3803 3804 3805 3806 3807 3808 3809 3810 3811 3812 3813 3814 3815 3816 3817 3818 3819 3820 3821 3822 3823 3824 3825 3826 3827 3828 3829 3830 3831 3832 3833 3834 3835 3836 3837 3838 3839 3840 3841 3842 3843 3844 3845 3846 3847 3848 3849 3850 3851 3852 3853 3854 3855 3856 3857 3858 3859 3860 3861 3862 3863 3864 3865 3866 3867 3868 3869 3870 3871 3872 3873 3874 3875 3876 3877 3878 3879 3880 3881 3882 3883 3884 3885 3886 3887 3888 3889 3890 3891 3892 3893 3894 3895 3896 3897 3898 3899 3900 3901 3902 3903 3904 3905 3906 3907 3908 3909 3910 3911 3912 3913 3914 3915 3916 3917 3918 3919 3920 3921 3922 3923 3924 3925 3926 3927 3928 3929 3930 3931 3932 3933 3934 3935 3936 3937 3938 3939 3940 3941 3942 3943 3944 3945 3946 3947 3948 3949 3950 3951 3952 3953 3954 3955 3956 3957 3958 3959 3960 3961 3962 3963 3964 3965 3966 3967 3968 3969 3970 3971 3972 3973 3974 3975 3976 3977 3978 3979 3980 3981 3982 3983 3984 3985 3986 3987 3988 3989 3990 3991 3992 3993 3994 3995 3996 3997 3998 3999 4000 4001 4002 4003 4004 4005 4006 4007 4008 4009 4010 4011 4012 4013 4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 4040 4041 4042 4043 4044 4045 4046 4047 4048 4049 4050 4051 4052 4053 4054 4055 4056 4057 4058 4059 4060 4061 4062 4063 4064 4065 4066 4067 4068 4069 4070 4071 4072 4073 4074 4075 4076 4077 4078 4079 4080 4081 4082 4083 4084 4085 4086 4087 4088 4089 4090 4091 4092 4093 4094 4095 4096 4097 4098 4099 4100 4101 4102 4103 4104 4105 4106 4107 4108 4109 4110 4111 4112 4113 4114 4115 4116 4117 4118 4119 4120 4121 4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 4162 4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 | |
load(path: str | Path) -> AppConfig
classmethod
¶
Load configuration from a JSON file.
Source code in packages/mewbo_core/src/mewbo_core/config.py
3994 3995 3996 3997 3998 | |
preflight(*, disable_on_failure: bool = True) -> dict[str, dict[str, Any]]
async
¶
Run async validation checks for optional integrations.
Source code in packages/mewbo_core/src/mewbo_core/config.py
4163 4164 4165 4166 4167 4168 4169 4170 4171 4172 4173 4174 4175 4176 4177 4178 4179 4180 4181 4182 4183 4184 4185 4186 4187 4188 4189 4190 4191 4192 4193 4194 4195 4196 4197 4198 4199 4200 4201 4202 4203 4204 4205 4206 4207 4208 4209 4210 4211 4212 4213 4214 4215 4216 4217 4218 4219 4220 4221 4222 4223 4224 4225 4226 4227 4228 4229 4230 4231 4232 4233 4234 4235 4236 4237 4238 4239 4240 4241 4242 4243 4244 | |
probe_write_access(path: str | Path) -> ConfigWriteAccess
classmethod
¶
Report whether path could be persisted to, without modifying it.
The probe creates and removes a temporary file in the directory an
atomic :meth:write would stage into — exactly the permission that
write needs — so it never opens, truncates or replaces an existing
config. A missing parent is probed at its nearest existing ancestor
(where mkdir would have to write) rather than being created, so the
probe itself has no side effects at all.
It answers for the SAME rungs :meth:write will try, fallback
included. Reporting a directory-only verdict would say "not writable"
for a single-file-mounted config that saves perfectly well in place,
and a console that disables its Save button on this would then be
refusing a write the server would have accepted.
Source code in packages/mewbo_core/src/mewbo_core/config.py
4122 4123 4124 4125 4126 4127 4128 4129 4130 4131 4132 4133 4134 4135 4136 4137 4138 4139 4140 4141 4142 4143 4144 4145 4146 4147 4148 4149 4150 4151 4152 4153 4154 4155 4156 4157 4158 4159 4160 4161 | |
to_json(*, indent: int = 2) -> str
¶
Serialize config to JSON.
Source code in packages/mewbo_core/src/mewbo_core/config.py
4000 4001 4002 | |
write(path: str | Path, *, indent: int = 2) -> None
¶
Atomically persist THIS MODEL as the whole config file.
Renders every declared field, so an unset one is written out at its
resolved default. That suits a caller scaffolding a fresh config; it is
the wrong tool for saving an edit to a file someone already maintains —
use :meth:write_document for that and see the warning there.
Source code in packages/mewbo_core/src/mewbo_core/config.py
4004 4005 4006 4007 4008 4009 4010 4011 4012 | |
write_document(path: str | Path, document: Mapping[str, Any], *, indent: int = 2) -> None
classmethod
¶
Atomically persist an already-shaped config document.
Editing a config means writing back the operator's OWN document with
their change applied — never a re-rendering of the validated model.
Re-rendering looks equivalent and is not, in two ways that both corrupt
a shared file. It converts every unset field into an explicit default,
so "leave this to the runtime" silently becomes "pin this forever". And
because several defaults are derived from the environment of whichever
process happens to save (MEWBO_HOME feeding the runtime.*
directories, the storage driver's URI), a save from inside a container
rewrites the shared file with container-only absolute paths and
hostnames, which then breaks every other consumer of it. The model is
still the validator — nothing unvalidated reaches disk — it is just not
the thing serialized. This also keeps a key the model does not declare
($schema, a block for a feature with no typed field yet) instead of
dropping it, since extra="ignore" discards those at validation.
Source code in packages/mewbo_core/src/mewbo_core/config.py
4014 4015 4016 4017 4018 4019 4020 4021 4022 4023 4024 4025 4026 4027 4028 4029 4030 4031 4032 4033 4034 4035 4036 4037 4038 4039 | |
AuthenticatorEntry
¶
Bases: BaseModel
One identity source in api.auth.authenticators.
Deliberately PERMISSIVE (extra="allow"): the authoritative model is the
identity kernel's discriminated authenticator union, which sits a layer
above core and must never be imported down into it. Every kind-specific
setting therefore rides through here untyped and is re-validated STRICTLY —
per-kind, extra="forbid" — when the server builds its auth settings at
startup, which refuses to boot on an invalid entry. So this model is not a
second validator and must not grow into one.
What it DOES declare is the plaintext credentials, because the config API
redacts by SCHEMA: a field carries x-secret or its value is returned to
every caller holding config.read. An untyped dict contributes no
schema, so nothing marked these and they were served in the clear. Core
knows these two NAMES — a stable wire contract it shares with the identity
kernel — without knowing which kind each belongs to or what it means, which
is precisely the sliver of knowledge redaction needs and no more.
kind/name stay typed so an entry is self-describing.
Source code in packages/mewbo_core/src/mewbo_core/config.py
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 | |
CLIConfig
¶
Bases: BaseModel
Terminal CLI display and interaction settings.
Source code in packages/mewbo_core/src/mewbo_core/config.py
1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 | |
CliRemoteConfig
¶
Bases: BaseModel
Opt-in remote endpoint for the terminal CLI; CLI-scoped ONLY.
Every other surface ignores this block. When base_url is set the CLI is
still a strictly-local engine (the run loop + authoritative JSONL transcript
stay on this host), but it additionally (a) mirrors each session event to the
remote REST API fire-and-forget for cross-device visibility and (b)
auto-registers the Mewbo MCP server so the product tools
(ask_wiki/search/structured_query + wiki-graph reads) appear in
the CLI registry and execute remotely (compute offload). Empty ⇒ fully local.
Source code in packages/mewbo_core/src/mewbo_core/config.py
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 | |
enabled: bool
property
¶
True when a remote base URL is configured (sync + product tools on).
CompactionConfig
¶
Bases: BaseModel
Summarization prompt selection for conversation compaction.
caveman_mode enables a rule-augmented "caveman" prompt that
instructs the summarizer LLM to drop articles, filler, pleasantries,
and hedging while preserving code, paths, URLs, and error strings
verbatim. Reduces output tokens in the compaction summary without
changing the
<analysis>/<summary> response structure downstream parsers expect.
Source code in packages/mewbo_core/src/mewbo_core/config.py
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 | |
ConfigCheck
dataclass
¶
Result of a configuration preflight check.
Source code in packages/mewbo_core/src/mewbo_core/config.py
4292 4293 4294 4295 4296 4297 4298 4299 4300 4301 4302 4303 4304 4305 4306 4307 4308 4309 4310 | |
to_dict() -> dict[str, Any]
¶
Serialize the check result to a dictionary.
Source code in packages/mewbo_core/src/mewbo_core/config.py
4302 4303 4304 4305 4306 4307 4308 4309 4310 | |
ConfigWriteAccess
¶
Bases: BaseModel
Whether the configuration store can be persisted to.
Source code in packages/mewbo_core/src/mewbo_core/config.py
3500 3501 3502 3503 3504 3505 3506 3507 | |
ConfigWriteError
¶
Bases: RuntimeError
Raised when the configuration file cannot be persisted.
A bare OSError escaping the persistence path reaches an HTTP surface as
an opaque 500 with a traceback and nothing a deployment can act on. This
carries the two things a caller needs instead: a stable machine code to
branch on and an operator-actionable reason to render. The absolute
path stays on the exception (and therefore in the logs) rather than in
the prose, because reason is user-facing copy and a server path is not.
Source code in packages/mewbo_core/src/mewbo_core/config.py
3415 3416 3417 3418 3419 3420 3421 3422 3423 3424 3425 3426 3427 3428 3429 3430 3431 3432 3433 3434 3435 3436 3437 3438 3439 3440 3441 3442 3443 3444 3445 3446 3447 3448 3449 3450 3451 3452 3453 3454 3455 3456 3457 3458 3459 3460 3461 3462 3463 3464 3465 3466 3467 3468 3469 3470 3471 3472 3473 3474 3475 3476 3477 3478 3479 3480 3481 3482 3483 3484 3485 3486 3487 3488 3489 3490 3491 3492 3493 3494 3495 3496 3497 | |
__init__(path: Path, code: str, reason: str) -> None
¶
Build the failure from an already-classified code/reason.
Source code in packages/mewbo_core/src/mewbo_core/config.py
3470 3471 3472 3473 3474 3475 | |
classify(exc: OSError) -> tuple[str, str]
classmethod
¶
Map an OSError to its stable (code, reason) pair.
Source code in packages/mewbo_core/src/mewbo_core/config.py
3482 3483 3484 3485 3486 | |
from_oserror(path: Path, exc: OSError) -> ConfigWriteError
classmethod
¶
Build the typed failure for an OSError raised while persisting.
Source code in packages/mewbo_core/src/mewbo_core/config.py
3493 3494 3495 3496 3497 | |
is_structural(exc: OSError) -> bool
classmethod
¶
Whether exc means atomic replacement can never work at this path.
Source code in packages/mewbo_core/src/mewbo_core/config.py
3488 3489 3490 3491 | |
reason_for(code: str) -> str
classmethod
¶
Return the operator-facing prose for a stable machine code.
Source code in packages/mewbo_core/src/mewbo_core/config.py
3477 3478 3479 3480 | |
ContextConfig
¶
Bases: BaseModel
Context window selection and event filtering.
Source code in packages/mewbo_core/src/mewbo_core/config.py
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 | |
EnvOverridable
¶
Bases: BaseModel
Base for a section whose fields may be OVERRIDDEN from the environment.
A field declares the variable that overrides it next to the field itself, and this base applies every such declaration in one place::
driver: str = Field(
"json",
json_schema_extra={"x-env-var": "MEWBO_STORAGE_DRIVER"},
)
Adding an override is therefore a declaration, not another hand-written
validator that reads os.environ. A hand-written one is invisible to
configs/app.schema.json and so to the console and the docs; a
declaration reaches both, because x-env-var is emitted on the field's
schema node like every other x- annotation.
This is the OPPOSITE direction to :class:EnvRef, and the two are not
interchangeable:
- an :class:
EnvRefis written BY the operator inapp.jsonas the value${VARIABLE}, names a variable the file has chosen to defer to, and is an error at load when that variable is unset; - an override is declared BY this module on a field the operator may have set to a perfectly good literal, and takes precedence over it. An unset — or empty — variable is simply "not overridden", never an error, because the file value is still the answer.
The override is applied to the raw payload, so the field's own validators
still run over it: a bad MEWBO_STORAGE_DRIVER is rejected exactly as a
bad driver in the file is.
Cost: O(1) — one pass over a section's declared fields, at validation.
Source code in packages/mewbo_core/src/mewbo_core/config.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 | |
EnvRef
¶
Bases: BaseModel
A config value that NAMES an environment variable instead of holding one.
Written as a value that is exactly ${VARIABLE}, so a secret can stay in
the environment and out of app.json::
{"llm": {"api_key": "${OPENAI_API_KEY}"}}
Two deliberate limits, both there so this stays a naming convention rather than a template language:
- the reference is the WHOLE value or it is not a reference at all — a value
that merely contains
${is left exactly as written, which is what lets a literal password contain those characters with nothing to escape; - a reference to a variable that is not set is an error at load, never an empty string. Substituting empty turns a missing secret into a puzzling 401 much later; naming a variable is a claim that it will be there, and a claim is worth checking. A variable set to the empty string IS set, and resolves to empty — that is the way to say a value is deliberately blank.
Not to be confused with :class:EnvOverridable, which runs the other way
round: there the FIELD names a variable that overrides whatever the file
says, and an unset variable is a no-op rather than an error.
Cost: O(one record) — one walk of the config document, on load only.
Source code in packages/mewbo_core/src/mewbo_core/config.py
3510 3511 3512 3513 3514 3515 3516 3517 3518 3519 3520 3521 3522 3523 3524 3525 3526 3527 3528 3529 3530 3531 3532 3533 3534 3535 3536 3537 3538 3539 3540 3541 3542 3543 3544 3545 3546 3547 3548 3549 3550 3551 3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 3562 3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 | |
parse(value: Any) -> EnvRef | None
classmethod
¶
Return the reference value spells, or None if it spells none.
Source code in packages/mewbo_core/src/mewbo_core/config.py
3544 3545 3546 3547 3548 3549 3550 | |
resolve(environ: Mapping[str, str], where: str) -> str
¶
Return the variable's value, or raise naming both it and where.
Source code in packages/mewbo_core/src/mewbo_core/config.py
3552 3553 3554 3555 3556 3557 3558 3559 3560 3561 | |
resolve_document(payload: Any, environ: Mapping[str, str], where: str = '') -> Any
classmethod
¶
Rebuild payload with every reference in it replaced by its value.
Returns the payload unchanged — the same object, not a copy — when it
holds no reference, so the common case allocates nothing and the
caller's document is never touched. See
:meth:AppConfig._drop_retired_keys for why not touching it matters.
Source code in packages/mewbo_core/src/mewbo_core/config.py
3563 3564 3565 3566 3567 3568 3569 3570 3571 3572 3573 3574 3575 3576 3577 3578 3579 3580 3581 3582 3583 3584 3585 | |
FallbackConfig
¶
Bases: BaseModel
Opt-in cross-model fallback policy.
Disabled by default so a run never fans out to a different model, with different cost, latency, output style and prompt-cache behaviour, without an explicit opt-in. When disabled, an error that is hopeless on the current model (e.g. quota exhausted) halts cleanly for one-click recovery instead.
Source code in packages/mewbo_core/src/mewbo_core/config.py
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 | |
HomeAssistantConfig
¶
Bases: BaseModel
Home Assistant smart-home integration.
Source code in packages/mewbo_core/src/mewbo_core/config.py
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 | |
HookEntry
¶
Bases: BaseModel
A single hook configuration entry.
Source code in packages/mewbo_core/src/mewbo_core/config.py
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 | |
HooksConfig
¶
Bases: BaseModel
External shell hooks fired during the session lifecycle.
Command hooks run unsandboxed shell commands with the API/CLI process's
own privileges (see HookEntry.command's docstring) — a caller who can
PATCH this section can execute arbitrary code on the host. x-protected
puts the whole section in the same never-read-never-written-via-API tier
as the other host-level settings in this file: settable only by editing
the config file directly, never over the network regardless of
credential (see ConfigSchemaView in apps/mewbo_api).
Source code in packages/mewbo_core/src/mewbo_core/config.py
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 | |
LLMConfig
¶
Bases: BaseModel
LLM provider connection and model selection.
Source code in packages/mewbo_core/src/mewbo_core/config.py
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 | |
effective_fallback_models() -> list[str]
¶
Resolve the active fallback ladder from this instance.
The precedence rule lives HERE, on the data that owns it, so the
module-level accessor (which reads the process-wide config) and any
validator holding a not-yet-installed AppConfig cannot disagree
about how long the ladder is.
Source code in packages/mewbo_core/src/mewbo_core/config.py
690 691 692 693 694 695 696 697 698 699 700 | |
resolve_available_model(model: str, *, fallback: str, timeout: float = 4.0) -> str
¶
Return model if the proxy still advertises it, else fallback.
Guards a persisted/stale model id (e.g. a wiki reindex replaying an old
submission) against a model the proxy has since retired, which would
otherwise fast-fail the whole run on an invalid-model 400. Best-effort:
if the model list can't be fetched we trust model (the caller's
retry/fallback ladder is the backstop). The provider prefix is ignored
on both sides (openai/x matches a bare x the proxy advertises).
Source code in packages/mewbo_core/src/mewbo_core/config.py
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 | |
LSPConfig
¶
Bases: BaseModel
Language Server Protocol integration settings.
Source code in packages/mewbo_core/src/mewbo_core/config.py
2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 | |
LangfuseConfig
¶
Bases: BaseModel
Langfuse LLM observability integration.
Source code in packages/mewbo_core/src/mewbo_core/config.py
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 | |
MongoDBConfig
¶
Bases: EnvOverridable
MongoDB connection settings.
Source code in packages/mewbo_core/src/mewbo_core/config.py
2910 2911 2912 2913 2914 2915 2916 2917 2918 2919 2920 2921 2922 2923 2924 2925 2926 2927 2928 2929 2930 2931 2932 2933 2934 2935 2936 2937 2938 2939 2940 2941 2942 2943 2944 | |
PermissionsConfig
¶
Bases: BaseModel
Tool execution permission policy.
Source code in packages/mewbo_core/src/mewbo_core/config.py
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 | |
PluginsConfig
¶
Bases: BaseModel
Plugin system configuration.
Source code in packages/mewbo_core/src/mewbo_core/config.py
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 | |