API: Orchestrators
This section covers the classes responsible for executing agent workflows.
safeagent.orchestrator
SimpleOrchestrator
Minimal DAG runner: each node is a function, edges define dependencies, with audit and lineage tagging.
Source code in src/safeagent/orchestrator.py
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
|
add_edge(src, dest)
Specify that 'dest' depends on 'src'.
Source code in src/safeagent/orchestrator.py
19 20 21 22 23 |
|
add_node(name, func)
Register a function under the given node name.
Source code in src/safeagent/orchestrator.py
14 15 16 17 |
|
run(inputs)
Execute all nodes in topological order, audit pipeline start/end, and tag lineage on outputs.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
inputs
|
Dict[str, Any]
|
Global inputs (e.g., 'user_input', 'user_id'). |
required |
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
Dict[str, Any]: Mapping of node name to its return value. |
Source code in src/safeagent/orchestrator.py
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 |
|
safeagent.stateful_orchestrator
EdgeRegistrationError
Bases: OrchestratorError
Raised during an invalid attempt to register an edge.
Source code in src/safeagent/stateful_orchestrator.py
19 20 21 22 23 |
|
NodeNotFoundError
Bases: OrchestratorError
Raised when a node name is not found in the graph.
Source code in src/safeagent/stateful_orchestrator.py
13 14 15 16 17 |
|
OrchestratorError
Bases: Exception
Base exception for all stateful orchestrator errors.
Source code in src/safeagent/stateful_orchestrator.py
9 10 11 |
|
StateValidationError
Bases: OrchestratorError
Raised when the state does not conform to the defined schema.
Source code in src/safeagent/stateful_orchestrator.py
25 26 27 28 |
|
StatefulOrchestrator
An orchestrator that manages a central state object, allowing for complex, cyclical, and conditional workflows with integrated governance, human-in-the-loop interrupts, and optional state schema validation.
Source code in src/safeagent/stateful_orchestrator.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 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 |
|
__init__(entry_node, state_schema=None)
Initializes the stateful orchestrator.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
entry_node
|
str
|
The name of the first node to execute in the graph. |
required |
state_schema
|
Optional[Dict[str, Type]]
|
An optional schema defining expected keys and their Python types in the state object. |
None
|
Source code in src/safeagent/stateful_orchestrator.py
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
|
resume(state, human_input, user_id='system', max_steps=15)
Resumes execution of a paused graph.
Source code in src/safeagent/stateful_orchestrator.py
100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
|
run(inputs, user_id='system', max_steps=15)
Executes the graph starting from the entry node.
Returns:
Type | Description |
---|---|
str
|
A tuple containing the final status ('completed', 'paused', 'error') |
Dict[str, Any]
|
and the final state of the graph. |
Source code in src/safeagent/stateful_orchestrator.py
86 87 88 89 90 91 92 93 94 95 96 97 98 |
|