Review a collection with an agent
Use EACH when the same process applies to several items. This example reviews three chapters in order. The reader sees its earlier conversation when reviewing the next chapter.
Review a collection with an agent
Use EACH when the same process applies to several items. This example reviews
three chapters in order. The reader sees its earlier conversation when reviewing
the next chapter.
TEAM desk
reader USING "book-reviewer"
END
PROCESS review(chapters) WITH reader
EACH chapter IN chapters
ASK(reader, "Review this chapter in the light of earlier chapters.", chapter)
END
END
report = review([
"Chapter one: the village loses its water supply.",
"Chapter two: residents repair the old reservoir.",
"Chapter three: the village agrees how to maintain it."
]) USING desk
Save the model, open Agent → Tasks → Processes, select report, choose the
model for book-reviewer, and press Start process. Inspect the three replies
and the final ordered list. Each result has a one-based position and a value:
[{"key": 1, "value": "First review"}, {"key": 2, "value": "Second review"}]
The example is abbreviated to two result rows. Actual output contains one row
for each input chapter. An empty collection returns [] and makes no calls.
Use ASK(FRESH reader, ...) to review each item without prior conversation.
The item name and any variables declared inside the loop stay inside it.
Carry a running summary
For a cumulative result, name its initial state with WITH:
PROCESS summarize(chapters) WITH reader
EACH chapter IN chapters WITH summary = ""
ASK(reader, "Extend the running summary.",
{summary: summary, chapter: chapter})
END
END
Each answer becomes the next summary. The expression returns the last answer,
or the seed "" when the collection is empty. The result type must stay the same
as the seed. Bind this recipe with summary = summarize([...]) USING desk and
start that plan to run it.
The collection can also come from an earlier typed answer, such as
ASK(reader, "List the regions") EXPECT [string]. The runtime checks its
actual size before starting the loop. A human participant can answer each item
in turn using the existing review form; the process waits without occupying an
execution worker.
Choose a bounded task list
A local conditional can select between known lists without reserving 32 copies of the body:
full = ASK(editor, "Should we cover both assignments?") EXPECT boolean
topics = full THEN ["Library opening", "Park cleanup"] ELSE ["Library opening"]
EACH topic IN topics
RUN review(topic) USING writer = writer, editor = editor
END
The compiler reserves the larger branch before the editor answers. The complete routed newsroom reserves five model calls: one routing decision, then drafting and review for up to two assignments. A short edition uses three calls. Invalid routing responses stop before an assignment starts. Both paths execute in native tests; Desktop verification remains pending. This selects among authored work lists; it does not authorize a model to add procedures or increase the budget.
Current boundaries
Desktop currently supports sequential traversal of finite data arrays, with up
to 32 items per traversal. Larger inputs fail before any iteration runs; they
are never truncated. Unknown parameter and computed collections reserve the 32-iteration
upper bound. A literal directly in EACH, such as EACH chapter IN ["First", "Second"],
reserves its structural item count instead. Immutable local bindings preserve
that bound: topics = ["First", "Second"] followed by EACH topic IN topics
works the same way, including local aliases. Conditional local lists reserve
the larger branch's known bound; if either branch is unknown, they retain 32. Published values and unknown process
parameters retain the conservative ceiling. Known lists retain their bound when
passed to reusable PROCESS parameters, including forwarding through helpers. Empty literals conservatively reserve
one body but execute none. This lets small fixed lists use multi-step child
workflows without reserving 32 copies. The runtime enforces the admitted maximum
before the first body action, and plan inspection shows that maximum. The
small newsroom sample
drafts and reviews two fixed assignments with five reserved frames and four
model calls. Native execution is tested; its Desktop walkthrough remains pending. Loops share the original deadline and spending
limits. Collected results also obey the run's retained-data limit.
POPULATION, partial joins and generated participant bindings remain planned.
Independent child traversal is covered by the newsroom guide. This implementation does not create extra agents from
data. Existing fresh child processes, API reads, sharing, human waits and
conditional steps may appear inside a sequential body.
Reuse the workflow with a different list
PROCESS double(items)
EACH item IN items
item * 2
END
END
report = double([2, 3])
The call reserves two iterations. Another call with one item gets its own
reservation. Immutable local lists, aliases and bounded conditional lists also
keep their bounds through RUN. An oversized replacement argument fails before
the receiving process starts its body. Published and other unknown inputs keep
the conservative ceiling.
The reusable newsroom sample passes two assignments into a shared drafting/review process and reserves five frames and four model calls. Native execution is covered; Desktop proof is pending.
Create the review from the Process surface
Choose Create process → Review a list, supply a Grid array as the example input, and Apply draft in Code. The draft includes one reviewer and an ordered EACH loop. Review and Save, then bind the reviewer profile and Start the plan. Creating the draft performs no inference. Its default two-item list reserves two calls, and the reviewer sees earlier replies while working through the list.