agentic¶
The Agentic module provides core components for building intelligent agent systems.
This module contains various Automa implementations for orchestrating and executing LLM-based workflows or agents. These Automa implementations are typically composed together to build complex intelligent agents with advanced capabilities.
ConcurrentAutoma ¶
Bases: GraphAutoma
This class is to provide concurrent execution of multiple workers.
In accordance with the defined "Concurrency Model of Worker", each worker within a ConcurrentAutoma can be configured to operate in one of two concurrency modes:
- Async Mode: Workers execute concurrently in an asynchronous fashion, driven by the event loop of the main thread. This execution mode corresponds to the
arun()method of the Worker. - Parallel Mode: Workers execute synchronously, each running in a dedicated thread within a thread pool managed by the ConcurrentAutoma. This execution mode corresponds to the
run()method of the Worker.
Upon completion of all worker tasks, the concurrent automa instance aggregates the result outputs from each worker into a single list, which is then returned to the caller.
Source code in bridgic/core/agentic/_concurrent_automa.py
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 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 | |
add_worker ¶
add_worker(key: str, worker: Worker) -> None
Add a concurrent worker to the concurrent automa. This worker will be concurrently executed with other concurrent workers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key | str | The key of the worker. | required |
worker | Worker | The worker instance to be registered. | required |
Source code in bridgic/core/agentic/_concurrent_automa.py
add_func_as_worker ¶
Add a function or method as a concurrent worker to the concurrent automa. This worker will be concurrently executed with other concurrent workers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key | str | The key of the function worker. | required |
func | Callable | The function to be added as a concurrent worker to the automa. | required |
Source code in bridgic/core/agentic/_concurrent_automa.py
worker ¶
This is a decorator to mark a function or method as a concurrent worker of the concurrent automa. This worker will be concurrently executed with other concurrent workers.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key | str | The key of the worker. If not provided, the name of the decorated callable will be used. | None |
Source code in bridgic/core/agentic/_concurrent_automa.py
remove_worker ¶
Remove a concurrent worker from the concurrent automa.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key | str | The key of the worker to be removed. | required |
Source code in bridgic/core/agentic/_concurrent_automa.py
all_workers ¶
Gets a list containing the keys of all concurrent workers registered in this concurrent automa.
Returns:
| Type | Description |
|---|---|
List[str] | A list of concurrent worker keys. |
Source code in bridgic/core/agentic/_concurrent_automa.py
SequentialAutoma ¶
Bases: GraphAutoma
This class is to provide an easy way to orchestrate workers in a strictly sequential manner.
Each worker within the SequentialAutoma is invoked in the precise order determined by their positional index, ensuring a linear workflow where the output of one worker can serve as the input to the next.
Upon the completion of all registered workers, the SequentialAutoma returns the output produced by the final worker in the sequence as the overall result to the caller. This design enforces ordered, step-wise processing, making the SequentialAutoma particularly suitable for use cases that require strict procedural dependencies among constituent tasks.
Source code in bridgic/core/agentic/_sequential_automa.py
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 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 | |
add_worker ¶
add_worker(
key: str,
worker: Worker,
*,
args_mapping_rule: ArgsMappingRule = AS_IS
) -> None
Add a sequential worker to the sequential automa at the end of the automa.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key | str | The key of the worker. | required |
worker | Worker | The worker instance to be registered. | required |
args_mapping_rule | ArgsMappingRule | The rule of arguments mapping. | AS_IS |
Source code in bridgic/core/agentic/_sequential_automa.py
add_func_as_worker ¶
add_func_as_worker(
key: str,
func: Callable,
*,
args_mapping_rule: ArgsMappingRule = AS_IS
) -> None
Add a function or method as a sequential worker to the sequential automa at the end of the automa.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key | str | The key of the worker. | required |
func | Callable | The function to be added as a sequential worker to the automa. | required |
args_mapping_rule | ArgsMappingRule | The rule of arguments mapping. | AS_IS |
Source code in bridgic/core/agentic/_sequential_automa.py
worker ¶
worker(
*,
key: Optional[str] = None,
args_mapping_rule: ArgsMappingRule = AS_IS
) -> Callable
This is a decorator to mark a function or method as a sequential worker of the sequential automa, at the end of the automa.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key | str | The key of the worker. If not provided, the name of the decorated callable will be used. | None |
args_mapping_rule | ArgsMappingRule | The rule of arguments mapping. | AS_IS |
Source code in bridgic/core/agentic/_sequential_automa.py
ReActAutoma ¶
Bases: GraphAutoma
A react automa is a subclass of graph automa that implements the ReAct prompting framework.
Source code in bridgic/core/agentic/react/_react_automa.py
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 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 | |
validate_and_transform ¶
async validate_and_transform(
user_msg: Optional[Union[str, UserTextMessage]] = None,
*,
chat_history: Optional[
List[
Union[
UserTextMessage,
AssistantTextMessage,
ToolMessage,
]
]
] = None,
messages: Optional[List[ChatMessage]] = None,
tools: Optional[
List[Union[Callable, Automa, ToolSpec]]
] = None
) -> Dict[str, Any]
Validate and transform the input messages and tools to the canonical format.
Source code in bridgic/core/agentic/react/_react_automa.py
merge_tools_results ¶
async merge_tools_results(
tool_results: List[Any],
tool_calls: List[ToolCall] = From("plan_next_step"),
) -> List[ToolMessage]
Merge the results of the tools.