You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
feat(agents): script mode — code-shaped orchestration for agents (#4239)
Add ScriptPlanner and ScriptRunner for agent orchestration via JavaScript scripts in QuickJS sandbox. Scripts can express loops, budget-scaled fan-out, dedup, and early exit — patterns a static DAG cannot.
Copy file name to clipboardExpand all lines: packages/agents/CLAUDE.md
+47Lines changed: 47 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -260,6 +260,53 @@ const agent = new Agent({
260
260
|`DEFAULT_MAX_STEPS`| 50 |`task-executor.ts`|
261
261
|`MAX_RETRIES` (planning) | 3 |`task-planner.ts`|
262
262
263
+
## Script Mode (code-shaped orchestration)
264
+
265
+
The third planning mode next to `TaskPlan` and the graph planner: the LLM
266
+
authors a JavaScript *orchestration script* (`ScriptPlanner`), and
267
+
`ScriptRunner` executes it in the QuickJS sandbox. Every `agent()` call in the
268
+
script runs a real `StepExecutor` sub-agent on the host. A script expresses
269
+
what a static DAG cannot — loops until a condition holds, budget-scaled
270
+
fan-out, dedup between rounds, early exit.
271
+
272
+
```typescript
273
+
const agent =newAgent({
274
+
name: "researcher",
275
+
objective: "Find and verify 5 claims about X",
276
+
provider, model,
277
+
useScriptPlanner: true, // LLM writes the script
278
+
// script: "...", // or supply one directly (skips planning)
279
+
maxConcurrentAgents: 8, // semaphore over concurrent agent() calls
280
+
maxAgentCalls: 100// lifetime cap per run
281
+
});
282
+
```
283
+
284
+
Guest API (see `SCRIPT_PRELUDE` in `script-runner.ts`):
285
+
286
+
| Primitive | Behavior |
287
+
|---|---|
288
+
|`await agent(prompt, opts?)`| Run a sub-agent. `opts.schema` → structured result via `finish_step`; `opts.tools` restricts the toolset; `opts.label` names progress events. Throws on failure. |
289
+
|`await parallel(thunks)`| Concurrent thunks; a failure resolves to `null` instead of rejecting the batch. |
290
+
|`await pipeline(items, ...stages)`| Each item flows through all stages independently (no barrier). Stages receive `(prev, originalItem, index)`. |
291
+
|`log(message)`| Emits a `log_update` to the host event stream. |
0 commit comments