Skip to contents

Each argument is a peter() call; it is evaluated with deferral on, so it builds its session without running it, and all members then run together on one reactor, at most max_active at a time. The result is a team session: team$text joins the members' answers under ### <name> (<model>) headings (a failed member's says (ended with status error)), team$value is the named list of their values, and team$<name> (or team[[i]]) is a member's session. Piping the team into peter() continues it: then team$text (and printing) is the team's own answer, team$value its own value once a turn designates one, and each member's answer stays at team$<name>$text.

Usage

gptr_parallel(
  ...,
  .list = NULL,
  max_active = NULL,
  on_error = c("return", "stop")
)

Arguments

...

Named peter() calls (or sessions created with .run = FALSE).

.list

A named list of sessions created with .run = FALSE.

max_active

The number of members that run at once; NULL uses the option gptr.subagents.max_active (8).

on_error

"return" keeps failed members with their status; "stop" signals the first failed member's condition once every member settled.

Value

A team session (kind = "team").

Details

Members evaluate R code in the environment their envir = names, with their own random-number stream, and share one budget, as one peter() call does. A member without envir = runs in the caller's environment, which it shares with the other members, so members that assign the same name overwrite each other: give each its own envir = new.env(). A member's tools =, budget = and the run options in its .opts (such as max_turns) are not applied.

Use peter(..., agents = list(...)) for named roles on one task, or parallel = for one task per input element. Those routes start new foreground children, cannot be deferred as members here, and make a recorded team; the members of gptr_parallel() are nested calls that record nothing, so a history document (see gptr_doc()) that holds one cannot replay or export it. A team report is model-generated output; inspect child statuses and workspace results before continuing the team with a synthesis prompt.

Examples

fake = gptr_fake_provider(list("ok"))
session = gptr_parallel(planner = peter("Plan it", model = fake, envir = new.env()),
                        review = peter("Review it", model = fake, envir = new.env()))
#>   ▌ sub-agent planner (fake/fake-1) started
#>   ▌ sub-agent review (fake/fake-1) started
#>   ▌ sub-agents 0/2 done · 2 active
#>     active   planner (fake/fake-1), review (fake/fake-1)
#>   ▌ sub-agent planner done (1/2) · 1 turn · 0 s
#>   ▌ sub-agents 1/2 done · 1 active
#>     active   review (fake/fake-1)
#>   ▌ sub-agent review done (2/2) · 1 turn · 0 s
names(session$children)
#> [1] "planner" "review"