- Orchestration
- Control flow
Orchestration
Control flow
Run a step once per item, skip a step, or call another workflow.
A workflow is a fixed graph, but three things change at run time: how many times a step runs, whether it runs, and which other workflows it starts.
| Need | Use |
|---|---|
| Run a step for each item of a list | step.map(...) |
| Leave a step out of this run | ava.skip(...) |
| Run another workflow and use its result | ava.call(...) |
| Start another workflow and move on | ava.start_run(...) |
Map
step.map(items) runs the step once per item, side by side, and gives the next step the list of
results in order.
@ava.workflow
def articles():
jobs = select_jobs() # returns a list
drafts = write_article.map(jobs) # one agent per job
return publish_batch(drafts) # receives the list of drafts
Rendering diagram…
| Option | Default | Meaning |
|---|---|---|
max_items | 8 | Most items allowed. Raise it up to 64. A longer list fails the run; it is never cut short. |
fail_fast | True | Stop at the first failed item. False lets the other items finish first. |
| keyword arguments | Passed unchanged to every item: write_article.map(jobs, tone="formal"). |
Works on every kind of step. For an agent declared in the workflow: ava.agent.step.map(Signature, items).
Skip
Call ava.skip inside a step that has nothing to do. The step ends as skipped, with the
reason shown. It is not a failure, and the run still succeeds.
@ava.step
def score(lead: Lead) -> Score:
if not lead.qualified:
ava.skip("Lead is not qualified")
...
@ava.step
def decide(score: Score | None) -> str: # accepts None: still runs
return "pass" if score is None else "review"
| The next step’s parameter | What happens |
|---|---|
Accepts None (Score | None) | It runs and receives None |
Does not accept None | It is skipped too |
In a map, a skipped item is left out of the list.
Call another workflow
@ava.workflow
def onboard():
customer = load_customer()
report = ava.call(credit_check, customer) # wait for its result
ava.start_run(send_welcome, customer) # start it, do not wait
return decide(report)
ava.call | ava.start_run | |
|---|---|---|
| Waits for the other workflow | Yes | No |
| Gives you | Its result | Its run ID |
| Options | timeout=, when= | when= |
when= takes a step’s boolean output. When it is False, nothing starts and the step shows as skipped.
ava.start_run(send_welcome, customer, when=is_new(customer))
