Core Systems
Core Systems
The core namespace exposes the runtime building blocks that orchestrate workflows in Manager Agent Gym. Use the sections below to understand each component before diving into the full API reference generated by mkdocstrings.
Workflow Execution
WorkflowExecutionEngine advances the simulation timestep-by-timestep, manages task
queues, and gathers metrics for analysis.
Timestep-based workflow execution engine.
Orchestrates agents and evaluations in a discrete-time loop. Tasks run concurrently, while a manager agent observes state and takes actions between timesteps. Produces rich artifacts (snapshots, metrics, logs) for analysis and benchmarking.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
workflow
|
Workflow
|
The workflow graph (tasks, resources, constraints). |
required |
agent_registry
|
AgentRegistry
|
Dynamic registry used to join/leave agents. |
required |
stakeholder_agent
|
StakeholderBase
|
Stakeholder simulator providing preferences and messages over time. |
required |
manager_agent
|
ManagerAgent
|
The decision-making manager agent. |
required |
seed
|
int
|
Global deterministic seed to propagate to components. |
required |
evaluations
|
list[Evaluator] | None
|
Optional workflow-level evaluators to run. |
None
|
output_config
|
OutputConfig | None
|
Output directories and filenames. |
None
|
max_timesteps
|
int
|
Maximum number of timesteps to execute. |
50
|
enable_timestep_logging
|
bool
|
Persist per-timestep snapshots and metrics. |
True
|
enable_final_metrics_logging
|
bool
|
Persist final metrics and summary. |
True
|
communication_service
|
CommunicationService | None
|
Message bus; a default service is created if not provided. |
None
|
timestep_end_callbacks
|
Sequence[Callable[[TimestepEndContext], Awaitable[None]]] | None
|
Optional hooks fired at the end of each timestep (failures logged and ignored). |
None
|
log_preference_evaluation_progress
|
bool
|
Show tqdm progress for preference evals. |
True
|
max_concurrent_rubrics
|
int
|
Concurrency limit for rubric evaluation. |
100
|
reward_aggregator
|
BaseRewardAggregator | None
|
Aggregator used by the evaluator. |
None
|
reward_projection
|
RewardProjection | None
|
Optional projection to scalar reward. |
None
|
Attributes:
| Name | Type | Description |
|---|---|---|
current_timestep |
int
|
Zero-based timestep index. |
execution_state |
ExecutionState
|
Current engine state. |
timestep_results |
list[ExecutionResult]
|
Accumulated per-timestep outputs. |
validation_engine |
ValidationEngine
|
Evaluator used to compute rewards. |
communication_service |
CommunicationService
|
Message hub used by agents. |
Example
engine = WorkflowExecutionEngine(
workflow=my_workflow,
agent_registry=registry,
stakeholder_agent=stakeholder,
manager_agent=manager,
seed=42,
evaluations=[...],
)
results = await engine.run_full_execution()
Source code in manager_agent_gym/core/execution/engine.py
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 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 | |
_check_and_apply_agent_changes() -> list[str]
Check if agents should change and apply changes if needed.
Returns:
| Type | Description |
|---|---|
list[str]
|
List of change descriptions for logging |
Source code in manager_agent_gym/core/execution/engine.py
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 | |
_execute_ready_tasks() -> tuple[list[UUID], list[UUID], list[UUID]]
async
Execute all tasks that are ready to start.
Returns:
| Type | Description |
|---|---|
tuple[list[UUID], list[UUID], list[UUID]]
|
Tuple of (tasks_started, tasks_completed, tasks_failed) |
Source code in manager_agent_gym/core/execution/engine.py
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 | |
_get_preferences_from_stakeholder_agent(timestep: int) -> PreferenceWeights
Resolve stakeholder-owned preferences for the given timestep.
Source code in manager_agent_gym/core/execution/engine.py
307 308 309 310 311 312 | |
_get_task_resources(task: Task) -> list[Resource]
Get input resources for a task.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task
|
Task
|
The task to get resources for |
required |
Returns:
| Type | Description |
|---|---|
list[Resource]
|
List of available input resources |
Source code in manager_agent_gym/core/execution/engine.py
757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 | |
_inject_communication_service() -> None
Inject communication service into all agents in the workflow.
Source code in manager_agent_gym/core/execution/engine.py
602 603 604 605 606 607 608 609 | |
_is_terminal_state() -> bool
Check if execution is in a terminal state.
Source code in manager_agent_gym/core/execution/engine.py
888 889 890 891 892 893 894 | |
_restore_communication_history(messages: list) -> None
Restore communication message history from snapshot.
Source code in manager_agent_gym/core/execution/engine.py
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 | |
_restore_stakeholder_preferences(prefs_data: dict) -> None
Update stakeholder agent preferences to match snapshot.
Source code in manager_agent_gym/core/execution/engine.py
263 264 265 266 267 268 269 270 271 272 273 274 | |
_restore_workflow_state(workflow_snapshot: dict) -> None
Update workflow task and resource states from snapshot.
Source code in manager_agent_gym/core/execution/engine.py
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 | |
_save_workflow_state(timestep_result: ExecutionResult) -> None
async
Save workflow state to disk.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
timestep_result
|
ExecutionResult
|
The timestep result to save |
required |
Source code in manager_agent_gym/core/execution/engine.py
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 | |
_update_workflow_state(completed_tasks: list[UUID], failed_tasks: list[UUID]) -> None
Update workflow state after task completions.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
completed_tasks
|
list[UUID]
|
List of completed task IDs |
required |
failed_tasks
|
list[UUID]
|
List of failed task IDs |
required |
Source code in manager_agent_gym/core/execution/engine.py
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 | |
execute_timestep() -> ExecutionResult
async
Execute a single timestep of the workflow.
Returns:
| Type | Description |
|---|---|
ExecutionResult
|
ExecutionResult with details of what happened |
Source code in manager_agent_gym/core/execution/engine.py
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 | |
get_current_execution_context() -> dict
Get current execution context for evaluation.
Returns execution metadata that evaluators might need.
Source code in manager_agent_gym/core/execution/engine.py
1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 | |
get_current_workflow_state() -> Workflow
Get a snapshot of the current workflow state for external evaluation.
This enables decoupled evaluation where external evaluators can assess the current state without being tightly coupled to the engine.
Returns:
| Type | Description |
|---|---|
Workflow
|
Current workflow state with all tasks, resources, and metadata |
Source code in manager_agent_gym/core/execution/engine.py
990 991 992 993 994 995 996 997 998 999 1000 | |
restore_from_snapshot(snapshot_dir: str, timestep: int) -> None
Restore engine state from a previous simulation snapshot.
This updates the existing engine with state from a snapshot without reconstructing the entire engine. The engine should already be constructed with fresh components (workflow, agents, etc.).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
snapshot_dir
|
str
|
Path to simulation run directory containing timestep_data/ |
required |
timestep
|
int
|
Target timestep to restore from |
required |
Source code in manager_agent_gym/core/execution/engine.py
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 | |
run_full_execution(save_outputs: bool = True) -> list[ExecutionResult]
async
Run the complete workflow execution until completion or failure.
Returns:
| Type | Description |
|---|---|
list[ExecutionResult]
|
List of timestep results from the execution |
Source code in manager_agent_gym/core/execution/engine.py
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 | |
serialise_workflow_states_and_metrics() -> None
Write high-level execution logs (manager actions) into execution_logs directory.
Source code in manager_agent_gym/core/execution/engine.py
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 | |
Manager Agents
ManagerAgent is the abstract contract for decision-making managers. Implement custom
manager strategies by inheriting from this base class.
Bases: ABC
Abstract interface for manager agents.
Implementations observe the workflow, choose an action each timestep, and maintain a compact action history for downstream evaluation.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agent_id
|
str
|
Unique identifier for the manager agent. |
required |
preferences
|
PreferenceWeights
|
Initial normalized preference weights. |
required |
Attributes:
| Name | Type | Description |
|---|---|---|
agent_id |
str
|
Identifier for logging and communications. |
preferences |
PreferenceWeights
|
Current preference weights. |
_action_buffer |
deque[ActionResult]
|
Recent actions (maxlen 50). |
Example
class MyManager(ManagerAgent):
async def step(self, workflow, execution_state, stakeholder_profile,
current_timestep, running_tasks, completed_task_ids,
failed_task_ids, communication_service=None,
previous_reward=0.0, done=False) -> BaseManagerAction:
# decide an action...
return NoOpAction(reasoning="Observing")
Source code in manager_agent_gym/core/manager_agent/interface.py
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 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 | |
configure_seed(seed: int) -> None
Configure deterministic seed for this manager (overridable).
Source code in manager_agent_gym/core/manager_agent/interface.py
60 61 62 | |
create_observation(workflow: Workflow, execution_state: ExecutionState, stakeholder_profile: StakeholderPublicProfile, current_timestep: int, running_tasks: dict, completed_task_ids: set, failed_task_ids: set, communication_service: CommunicationService | None = None) -> ManagerObservation
async
Create manager observation from workflow state.
Subclasses can override this to customize what they observe.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
workflow
|
Workflow
|
Current workflow state |
required |
execution_state
|
ExecutionState
|
Current execution state |
required |
current_timestep
|
int
|
Current timestep number |
required |
running_tasks
|
dict
|
Currently executing tasks |
required |
completed_task_ids
|
set
|
Set of completed task IDs |
required |
failed_task_ids
|
set
|
Set of failed task IDs |
required |
communication_service
|
CommunicationService | None
|
Optional communication service for messages |
None
|
Returns:
| Type | Description |
|---|---|
ManagerObservation
|
ManagerObservation with workflow state data |
Source code in manager_agent_gym/core/manager_agent/interface.py
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 | |
on_action_executed(timestep: int, action: BaseManagerAction, action_result: ActionResult | None) -> None
Hook invoked by the engine after a manager action has been executed.
Default implementation records a compact action brief, including a short outcome summary when available. Manager implementations can override this to customize how actions are logged or persisted.
Source code in manager_agent_gym/core/manager_agent/interface.py
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 | |
reset() -> None
abstractmethod
Reset the manager agent state for a new workflow execution.
Source code in manager_agent_gym/core/manager_agent/interface.py
216 217 218 219 220 221 | |
set_max_timesteps(max_timesteps: int | None) -> None
Set the maximum timesteps for the current execution (set by engine).
Source code in manager_agent_gym/core/manager_agent/interface.py
75 76 77 78 79 | |
step(workflow: Workflow, execution_state: ExecutionState, stakeholder_profile: StakeholderPublicProfile, current_timestep: int, running_tasks: dict, completed_task_ids: set, failed_task_ids: set, communication_service: CommunicationService | None = None, previous_reward: float = 0.0, done: bool = False) -> BaseManagerAction
abstractmethod
async
One-call RL-friendly step: build observation and return an action.
Source code in manager_agent_gym/core/manager_agent/interface.py
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 | |
Worker Interfaces
AgentInterface specifies the capabilities worker agents must expose. Concrete AI and
human simulations live under manager_agent_gym.core.workflow_agents.
Bases: ABC, Generic[ConfigType]
Abstract base class for all agents in the system.
Agents execute tasks and form the core workforce in workflows. They combine execution capabilities with business logic like availability and capacity management.
Source code in manager_agent_gym/core/workflow_agents/interface.py
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 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 | |
agent_id: str
property
Get the agent's unique identifier.
agent_type: str
property
Get the agent's type.
can_handle_task(task: Task) -> bool
Check if agent can handle a given task based on availability.
Source code in manager_agent_gym/core/workflow_agents/interface.py
75 76 77 78 79 80 81 | |
configure_seed(seed: int) -> None
Configure deterministic seed for this agent (overridable).
Source code in manager_agent_gym/core/workflow_agents/interface.py
61 62 63 | |
execute_task(task: Task, resources: list[Resource]) -> ExecutionResult
abstractmethod
async
Execute a task given the task and available resources.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task
|
Task
|
The task to execute |
required |
resources
|
list[Resource]
|
Available input resources (optional) |
required |
Returns:
| Type | Description |
|---|---|
ExecutionResult
|
ExecutionResult with outputs and metadata |
Raises:
| Type | Description |
|---|---|
Exception
|
If execution fails in an unrecoverable way |
Source code in manager_agent_gym/core/workflow_agents/interface.py
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 | |
get_tool_usage_by_task() -> dict[UUID, list[AgentToolUseEvent]]
Return a copy of per-task tool usage events for this agent.
Source code in manager_agent_gym/core/workflow_agents/interface.py
90 91 92 | |
record_tool_use_event(event: AgentToolUseEvent) -> None
Record a tool usage event under the current task bucket.
Source code in manager_agent_gym/core/workflow_agents/interface.py
83 84 85 86 87 88 | |
Agent Registry
AgentRegistry tracks available agents and provides helpers for registering them with
an execution engine.
Dynamic registry for agents participating in a workflow run.
Maintains agent instances, allows late binding of agent classes, and optionally schedules agents to join/leave at specific timesteps.
Example
reg = AgentRegistry()
reg.register_agent_class("ai", AIAgent)
reg.register_agent_class("human_mock", MockHumanAgent)
reg.register_ai_agent(AIAgentConfig(agent_id="ai_analyst"), [])
Source code in manager_agent_gym/core/workflow_agents/registry.py
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 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 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 | |
apply_scheduled_changes_for_timestep(timestep: int, communication_service: CommunicationService | None = None, tool_factory: ToolFactoryType | None = None) -> list[str]
Apply any scheduled add/remove operations for the given timestep.
Returns a list of human-readable change descriptions.
Source code in manager_agent_gym/core/workflow_agents/registry.py
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 | |
clear() -> None
Clear all registered agents.
Source code in manager_agent_gym/core/workflow_agents/registry.py
126 127 128 | |
create_agent(config: AgentConfig) -> AgentInterface
Create an agent instance from configuration.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
AgentConfig
|
Agent configuration |
required |
Returns:
| Type | Description |
|---|---|
AgentInterface
|
Agent instance |
Raises:
| Type | Description |
|---|---|
ValueError
|
If agent type is not registered |
Source code in manager_agent_gym/core/workflow_agents/registry.py
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 | |
get_agent(agent_id: str) -> AgentInterface | None
Get an agent by ID.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agent_id
|
str
|
The agent's unique identifier |
required |
Returns:
| Type | Description |
|---|---|
AgentInterface | None
|
Agent instance or None if not found |
Source code in manager_agent_gym/core/workflow_agents/registry.py
90 91 92 93 94 95 96 97 98 99 100 | |
get_agent_stats() -> dict[str, int]
Get statistics about registered agents.
Returns:
| Type | Description |
|---|---|
dict[str, int]
|
Dictionary with agent type counts |
Source code in manager_agent_gym/core/workflow_agents/registry.py
130 131 132 133 134 135 136 137 138 139 140 141 | |
list_agents() -> list[AgentInterface]
Get all registered agents.
Returns:
| Type | Description |
|---|---|
list[AgentInterface]
|
List of all agent instances |
Source code in manager_agent_gym/core/workflow_agents/registry.py
102 103 104 105 106 107 108 109 | |
register_agent(agent: AgentInterface) -> None
Register an existing agent instance.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agent
|
AgentInterface
|
The agent instance to register |
required |
Source code in manager_agent_gym/core/workflow_agents/registry.py
81 82 83 84 85 86 87 88 | |
register_agent_class(agent_type: str, agent_class: Type[AgentInterface]) -> None
Register an agent class for a specific agent type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agent_type
|
str
|
The type identifier for the agent |
required |
agent_class
|
Type[AgentInterface]
|
The agent class to register |
required |
Source code in manager_agent_gym/core/workflow_agents/registry.py
48 49 50 51 52 53 54 55 56 57 58 | |
register_ai_agent(config: AgentConfig | AIAgentConfig, additional_tools: list[Tool]) -> None
Create and register an AI agent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
AgentConfig | AIAgentConfig
|
Agent configuration |
required |
additional_tools
|
list[Tool]
|
List of tools for the agent |
required |
Returns:
| Type | Description |
|---|---|
None
|
Created AI agent instance |
Source code in manager_agent_gym/core/workflow_agents/registry.py
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 | |
register_human_agent(config: HumanAgentConfig, additional_tools: list[Tool]) -> None
Create and register a human mock agent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
HumanAgentConfig
|
Human agent configuration (includes persona and noise settings) |
required |
additional_tools
|
list[Tool]
|
List of tools for the agent |
required |
Returns:
| Type | Description |
|---|---|
None
|
Created human mock agent instance |
Source code in manager_agent_gym/core/workflow_agents/registry.py
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 | |
remove_agent(agent_id: str) -> bool
Remove an agent from the registry.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agent_id
|
str
|
The agent's unique identifier |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if agent was removed, False if not found |
Source code in manager_agent_gym/core/workflow_agents/registry.py
111 112 113 114 115 116 117 118 119 120 121 122 123 124 | |
Communication Service
CommunicationService stores threaded conversations and broadcasts between agents and
stakeholders throughout a run.
Centralized message hub for agent interactions.
Implements the Communication (C) component of the POSG model. Provides direct, multicast, and broadcast messaging, conversation threads, and grouped views for manager oversight.
Example
comm = CommunicationService()
await comm.broadcast_message(from_agent="manager", content="Kickoff")
inbox = comm.get_messages_for_agent("agent_a", limit=20)
Source code in manager_agent_gym/core/communication/service.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 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 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 | |
_notify_listeners(message: Message) -> None
async
Notify all registered listeners about a new message.
Source code in manager_agent_gym/core/communication/service.py
662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 | |
add_message_listener(agent_id: str, callback: Callable[[Message], Awaitable[None]] | Callable[[Message], None]) -> None
async
Add a listener for new messages to an agent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agent_id
|
str
|
The agent to listen for messages to |
required |
callback
|
Callable[[Message], Awaitable[None]] | Callable[[Message], None]
|
Function to call when new messages arrive |
required |
Source code in manager_agent_gym/core/communication/service.py
644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 | |
add_message_to_thread(thread_id: UUID, from_agent: str, to_agent: str | None, content: str, message_type: MessageType = MessageType.DIRECT, priority: int = 1) -> Message
async
Add a message into an existing thread (direct to one or multicast to participants).
Source code in manager_agent_gym/core/communication/service.py
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 | |
broadcast_message(from_agent: str, content: str, message_type: MessageType = MessageType.BROADCAST, related_task_id: UUID | None = None, exclude_agents: list[str] | None = None, priority: int = 1) -> Message
async
Broadcast a message to all agents in the system.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
from_agent
|
str
|
ID of the sending agent |
required |
content
|
str
|
Message content |
required |
message_type
|
MessageType
|
Type of message |
BROADCAST
|
related_task_id
|
UUID | None
|
Optional task this message relates to |
None
|
exclude_agents
|
list[str] | None
|
Optional list of agents to exclude from broadcast |
None
|
priority
|
int
|
Message priority (1-5) |
1
|
Returns:
| Type | Description |
|---|---|
Message
|
The created Message object |
Source code in manager_agent_gym/core/communication/service.py
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 | |
create_thread(participants: list[str], topic: str | None = None, related_task_id: UUID | None = None) -> CommunicationThread
Create a new conversation thread.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
participants
|
list[str]
|
List of agent IDs to include in the thread |
required |
topic
|
str | None
|
Optional topic for the thread |
None
|
related_task_id
|
UUID | None
|
Optional task this thread relates to |
None
|
Returns:
| Type | Description |
|---|---|
CommunicationThread
|
The created CommunicationThread |
Source code in manager_agent_gym/core/communication/service.py
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 | |
get_agent_view(agent_id: str) -> dict[str, Any]
Get filtered communication view for a specific agent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agent_id
|
str
|
The agent to get the view for |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary containing agent-specific communication data |
Source code in manager_agent_gym/core/communication/service.py
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 | |
get_all_messages() -> list[Message]
Get all messages in the communication system.
Useful for manager oversight and debugging/examples.
Returns:
| Type | Description |
|---|---|
list[Message]
|
List of all messages sorted by timestamp (newest first) |
Source code in manager_agent_gym/core/communication/service.py
318 319 320 321 322 323 324 325 326 327 328 | |
get_all_messages_grouped(grouping: MessageGrouping = MessageGrouping.BY_SENDER, sort_within_group: str = 'time', include_broadcasts: bool = True) -> list[SenderMessagesView] | list[ThreadMessagesView]
Return a strongly-typed view of all messages grouped by sender or thread.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
grouping
|
MessageGrouping
|
How to group messages (by sender or by thread). |
BY_SENDER
|
sort_within_group
|
str
|
Sort messages inside each group by "time" (default) or by "thread" id. |
'time'
|
include_broadcasts
|
bool
|
Whether to include broadcast messages in groups. |
True
|
Returns:
| Type | Description |
|---|---|
list[SenderMessagesView] | list[ThreadMessagesView]
|
A list of |
list[SenderMessagesView] | list[ThreadMessagesView]
|
|
Source code in manager_agent_gym/core/communication/service.py
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 | |
get_communication_analytics() -> dict[str, Any]
Get analytics and insights about communication patterns.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary containing communication analytics |
Source code in manager_agent_gym/core/communication/service.py
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 | |
get_conversation_history(agent_id: str, other_agent: str, limit: int = 50) -> list[Message]
Get conversation history between two agents.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agent_id
|
str
|
First agent ID |
required |
other_agent
|
str
|
Second agent ID |
required |
limit
|
int
|
Maximum number of messages to return |
50
|
Returns:
| Type | Description |
|---|---|
list[Message]
|
List of messages in chronological order |
Source code in manager_agent_gym/core/communication/service.py
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 | |
get_manager_view() -> dict[str, Any]
Get complete communication overview for manager agent.
Provides full visibility into all communications for oversight.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
Dictionary containing comprehensive communication data |
Source code in manager_agent_gym/core/communication/service.py
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 | |
get_messages_for_agent(agent_id: str, since: datetime | None = None, message_types: list[MessageType] | None = None, related_to_task: UUID | None = None, limit: int | None = None, include_broadcasts: bool = True) -> list[Message]
Get messages sent to a specific agent with filtering.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agent_id
|
str
|
The agent to get messages for |
required |
since
|
datetime | None
|
Only return messages after this timestamp |
None
|
message_types
|
list[MessageType] | None
|
Only return messages of these types |
None
|
related_to_task
|
UUID | None
|
Only return messages related to this task |
None
|
limit
|
int | None
|
Maximum number of messages to return |
None
|
include_broadcasts
|
bool
|
Whether to include broadcast messages |
True
|
Returns:
| Type | Description |
|---|---|
list[Message]
|
List of messages sorted by timestamp (newest first) |
Source code in manager_agent_gym/core/communication/service.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 | |
get_messages_grouped_by_sender(sort_within_group: str = 'time', include_broadcasts: bool = True) -> list[SenderMessagesView]
Typed helper: return messages grouped by sender.
Source code in manager_agent_gym/core/communication/service.py
429 430 431 432 433 434 435 436 437 438 439 440 | |
get_recent_broadcasts(since_minutes: int = 60, limit: int = 10) -> list[Message]
Get recent broadcast messages.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
since_minutes
|
int
|
How many minutes back to look |
60
|
limit
|
int
|
Maximum number of broadcasts to return |
10
|
Returns:
| Type | Description |
|---|---|
list[Message]
|
List of recent broadcast messages |
Source code in manager_agent_gym/core/communication/service.py
293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 | |
get_task_communications(task_id: UUID) -> list[Message]
Get all communications related to a specific task.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
task_id
|
UUID
|
The task ID to get communications for |
required |
Returns:
| Type | Description |
|---|---|
list[Message]
|
List of task-related messages sorted by timestamp |
Source code in manager_agent_gym/core/communication/service.py
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 | |
is_end_workflow_requested() -> bool
Return True if an end-of-workflow has been requested.
Source code in manager_agent_gym/core/communication/service.py
60 61 62 | |
mark_message_read(message_id: UUID, agent_id: str) -> bool
Mark a message as read by an agent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message_id
|
UUID
|
The message to mark as read |
required |
agent_id
|
str
|
The agent who read the message |
required |
Returns:
| Type | Description |
|---|---|
bool
|
True if successful, False if message not found |
Source code in manager_agent_gym/core/communication/service.py
547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 | |
request_end_workflow(reason: str | None = None) -> None
Signal that the current workflow should end as soon as possible.
Source code in manager_agent_gym/core/communication/service.py
52 53 54 55 56 57 58 | |
send_direct_message(from_agent: str, to_agent: str, content: str, message_type: MessageType = MessageType.DIRECT, related_task_id: UUID | None = None, thread_id: UUID | None = None, priority: int = 1) -> Message
async
Send a direct message between two agents.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
from_agent
|
str
|
ID of the sending agent |
required |
to_agent
|
str
|
ID of the receiving agent |
required |
content
|
str
|
Message content |
required |
message_type
|
MessageType
|
Type of message |
DIRECT
|
related_task_id
|
UUID | None
|
Optional task this message relates to |
None
|
thread_id
|
UUID | None
|
Optional conversation thread |
None
|
priority
|
int
|
Message priority (1-5) |
1
|
Returns:
| Type | Description |
|---|---|
Message
|
The created Message object |
Source code in manager_agent_gym/core/communication/service.py
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 | |
send_multicast_message(from_agent: str, to_agents: list[str], content: str, message_type: MessageType = MessageType.DIRECT, related_task_id: UUID | None = None, thread_id: UUID | None = None, priority: int = 1) -> Message
async
Send a message to multiple specific agents.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
from_agent
|
str
|
ID of the sending agent |
required |
to_agents
|
list[str]
|
List of recipient agent IDs |
required |
content
|
str
|
Message content |
required |
message_type
|
MessageType
|
Type of message |
DIRECT
|
related_task_id
|
UUID | None
|
Optional task this message relates to |
None
|
thread_id
|
UUID | None
|
Optional conversation thread |
None
|
priority
|
int
|
Message priority (1-5) |
1
|
Returns:
| Type | Description |
|---|---|
Message
|
The created Message object |
Source code in manager_agent_gym/core/communication/service.py
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 | |