Batch Fan‑Out
batch runs multiple independent tasks in parallel and merges their results back to the main chain.
Scenario, problem, solution
Scenario: call multiple tools/services in parallel.
Problem: sequential execution adds latency linearly.
Solution: use batch to fan out and auto‑merge results.
python
import asyncio
from agently import TriggerFlow, TriggerFlowEventData
flow = TriggerFlow()
@flow.chunk("one")
async def one(data: TriggerFlowEventData):
await asyncio.sleep(0.01)
return f"one:{data.value}"
@flow.chunk("two")
async def two(data: TriggerFlowEventData):
await asyncio.sleep(0.02)
return f"two:{data.value}"
flow.batch(one, two).end()
result = flow.start("X")
print(result)Output:
text
{'one': 'one:X', 'two': 'two:X'}