args¶
The Args module provides Arguments Mapping and Arguments Injection mechanisms in Bridgic.
ArgsMappingRule ¶
Bases: Enum
Enumeration of Arguments Mapping rules for worker parameter passing.
ArgsMappingRule defines how the return values from predecessor workers are mapped to the parameters of the current worker. This controls the data flow between workers in an automa execution graph.
Attributes:
| Name | Type | Description |
|---|---|---|
AS_IS | Enum | Preserves the exact order and types of return values from predecessor workers. No unpacking or merging is performed. |
UNPACK | Enum | Unpacks the return value from the predecessor worker and passes as individual arguments. Only valid when the current worker has exactly one dependency and the return value is a list/tuple or dict. |
MERGE | Enum | Merges all return values from predecessor workers into a single tuple as the only argument of the current worker. |
SUPPRESSED | Enum | Suppresses all return values from predecessor workers. No arguments are passed to the current worker from its dependencies. |
Examples:
Note
- AS_IS is the default mapping rule when not specified
- UNPACK requires exactly one dependency and a list/tuple/dict return value
- MERGE combines all predecessor outputs into a single tuple argument
- SUPPRESSED allows workers to ignore dependency outputs completely
Source code in bridgic/core/types/_common.py
From dataclass ¶
Bases: ArgsDescriptor
Implementing arguments injection for worker parameters with default value.
When a worker needs the output of another worker but does not directly depend on it in execution, you can use From to declare an arguments injection in its parameters.
Attributes:
| Name | Type | Description |
|---|---|---|
key | str | The key of the worker to inject arguments from. |
default | Optional[Any] | The default value of the arguments. |
Examples:
Returns:
| Type | Description |
|---|---|
Any | The output of the worker specified by the key. |
Raises:
| Type | Description |
|---|---|
WorkerArgsInjectionError | If the worker specified by the key does not exist and no default value is set. |
Note:
- Can set a default value for a
Fromdeclaration, which will be returned when the specified worker does not exist. - Will raise
WorkerArgsInjectionErrorif the worker specified by the key does not exist and no default value is set.
Source code in bridgic/core/automa/args/_args_descriptor.py
System dataclass ¶
Bases: ArgsDescriptor
Implementing system-level arguments injection for worker parameters.
System provides access to automa-level resources and context through arguments injection. It supports pattern matching for different types of system resources.
Attributes:
| Name | Type | Description |
|---|---|---|
key | str | The system resource key to inject. Supported keys: - "runtime_context": Runtime context for data persistence across worker executions. - "automa": Current automa instance. - "automa:worker_key": Sub-automa instance in current automa. |
Examples:
Returns:
| Type | Description |
|---|---|
Any | The system resource specified by the key: - RuntimeContext: For "runtime_context" - AutomaInstance: For current automa instance or a sub-automa instance from the current automa. |
Raises:
| Type | Description |
|---|---|
WorkerArgsInjectionError |
|
Note
- "runtime_context" provides a
RuntimeContextinstance for data persistence - "automa" provides access to the current automa instance
- "automa:worker_key" provides access to a sub-automa from the specified worker key
Source code in bridgic/core/automa/args/_args_descriptor.py
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 | |