Skip to main content
Version: 1.0.0

Process a list in parallel

Transform a batch of tickets with a typed target, bounded concurrency and ordered results. This first walkthrough uses neither a model nor a handler: verify composition before adding external effects.

1. Write the program​

Create batch.tb:

batch.tb
module examples.parallel_batch

strategy Label
takes ticket as Text
gives Text
do
give "Ticket: " ++ ticket

strategy Run
takes tickets as List of Text
gives List of Text
uses Label
do
parallel Label
each ticket in tickets
with ticket as ticket
max_concurrency 2
max_items 8
into labels
give labels

Run orchestrates; Label produces a value for each input. The group admits at most eight tickets and executes at most two branches simultaneously.

2. Execute​

touba compile batch.tb --out batch.air.json
touba run batch.air.json \
--entry strategy:examples.parallel_batch/Run \
--inputs-json '{"tickets":["T-3","T-1","T-2"]}' \
--output result

Expected result: ["Ticket: T-3","Ticket: T-1","Ticket: T-2"]. It follows input order even when branches finish in a different order. This small pure transformation does not measure a performance improvement.

3. Test bounds​

  • With {"tickets":[]}, the result is [].
  • With nine tickets, the run refuses with ParallelItemLimitExceeded before the group's first call.
  • A non-text value in the list causes an input refusal.

The business testing guide provides an executable test file for this program, with success and refusal assertions.

4. Keep a recovery point​

touba run batch.air.json \
--entry strategy:examples.parallel_batch/Run \
--inputs-json '{"tickets":["T-3","T-1"]}' \
--parallel-checkpoint-out progress.json \
--output result
touba run batch.air.json \
--entry strategy:examples.parallel_batch/Run \
--parallel-resume-checkpoint progress.json \
--output result

The second command restores completed results without calling the targets again. Treat this checkpoint as private data: it may contain business arguments and results. Do not alter its identity to force resumption of an incompatible program.

Move to agents or tools​

The target can be a skill, agent or tool with an explicit output signature. Add its actual authorizations and dependencies; parallelism does not supply them. The multi-agent guide demonstrates composition, and the parallel guide explains budgets, errors, shared memory and human pauses.