Run separate Flow instances; nested agents share only their own run.
(topic: str, runs: int = 3)
| 198 | |
| 199 | |
| 200 | async def run_concurrent(topic: str, runs: int = 3) -> list[RunResult]: |
| 201 | """Run separate Flow instances; nested agents share only their own run.""" |
| 202 | if runs < 1: |
| 203 | raise ValueError("runs must be at least 1") |
| 204 | if get_execution_uuid() is not None: |
| 205 | raise ValueError("Start independent runs outside an active execution session") |
| 206 | |
| 207 | async def run_one(number: int) -> RunResult: |
| 208 | flow = WharfDemoFlow(tracing=True) |
| 209 | output, error = "", None |
| 210 | try: |
| 211 | result = await flow.kickoff_async( |
| 212 | inputs={"topic": topic, "run_number": number} |
| 213 | ) |
| 214 | if not isinstance(result, str): |
| 215 | raise TypeError("Expected the Flow to return a summary string") |
| 216 | output = result |
| 217 | except Exception as exc: |
| 218 | error = f"{type(exc).__name__}: {exc}" |
| 219 | return RunResult( |
| 220 | run_number=number, |
| 221 | execution_uuid=flow.state.execution_uuid, |
| 222 | trace_id=flow.state.trace_id, |
| 223 | output=output, |
| 224 | error=error, |
| 225 | ) |
| 226 | |
| 227 | return await asyncio.gather(*(run_one(number) for number in range(1, runs + 1))) |
| 228 | |
| 229 | |
| 230 | def main() -> int: |
no test coverage detected