Asynchronous execution entry supporting standard and KV-reuse workflows.
(
self,
input: Dict[str, str],
num_rounds: int = 1,
max_tries: int = 3,
max_time: int = 600,
*,
mode: str = "default",
**kwargs,
)
| 259 | return final_answers |
| 260 | |
| 261 | async def arun( |
| 262 | self, |
| 263 | input: Dict[str, str], |
| 264 | num_rounds: int = 1, |
| 265 | max_tries: int = 3, |
| 266 | max_time: int = 600, |
| 267 | *, |
| 268 | mode: str = "default", |
| 269 | **kwargs, |
| 270 | ) -> List[Any]: |
| 271 | """Asynchronous execution entry supporting standard and KV-reuse workflows.""" |
| 272 | if mode == "default": |
| 273 | request_uid = input.setdefault( |
| 274 | "_request_uid", shortuuid.ShortUUID().random(length=8) |
| 275 | ) |
| 276 | metrics_recorder.start_request( |
| 277 | request_uid=request_uid, |
| 278 | batch_index=input.get("_batch_index"), |
| 279 | task=input.get("task"), |
| 280 | execution_mode=mode, |
| 281 | ) |
| 282 | for round in range(num_rounds): |
| 283 | self.construct_spatial_connection() |
| 284 | self.construct_temporal_connection(round) |
| 285 | |
| 286 | in_degree = { |
| 287 | node_id: len(node.spatial_predecessors) |
| 288 | for node_id, node in self.nodes.items() |
| 289 | } |
| 290 | zero_in_degree_queue = [ |
| 291 | node_id for node_id, deg in in_degree.items() if deg == 0 |
| 292 | ] |
| 293 | |
| 294 | while zero_in_degree_queue: |
| 295 | current_node_id = zero_in_degree_queue.pop(0) |
| 296 | tries = 0 |
| 297 | while tries < max_tries: |
| 298 | await asyncio.wait_for( |
| 299 | self.nodes[current_node_id].async_execute(input), |
| 300 | timeout=max_time, |
| 301 | ) |
| 302 | break |
| 303 | for successor in self.nodes[current_node_id].spatial_successors: |
| 304 | if successor.id not in self.nodes: |
| 305 | continue |
| 306 | in_degree[successor.id] -= 1 |
| 307 | if in_degree[successor.id] == 0: |
| 308 | zero_in_degree_queue.append(successor.id) |
| 309 | |
| 310 | self.update_memory() |
| 311 | if self.decision_node: |
| 312 | self.connect_decision_node() |
| 313 | await self.decision_node.async_execute(input) |
| 314 | final_answers = self.decision_node.outputs |
| 315 | if len(final_answers) == 0: |
| 316 | final_answers.append("No answer of the decision node") |
| 317 | metrics_recorder.finalize_request(request_uid) |
| 318 | else: |
no test coverage detected