parallel

Runs several of the agent's functions at the same time and returns their results as a dict, with one entry per call.

Shape

parallel is shaped like var, not like a command block. Each key names a function to call. Each value is an object holding the arguments for that call; the object is empty when the function takes no arguments. To call the same function twice, add a suffix after a dot, as with repeated commands: lookup and lookup.2. The result is a dict with the same keys. At least one function must be named, and main cannot be one of them.

parallel{A: args, B: args, C: args}function Aown localsfunction Bown localsfunction Cown localsresult{A: rA, B: rB, C: rC}
parallel runs functions at once and returns their results keyed by name

Example

"parallel": {
  "fetchWeather": { "city": "{ city }" },
  "fetchEvents":  { "city": "{ city }" }
},
"var": {
  "weather": "{ result['fetchWeather'] }",
  "events": "{ result['fetchEvents'] }"
}

Rules

  • The result is keyed by the names used in the command, so the order in which the calls finish does not matter.
  • Each function runs in its own scope with its own locals. Agent and conversation variables are shared, so two parallel functions should not write the same variable.
  • A function that runs in parallel cannot use ask, and cannot call a function that uses ask.
  • If any call fails, the whole command fails with that error. onError on the calling function can handle the error.