Graph
GraphOrchestrator
Bases: Orchestrator
Orchestrates the execution of complex tasks, interconnected within the graph structure.
This class manages the execution by following structure of directed graph. When finished synthesizes the results into a final answer.
Attributes:
Name | Type | Description |
---|---|---|
manager |
ManagerAgent
|
The managing agent responsible for overseeing the orchestration process. |
context |
Dict[str, Any]
|
Context of the orchestrator. |
states |
List[GraphState]
|
List of states within orchestrator. |
initial_state |
str
|
State to start from. |
objective |
Optional[str]
|
The main objective of the orchestration. |
max_loops |
Optional[int]
|
Maximum number of transition between states. |
Source code in dynamiq/nodes/agents/orchestrators/graph.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 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 |
|
add_conditional_edge(source_id, destination_ids, condition, callbacks=[])
Adds conditional edge to the graph. Conditional edge provides opportunity to choose between destination states based on condition.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
source_id |
str
|
Id of the source state. |
required |
destination_ids |
list[str]
|
Ids of destination states. |
required |
condition |
Callable | Python
|
Condition that will determine next state. |
required |
callbacks |
list[NodeCallbackHandler]
|
list[NodeCallbackHandler]: List of callbacks. |
[]
|
Raises: ValueError: If state with specified id is not present.
Source code in dynamiq/nodes/agents/orchestrators/graph.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 |
|
add_edge(source_id, destination_id)
Adds edge to the graph. When source state finishes execution, destination state will be executed next.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
source_id |
str
|
Id of source state. |
required |
destination_id |
str
|
Id of destination state. |
required |
Raises:
Type | Description |
---|---|
ValueError
|
If state with specified id does not exist. |
Source code in dynamiq/nodes/agents/orchestrators/graph.py
149 150 151 152 153 154 155 156 157 158 159 160 161 |
|
add_state(state)
Adds state to the graph.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
state |
State
|
State to add to the graph. |
required |
Raises:
Type | Description |
---|---|
ValueError
|
If state with specified id already exists. |
Source code in dynamiq/nodes/agents/orchestrators/graph.py
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 |
|
add_state_by_tasks(state_id, tasks, callbacks=[])
Adds state to the graph based on tasks.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
state_id |
str
|
Id of the state. |
required |
tasks |
list[Node | Callable]
|
List of tasks that have to be executed when running this state. |
required |
callbacks |
list[NodeCallbackHandler]
|
list[NodeCallbackHandler]: List of callbacks. |
[]
|
Raises: ValueError: If state with specified id already exists.
Source code in dynamiq/nodes/agents/orchestrators/graph.py
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 |
|
get_next_state_by_manager(state, config, **kwargs)
Determine the next state based on the current state and history. Uses GraphAgentManager.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
state |
State
|
Current state. |
required |
config |
Optional[RunnableConfig]
|
Configuration for the runnable. |
required |
**kwargs |
Additional keyword arguments. |
{}
|
Returns:
Name | Type | Description |
---|---|---|
State |
GraphState
|
Next state to execute. |
Raises:
Type | Description |
---|---|
OrchestratorError
|
If there is an error parsing the action from the LLM response. |
StateNotFoundError
|
If the state is invalid or not found. |
Source code in dynamiq/nodes/agents/orchestrators/graph.py
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 |
|
init_components(connection_manager=None)
Initialize components of the orchestrator.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
connection_manager |
Optional[ConnectionManager]
|
The connection manager. Defaults to ConnectionManager. |
None
|
Source code in dynamiq/nodes/agents/orchestrators/graph.py
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
|
run_flow(input_task, config=None, **kwargs)
Process the graph workflow.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
input_task |
str
|
The task to be processed. |
required |
config |
RunnableConfig
|
Configuration for the runnable. |
None
|
Returns:
Type | Description |
---|---|
dict[str, Any]
|
dict[str, Any]: The final output generated after processing the task and inner context of orchestrator. |
Source code in dynamiq/nodes/agents/orchestrators/graph.py
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 |
|
setup_streaming()
Setups streaming for orchestrator.
Source code in dynamiq/nodes/agents/orchestrators/graph.py
348 349 350 351 352 353 354 |
|
states_descriptions(states)
Get a formatted string of states descriptions.
Source code in dynamiq/nodes/agents/orchestrators/graph.py
298 299 300 301 302 |
|
to_dict(**kwargs)
Converts the instance to a dictionary.
Returns:
Name | Type | Description |
---|---|---|
dict |
dict
|
A dictionary representation of the instance. |
Source code in dynamiq/nodes/agents/orchestrators/graph.py
83 84 85 86 87 88 89 90 91 92 |
|
validate_states(ids)
Check if the provided state ids are valid.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
ids |
list[str]
|
State ids to validate. |
required |
Raises:
Type | Description |
---|---|
ValueError
|
If state with specified id does not exist. |
Source code in dynamiq/nodes/agents/orchestrators/graph.py
163 164 165 166 167 168 169 170 171 172 173 174 175 |
|
StateNotFoundError
Bases: OrchestratorError
Raised when next state was not found.
Source code in dynamiq/nodes/agents/orchestrators/graph.py
17 18 19 |
|