@dudko.dev/agent 0.0.36 → 0.0.37
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 +91 -2
- package/dist/cli.js +90 -68
- package/dist/index.cjs +71 -57
- package/dist/index.d.cts +76 -3
- package/dist/index.d.ts +76 -3
- package/dist/index.js +71 -57
- package/dist/subagent-worker.js +63 -53
- package/package.json +11 -11
package/README.md
CHANGED
|
@@ -103,6 +103,7 @@ Pass an event handler as the second argument to `createAgent`, or per run via `o
|
|
|
103
103
|
| `tools.discovered` | `find_tools` activated tools (`query`, `names`). |
|
|
104
104
|
| `tool.approval-requested` / `tool.approval-resolved` | The approval gate asked / decided (`automatic` for rule, mode and timeout denials). |
|
|
105
105
|
| `subagent.start` / `subagent.event` / `subagent.complete` / `subagent.error` | A subagent tool call's lifecycle and its forwarded child events. |
|
|
106
|
+
| `message.queued` / `message.delivered` | A `RunControl.send()` message is waiting for a boundary / the model has seen it (`at: 'round' \| 'step' \| 'final'`). See [Steering a run](#steering-a-run-that-is-already-going). |
|
|
106
107
|
| `usage` | Per LLM call; `phase` is `'plan' \| 'execute' \| 'replan' \| 'synthesize' \| 'compact' \| 'subagent'`. |
|
|
107
108
|
|
|
108
109
|
```ts
|
|
@@ -406,6 +407,92 @@ Several calls in one model step run in parallel (bounded by `maxConcurrent`). Th
|
|
|
406
407
|
|
|
407
408
|
The worker entry ships as `dist/subagent-worker.js` and is resolved next to the bundle, from the ESM and the CJS build alike.
|
|
408
409
|
|
|
410
|
+
### Profiles: other models, params and context per call
|
|
411
|
+
|
|
412
|
+
A subagent normally has one fixed configuration. `profiles` lets the **parent model** choose between named variants of it, per call:
|
|
413
|
+
|
|
414
|
+
```ts
|
|
415
|
+
const researcher = createSubagentTool({
|
|
416
|
+
name: 'researcher',
|
|
417
|
+
description: 'Research a question with the docs tools and report the facts',
|
|
418
|
+
config: { ...cheapConfig }, // the default: a small, quick model
|
|
419
|
+
profiles: {
|
|
420
|
+
deep: {
|
|
421
|
+
description: 'A hard question that needs a thorough, multi-source answer',
|
|
422
|
+
config: { model: 'a-strong-model', thinking: 'high', maxIterations: 8 },
|
|
423
|
+
},
|
|
424
|
+
skeptic: {
|
|
425
|
+
description: 'Check a claim someone else made; look for what contradicts it',
|
|
426
|
+
config: { systemPrompt: 'Assume the claim is wrong until the sources show otherwise.' },
|
|
427
|
+
},
|
|
428
|
+
},
|
|
429
|
+
})
|
|
430
|
+
```
|
|
431
|
+
|
|
432
|
+
- The tool gains an optional `profile` argument, an enum of the names; leaving it out runs the base config. Each profile's `description` is appended to the tool's description, so the parent chooses by *when to use it* — write them that way.
|
|
433
|
+
- A profile's `config` is laid **over** the base config, field by field and shallow: a profile's `limits` replaces the base's `limits`, it is not merged into it. Anything in `IAgentConfig` can differ — the model (even another provider), `thinking`, limits, `systemPrompt`, `skills`, `tools`.
|
|
434
|
+
- With `'worker'` isolation a profile's `config` must be structured-cloneable like the base one, and that is checked when the tool is created — not hours into a run, when the profile is first chosen.
|
|
435
|
+
- The choice is bounded by what **you** listed: the parent cannot pick an arbitrary model, so cost stays in your hands. An unknown name is a tool error the model can correct, raised before any child starts or is announced.
|
|
436
|
+
- `subagent.start` carries `profile` when one was chosen. Child tokens are charged to the parent as always, whichever profile ran.
|
|
437
|
+
- The child's context is still just `task`. A different context means a profile that changes `systemPrompt`, `skills` or `tools` — the parent cannot hand a child more of its own conversation.
|
|
438
|
+
|
|
439
|
+
## Steering a run that is already going
|
|
440
|
+
|
|
441
|
+
`run()` takes one input and resolves when the run is over. To say something in the meantime
|
|
442
|
+
("use the staging database", "skip the report") or to stop one subagent out of several, make a
|
|
443
|
+
`RunControl` and pass it to the run:
|
|
444
|
+
|
|
445
|
+
```ts
|
|
446
|
+
import { createAgent, createRunControl } from '@dudko.dev/agent'
|
|
447
|
+
|
|
448
|
+
const control = createRunControl()
|
|
449
|
+
const running = agent.run({ input: 'Triage the new tickets', control, onEvent })
|
|
450
|
+
|
|
451
|
+
control.send('Ignore anything older than a week') // any time while it runs
|
|
452
|
+
control.subagents() // [{ id, name, task, profile?, startedAt }] - who is running now
|
|
453
|
+
control.stopSubagent(id) // stops that one; the run goes on
|
|
454
|
+
const result = await running
|
|
455
|
+
result.undelivered // messages the run never got to show the model - send them as the next run
|
|
456
|
+
```
|
|
457
|
+
|
|
458
|
+
A message is **not an interrupt**. The run never cuts a tool call short (it may be a write); the
|
|
459
|
+
message waits for the next boundary and is then shown to the model:
|
|
460
|
+
|
|
461
|
+
| It arrives... | It is shown... | `message.delivered` `at` |
|
|
462
|
+
| --- | --- | --- |
|
|
463
|
+
| during a step, while tools are being called | to the executor on its **next round** of that step, as a user turn after the tool results | `round` |
|
|
464
|
+
| between steps | to the **replanner**, and to every later step | `step` |
|
|
465
|
+
| after the last step, before the answer is written | to the synthesizer | `final` |
|
|
466
|
+
| while the answer is being written, or after the run ended | to **nobody** - it comes back in `result.undelivered` | - |
|
|
467
|
+
|
|
468
|
+
- **A message always makes the replanner look at the plan again**, at the end of the step it was
|
|
469
|
+
delivered in - also after the *last* planned step, where it may add work: a plan made before the
|
|
470
|
+
user spoke may no longer be the right one. That call (`replan.decision` with
|
|
471
|
+
`cause: 'user-message'`) ignores `maxRevisions`, a revise it makes is not counted against it, and
|
|
472
|
+
`replanAfter` does not matter. It costs one extra model call per boundary, not per message, and
|
|
473
|
+
there is no cap on messages. It does need an iteration left (`maxIterations`); without one the
|
|
474
|
+
message still reaches the synthesizer. A replanner that says `finish` ends the run early - that
|
|
475
|
+
is how "stop, that is enough" works.
|
|
476
|
+
- Every later stage sees what the user said (a "Messages from the user" block in its prompt), so a
|
|
477
|
+
correction is not forgotten two steps later - also on an executor retry. Run snapshots carry it
|
|
478
|
+
(`userUpdates`), so a resumed run still knows it. Prompts of a run **without** a control are
|
|
479
|
+
byte-for-byte what they were.
|
|
480
|
+
- A message sent **before** the run starts is queued and announced (`message.queued`) when it
|
|
481
|
+
starts. `send()` returns `false` for an empty text and once the run is over; it never throws.
|
|
482
|
+
- An aborted or failed run **throws**, so it cannot return `undelivered`: read
|
|
483
|
+
`control.pending()` - it keeps reporting what the run never delivered until the control serves
|
|
484
|
+
another run (which then starts clean).
|
|
485
|
+
- Use one control per run. A hand-made object in its place is refused: only the ones
|
|
486
|
+
`createRunControl()` makes are read.
|
|
487
|
+
|
|
488
|
+
**Stopping a subagent.** `stopSubagent(id)` aborts that child (and its worker thread, if it has
|
|
489
|
+
one). Its delegation fails with a message the parent model can route around ("stopped by the user
|
|
490
|
+
... carry on without its result"), `subagent.error` carries `stopped: true`, and sibling subagents
|
|
491
|
+
and the run are untouched. Only a child that has started is listed; one still waiting for a
|
|
492
|
+
`maxConcurrent` slot is not. A child's own subagents are not individually stoppable - stopping the
|
|
493
|
+
child stops them with it. What each child does is the `subagent.event` stream, the same events the
|
|
494
|
+
parent emits.
|
|
495
|
+
|
|
409
496
|
## Autonomy
|
|
410
497
|
|
|
411
498
|
The stage prompts are written for an agent that acts on its own:
|
|
@@ -539,9 +626,11 @@ The package ships a REPL CLI as `dd-agent`. After install, npm makes it availabl
|
|
|
539
626
|
dd-agent --env-file=.env
|
|
540
627
|
```
|
|
541
628
|
|
|
542
|
-
`--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`, `/tools`, `/history`, `/reset`, `/compact`, `/autopilot`, `/approval <mode>`, `/reconnect`, `/exit`).
|
|
629
|
+
`--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`, `/tools`, `/history`, `/reset`, `/compact`, `/autopilot`, `/approval <mode>`, `/reconnect`, `/agents`, `/stop`, `/exit`).
|
|
630
|
+
|
|
631
|
+
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_SKILLS_DIR`, `AGENT_TOOL_SELECTION_STRATEGY` (`auto | all | plan-narrowed | search`), `AGENT_CONTEXT_WINDOW_TOKENS` 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.
|
|
543
632
|
|
|
544
|
-
|
|
633
|
+
**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.
|
|
545
634
|
|
|
546
635
|
For local development against the source tree:
|
|
547
636
|
|