@dudko.dev/agent 0.0.40 → 0.0.42

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -294,6 +294,22 @@ const agent = await createAgent({
294
294
 
295
295
  The run caps are **soft**: they are checked between steps *and* inside an executor step, as an extra `stopWhen` condition that adds the usage of the step's LLM calls to the run so far — so a runaway tool loop stops at its next LLM step instead of at the end of the step. When a cap is crossed the agent emits `budget.exceeded` (`kind: 'input' | 'output' | 'reasoning' | 'total' | 'tool-calls'`), stops executing steps and goes straight to synthesis, which still runs (capped by `perCall.synthesizer`). `checkLimits(usage, limits)` is the pure check, exported.
296
296
 
297
+ **Per-call output caps default to a share of the context window.** `perCall` limits what one LLM call of a stage may write. Leave a stage out and it gets a share of `compaction.contextWindowTokens` (default 128k), kept between a floor and a ceiling, so the cap follows the model instead of being one number that is wrong at one end:
298
+
299
+ | Stage | Share of the window | Floor – ceiling | At 128k |
300
+ | --- | --- | --- | --- |
301
+ | `planner` | 1/64 | 512 – 4,000 | 2,000 |
302
+ | `executor` | 1/16 | 2,048 – 32,000 | 8,000 |
303
+ | `replanner` | 1/128 | 256 – 2,000 | 1,000 |
304
+ | `synthesizer` | 1/32 | 1,024 – 16,000 | 4,000 |
305
+
306
+ (`compaction` keeps its own `summaryMaxTokens`, default 1,024.) A cap never takes more than half of a small window. The executor's share is the widest because a tool call's arguments — a file it writes — count as output.
307
+
308
+ - **Yours wins.** Any `limits.perCall.<stage>` replaces the default, and **`0` means no cap** (the provider's own maximum applies — what Node did before these defaults existed).
309
+ - **A stage that thinks gets no default cap.** On OpenAI and Gemini the reasoning counts against `max_output_tokens`, so a default sized for the answer alone could leave a thinking model no room to write it. Set `perCall` yourself if you want a cap there (Anthropic adds the thinking budget on top of it).
310
+ - **A call the cap cuts off says so.** The executor and synthesizer emit a `log` warning (`[synthesizer] the model's output was cut off at 4000 tokens, the default cap for this stage …`); a plan or a replanner decision cut in half fails with the same reason in its error instead of a bare "could not parse the response".
311
+ - The browser sibling `@dudko.dev/agent-web` derives its caps the same way, with its own, smaller shares (800 / 1,200 / 400 / 3,000 at 128k).
312
+
297
313
  `maxToolCalls`: once reached, further tool calls in the run fail with `tool-call budget exhausted` (the model sees that as the tool result) and the run moves to synthesis with `budget.exceeded` of kind `'tool-calls'`. Built-in tools (`find_tools`, `load_skill`, `read_skill_file`) do not count.
298
314
 
299
315
  The other step caps are unchanged: `maxIterations` (executed steps per run), `maxStepsPerTask` (LLM steps inside one executor call) and `maxRevisions` (replanner revisions per run).
@@ -624,7 +640,7 @@ Consent is the host's job ([tool approval](#tool-approval-and-autopilot)) — th
624
640
  | `maxRevisions` | Cap on `revise` decisions the replanner can make per run. Default `2`. |
625
641
  | `replanAfter` | Replan trigger: `'failure'` (default; blocked step or a tool failure that stayed failed) \| `'always'` \| `(stepResult) => boolean \| Promise<boolean>` (bounded by `llmTimeoutMs`; falls back to `'failure'` on error). |
626
642
  | `maxTotalTokens` | Soft cap on cumulative input + output tokens; checked between steps and triggers an early jump to synthesis when crossed. Legacy shortcut for `limits.maxTotalTokens` (which wins). |
627
- | `limits` | `{ maxInputTokens?, maxOutputTokens?, maxReasoningTokens?, maxTotalTokens?, perCall?: { planner?, executor?, replanner?, synthesizer?, compaction? } }` — cumulative per-run caps (also enforced inside an executor step) and per-call output caps. See [Token limits](#token-limits-and-step-caps). |
643
+ | `limits` | `{ maxInputTokens?, maxOutputTokens?, maxReasoningTokens?, maxTotalTokens?, perCall?: { planner?, executor?, replanner?, synthesizer?, compaction? } }` — cumulative per-run caps (also enforced inside an executor step) and per-call output caps (default: a share of the context window; `0` = none). See [Token limits](#token-limits-and-step-caps). |
628
644
  | `maxToolCalls` | Cap on tool calls per run; further calls fail with "tool-call budget exhausted" and the run goes to synthesis. |
629
645
  | `maxPlanSteps` | Hard cap on plan steps (initial and revised). Default `8`. |
630
646
  | `thinking` / `stageThinking` | Reasoning for every stage / per stage (`planner`, `executor`, `replanner`, `synthesizer`). See [Thinking](#thinking-reasoning). |
@@ -731,7 +747,7 @@ dd-agent --env-file=.env
731
747
 
732
748
  `--env-file=<path>` is loaded via Node's built-in `process.loadEnvFile`, so no `dotenv` dependency is needed. Without the flag the CLI reads the ambient process env. `-h` / `--help` prints the supported flags and the in-REPL slash commands (`/status`, `/usage`, `/tools`, `/history`, `/reset`, `/compact`, `/autopilot`, `/approval <mode>`, `/reconnect`, `/skills`, `/forget <name>`, `/agents`, `/stop [n]`, `/exit` — `/quit` does the same).
733
749
 
734
- The newer features are env-driven too: `AGENT_THINKING` (`off | minimal | low | medium | high | xhigh | <budget tokens>`), `AGENT_MAX_INPUT_TOKENS` / `AGENT_MAX_OUTPUT_TOKENS` / `AGENT_MAX_REASONING_TOKENS` / `AGENT_MAX_TOTAL_TOKENS`, `AGENT_MAX_TOOL_CALLS`, `AGENT_TOOL_APPROVAL` (`autopilot | ask-writes | ask-all | read-only`), `AGENT_TOOL_RULES` (JSON `{ "<tool or glob*>": "allow" | "ask" | "deny" }`, beats the mode — e.g. `{"github__delete_*":"deny"}`), `AGENT_EGRESS` (`on | off`; with `AGENT_EGRESS_ALLOW`, `AGENT_EGRESS_DENY`, `AGENT_EGRESS_PROTOCOLS`, `AGENT_EGRESS_ALLOW_PRIVATE` — see [Egress](#egress-what-the-model-may-fetch)), `AGENT_SKILLS_DIR`, `AGENT_LEARNING` (`on | off`; `AGENT_LEARNING_DIR` keeps the lessons across sessions — see [Learning](#learning-lessons-that-outlive-the-task)), `AGENT_TOOL_SELECTION_STRATEGY` (`auto | all | plan-narrowed | search`), `AGENT_CONTEXT_WINDOW_TOKENS`, `AGENT_COMPACTION_THRESHOLD` (percent of the window where auto-compaction starts, default 85) and `AGENT_COMPACTION=off`. The REPL prints the model's thoughts dimmed, auto-compacts its history with the same settings, and — when the approval mode asks — prompts `allow? [y]es / [n]o / [a]lways` right in the terminal; `/autopilot` toggles between autopilot and the last asking mode.
750
+ The newer features are env-driven too: `AGENT_THINKING` (`off | minimal | low | medium | high | xhigh | <budget tokens>`), `AGENT_MAX_INPUT_TOKENS` / `AGENT_MAX_OUTPUT_TOKENS` / `AGENT_MAX_REASONING_TOKENS` / `AGENT_MAX_TOTAL_TOKENS`, `AGENT_MAX_TOOL_CALLS`, `AGENT_PER_CALL_TOKENS` (JSON `{"executor":16000,"synthesizer":0}` — per-stage output caps, `0` = no cap, see [Token limits](#token-limits-and-step-caps)), `AGENT_TOOL_APPROVAL` (`autopilot | ask-writes | ask-all | read-only`), `AGENT_TOOL_RULES` (JSON `{ "<tool or glob*>": "allow" | "ask" | "deny" }`, beats the mode — e.g. `{"github__delete_*":"deny"}`), `AGENT_EGRESS` (`on | off`; with `AGENT_EGRESS_ALLOW`, `AGENT_EGRESS_DENY`, `AGENT_EGRESS_PROTOCOLS`, `AGENT_EGRESS_ALLOW_PRIVATE` — see [Egress](#egress-what-the-model-may-fetch)), `AGENT_SKILLS_DIR`, `AGENT_LEARNING` (`on | off`; `AGENT_LEARNING_DIR` keeps the lessons across sessions — see [Learning](#learning-lessons-that-outlive-the-task)), `AGENT_TOOL_SELECTION_STRATEGY` (`auto | all | plan-narrowed | search`), `AGENT_CONTEXT_WINDOW_TOKENS`, `AGENT_COMPACTION_THRESHOLD` (percent of the window where auto-compaction starts, default 85) and `AGENT_COMPACTION=off`. The REPL prints the model's thoughts dimmed, auto-compacts its history with the same settings, and — when the approval mode asks — prompts `allow? [y]es / [n]o / [a]lways` right in the terminal; `/autopilot` toggles between autopilot and the last asking mode.
735
751
 
736
752
  **Talking to the agent while it works.** The REPL keeps reading while a run goes. Text you type then is said to the running agent (it sees it at its next boundary and the replanner re-checks the plan — see [Steering a run](#steering-a-run-that-is-already-going)): the REPL prints `[you->agent] queued` and then `delivered (round|step|final)`, and the message enters the history as a user turn. A message that arrives while the answer is being written is sent as the next prompt (`[follow-up]`). After Ctrl-C nothing is sent behind your back: what the agent never saw is listed as `[not delivered]`. While a run goes, `/agents` lists the running subagents and `/stop <n>` (or an id prefix, or just `/stop` when one runs) stops one — the run goes on; the other REPL commands work between runs. Each subagent's own steps and tool calls are logged as `[name id] ...` lines, so parallel ones can be told apart.
737
753