const guide = `## agent(), llm() and z in Code Mode
const guide = `## agent() and llm() in Code Mode
Scripts you run with \`execute\` also have these globals:
- \`await agent(prompt, { schema?, agent?, model?, effort?, label?, retries? })\` starts a subagent (default \`"general"\`, use \`"explore"\` for read-only work) in its own child session, waits for it, and returns its final text — or a checked value when \`schema\` is given.
- \`await agent(prompt, { schema?, agent?, model?, effort?, label?, retries? })\` starts a subagent (default \`"general"\`, use \`"explore"\` for read-only work) in its own child session, waits for it, and returns its final text — or a value checked against \`schema\` (a JSON Schema object).
- \`await llm(prompt, { schema?, system?, model?, effort?, label?, retries? })\` makes one fast model call with no tools and no history (defaults to low reasoning effort). Use it whenever the script already has the text to classify, extract, summarize or verify.
For speed, put scouting, per-item pipelining (\`Promise.all(items.map(async (item) => { const a = await ...; const b = a.flagged ? await ... : null; return ... }))\`), and writing final files (\`Bun.write\`) in ONE \`execute\` call instead of bouncing intermediate results back to the main session between turns. Read small shared files once in the script and include them in prompts instead of having every worker re-read them. Pass \`effort: "low"\` to \`agent()\` for mechanical stages; omit or pass \`"high"\` for harder reasoning. Up to ${LIMITS.agentConcurrency} agents and ${LIMITS.llmConcurrency} \`llm()\` calls run at once (caps: ${LIMITS.agentTotal} agents, ${LIMITS.llmTotal} \`llm()\`); after any usage/rate limit, no more calls start.
Expand All
@@ -139,7 +136,7 @@ Each \`agent()\` is a full subagent run. Start agents only when the user asks fo
| `agent(prompt, options?)` | Starts a subagent in its own child session, with tools, and waits for its result | A full subagent run |
| `llm(prompt, options?)` | One model call: no tools, no conversation history | One request |
| `z` | Builds schemas the way zod does | Free |
Start agents only when the user asked for parallel agents, multi-agent work or a workflow. For anything else, describe what a script would do and roughly how many agents it would start, and ask. `llm()` is cheap enough to use whenever a script needs a model.
Expand DownExpand Up
@@ -34,7 +33,15 @@ Each child is a normal session the user can open. agent() rejects when the child
```js
const label = await llm(`Is this a bug report or a feature request?\n\n${issue.body}`, {
With `schema`, the model must return a value that matches; agent() and llm() check it and give the model the exact problems to fix until it does, so the script gets a value it can use without parsing.
- Methods: `.optional()`, `.nullable()`, `.nullish()`, `.describe(text)`, `.default(value)`, `.min(n)`, `.max(n)`, `.length(n)`, `.nonempty()`, `.int()`, `.positive()`, `.nonnegative()`, `.email()`, `.url()`, `.uuid()`, `.datetime()`, `.regex(re)`. Nothing else from zod exists: no `.refine()`, `.transform()` or `.parse()`.
- `.regex()` and JSON Schema `pattern` are shown to the model but not enforced; check those values in the script if they matter.
- Object keys are required unless `.optional()`; extra keys are not allowed.
- A root that is not an object works: `schema: z.array(Finding)` returns an array.
- Plain JSON Schema works anywhere a `z` schema does.
- Pass standard JSON Schema (Draft 2020-12).
- `pattern` is shown to the model as guidance but is not enforced during validation; check regexes in the script if they matter.
- A root that is not an object works: `{ type: "array", items: { type: "string" } }` returns an array directly.
Describe fields whose meaning is not obvious from the name: the model reads the descriptions.
Expand DownExpand Up
@@ -108,7 +126,7 @@ Wait for every result first only when the next step needs all of them, such as d
## Rules of thumb
- Scout first in the main conversation (list files, check the diff) to learn the work list, then fan out over it.
- Put scouting, per-item pipelining, and writing final files (`Bun.write`) in one `execute` call instead of bouncing intermediate results back to the main session between turns.
- Keep each agent's task small and specific, with a clear result. One agent per file or per finding beats one agent for everything.
- Agents that edit files at the same time can overwrite each other. Give them separate files, or have them return changes and apply them yourself.
- Return the summary the user needs from the script, not every raw result: the script's return value is what you read next.
"Read before writing a Code Mode script that calls agent() or llm(): the full API, schemas with z, limits, and patterns for fanning work out, verifying it and combining the results."
"Read before writing a Code Mode script that calls agent() or llm(): the full API, schemas, limits, and patterns for fanning work out, verifying it and combining the results."
There was an error while loading. Please reload this page.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.