@dudko.dev/agent-web 0.0.42 → 0.0.43
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 +95 -2
- package/dist/agent-web.js +130 -130
- package/dist/agent-web.js.map +1 -1
- package/dist/index.cjs +201 -20
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +74 -200
- package/dist/index.d.ts +74 -200
- package/dist/index.js +195 -20
- package/dist/index.js.map +1 -1
- package/dist/pipeline-engine.cjs +1130 -0
- package/dist/pipeline-engine.cjs.map +1 -0
- package/dist/pipeline-engine.d.cts +226 -0
- package/dist/pipeline-engine.d.ts +226 -0
- package/dist/pipeline-engine.js +1094 -0
- package/dist/pipeline-engine.js.map +1 -0
- package/package.json +13 -3
package/README.md
CHANGED
|
@@ -809,7 +809,13 @@ tools — a helper can only have less than the run that starts it, and its spend
|
|
|
809
809
|
that run's limits. Give `persistence` a store
|
|
810
810
|
(`new IndexedDBRunStore()`) and a run interrupted by a reload or a crash resumes from its
|
|
811
811
|
last checkpoint with `run('', { resumeFromRunId })` — the planner does not run again and
|
|
812
|
-
no finished step is repeated
|
|
812
|
+
no finished step is repeated; every event of a run carries `seq` and `attempt` (one more
|
|
813
|
+
per resume, recorded by `onRunResume` before the resumed run emits anything), so
|
|
814
|
+
`(attempt, seq)` orders a run's events across reloads. `run(goal, { runId })` starts a fresh
|
|
815
|
+
run under an id of yours (1-128 letters, digits, `_` or `-`) instead of a random one, so that a
|
|
816
|
+
retry finds the same run: refused together with `resumeFromRunId`, and refused when `loadRun`
|
|
817
|
+
already has that run (resume it instead - a run on record is never written over); see
|
|
818
|
+
[Resuming](docs/capabilities.md#resuming-an-interrupted-run). `createRunControl()` steers a run that is going: `send()`
|
|
813
819
|
puts a message in front of the model at the next boundary (the replanner re-checks the plan
|
|
814
820
|
against it), `stopSubagent(id)` stops one subagent. `egress` (off by default) gives the model one safe `web_fetch` tool with allow / deny lists. `search` (off by default) adds `web_search` over a function of yours (any search API — recipes for Tavily, Brave and SearXNG are in the docs) or the built-in Google Search through Gemini grounding, which needs only a Gemini key and spends its tokens — the key stays in the credential store. `sandbox` (off by default) gives the model `run_js`: the code it wrote runs in QuickJS-in-WebAssembly inside a Web Worker that is killed at the deadline, so "I ran it" is a tool call you can see. `media` (off by default) mounts `generate_image`, `generate_speech` and `transcribe_audio` — each only when you configure its model — writes what they make into the virtual file system instead of the context, and turns attached audio into text for a model that cannot listen. `learning` (off by default) lets the agent write down what it figured out as skills of its own — in memory, or in the file system across sessions. Details, defaults and events:
|
|
815
821
|
**[docs/capabilities.md](docs/capabilities.md)**.
|
|
@@ -870,6 +876,93 @@ Conditions (`always`, `contains`, `matches`, `route`, `otherwise`), the scheduli
|
|
|
870
876
|
join, the loop caps), validation and the events: **[docs/capabilities.md](docs/capabilities.md#pipelines-a-graph-of-agents)**.
|
|
871
877
|
Loading a definition someone else wrote: [docs/security.md](docs/security.md#pipelines-a-definition-is-data).
|
|
872
878
|
|
|
879
|
+
### Running the graph yourself
|
|
880
|
+
|
|
881
|
+
`createPipeline` is a scheduler with `createAgent` as its node runner. Both halves are public, so a
|
|
882
|
+
host can keep the scheduler and run every node its own way - a worker, a server job, another tab -
|
|
883
|
+
and make the route call where the node ran:
|
|
884
|
+
|
|
885
|
+
```ts
|
|
886
|
+
import { createAgent, pickPipelineRoute, preparePipeline, runPipelineGraph } from '@dudko.dev/agent-web'
|
|
887
|
+
|
|
888
|
+
const plan = preparePipeline(definition) // validates (PipelineValidationError) and compiles
|
|
889
|
+
const result = await runPipelineGraph(
|
|
890
|
+
plan,
|
|
891
|
+
async (node, input, ctx) => {
|
|
892
|
+
// input: { request, from: [{ nodeId, name?, text }], visit } - renderPipelineNodeInput(input)
|
|
893
|
+
// is the text a createPipeline node is given.
|
|
894
|
+
const text = await worker.run(node.id, input, { signal: ctx.signal }) // your runner
|
|
895
|
+
if (!node.routes?.length) return { text }
|
|
896
|
+
// The route call createPipeline makes: the node's decision model, then its planner model.
|
|
897
|
+
const config = configOf(node) // the node's BrowserAgentConfig
|
|
898
|
+
const { route, usage } = await pickPipelineRoute(node, text, {
|
|
899
|
+
agent: await agentOf(node, config), // createAgent(config), kept per node
|
|
900
|
+
config,
|
|
901
|
+
signal: ctx.signal,
|
|
902
|
+
onEvent: ctx.emit,
|
|
903
|
+
})
|
|
904
|
+
return { text, usage, route }
|
|
905
|
+
},
|
|
906
|
+
{ input: 'A release note for v2', signal, onEvent, onAbort: 'resolve' },
|
|
907
|
+
)
|
|
908
|
+
```
|
|
909
|
+
|
|
910
|
+
The runner's contract:
|
|
911
|
+
|
|
912
|
+
- **When it is called.** Once per visit, never for an activation a cap refused (`plan.maxNodeVisits`
|
|
913
|
+
/ `plan.maxRuns`: the definition's `limits` or the defaults). All visits of a wave are started, in
|
|
914
|
+
the order their nodes were first activated, before any is awaited; the next wave starts when all
|
|
915
|
+
of them have settled. A visit's answer is applied (events, trace, edges) when it settles.
|
|
916
|
+
- **What it returns.** `{ text, usage?, route? }`. `text` is what the edges test (not a string
|
|
917
|
+
counts as `''`); `usage` is added to `result.usage`, every numeric field; `route` must be one of
|
|
918
|
+
`node.routes`' labels exactly as written - anything else, or none, is no route. To pick one with a
|
|
919
|
+
model of your own: `PIPELINE_ROUTER_SYSTEM` and `renderPipelineRoutePrompt(node, text)` are the
|
|
920
|
+
prompt, `matchPipelineRoute(node, answer)` turns the answer into a label.
|
|
921
|
+
- **When it fails.** A runner that rejects fails the run with a `PipelineNodeError` (`nodeId`,
|
|
922
|
+
`visit`, `cause`), whatever `onAbort` says: the other visits' `ctx.signal` aborts, and what they
|
|
923
|
+
return afterwards is ignored.
|
|
924
|
+
- **Abort.** `signal` aborts the visits in flight (their `ctx.signal`) and settles the run at once,
|
|
925
|
+
without waiting for them: it rejects with an `AbortError` (`onAbort: 'reject'`, the default, as
|
|
926
|
+
the Node sibling's `createPipeline` does) or resolves with what it has and `stoppedBy: 'aborted'`
|
|
927
|
+
(`'resolve'`, as `createPipeline` does here). Aborted before it starts: no visit at all.
|
|
928
|
+
- **Events.** `onEvent` gets the `pipeline.*` events `createPipeline` sends; `ctx.emit(event)`
|
|
929
|
+
forwards one of the node's own, with `nodeId` and `visit`, until the run is over.
|
|
930
|
+
|
|
931
|
+
`pickPipelineRoute(node, text, { agent, config, signal?, onEvent? })` resolves with
|
|
932
|
+
`{ route?, usage }`: the agent's decision model first (`config.decisionModel`, when it is
|
|
933
|
+
confident of a label), else its planner model - structured output, then plain text - with the
|
|
934
|
+
config's budget, temperature and `chatTimeoutMs`. No label, or a failed call, is no route; an
|
|
935
|
+
abort rejects with an `AbortError`.
|
|
936
|
+
|
|
937
|
+
**Deterministic by contract.** The engine - `preparePipeline`, `runPipelineGraph`, the conditions -
|
|
938
|
+
reads no clock, no randomness and no timer, and does no I/O: the same definition, input and runner
|
|
939
|
+
answers, arriving in the same order (and an abort at the same point), give the same calls, events,
|
|
940
|
+
trace and result. So it can be a deterministic scheduler, replayed from a log of the runner's
|
|
941
|
+
answers. It needs nothing but the JavaScript language: where there is no `AbortController`,
|
|
942
|
+
`ctx.signal` is a stand-in (`aborted`, `reason`, `onabort`, `throwIfAborted()`, `addEventListener` /
|
|
943
|
+
`removeEventListener`), where there is no `DOMException` the abort error is an `Error` named
|
|
944
|
+
`AbortError`, and of your `signal` only `aborted` and `addEventListener` / `removeEventListener`
|
|
945
|
+
for `'abort'` are read. `pickPipelineRoute` calls a model, so it is not part of that: it belongs
|
|
946
|
+
where the node runs. Why: [docs/design.md](docs/design.md#pipelines-waves-a-join-rule-caps).
|
|
947
|
+
|
|
948
|
+
**The engine alone: `@dudko.dev/agent-web/pipeline-engine`.** The main entry loads the whole
|
|
949
|
+
agent - `ai`, `zod`, `idb` -, which a bundled orchestrator cannot import (a workflow sandbox has the
|
|
950
|
+
language and little else). The engine has an entry point of its own, ESM and CommonJS with types,
|
|
951
|
+
whose file imports nothing:
|
|
952
|
+
|
|
953
|
+
```ts
|
|
954
|
+
// In the workflow: the scheduler only; every node runs outside it (an activity, a job).
|
|
955
|
+
import { preparePipeline, runPipelineGraph } from '@dudko.dev/agent-web/pipeline-engine'
|
|
956
|
+
```
|
|
957
|
+
|
|
958
|
+
It exports `preparePipeline`, `runPipelineGraph`, `validatePipeline`, `normalizePipeline`,
|
|
959
|
+
`testPipelineCondition`, `renderPipelineNodeInput`, `renderPipelineRoutePrompt`,
|
|
960
|
+
`matchPipelineRoute`, `PIPELINE_ROUTER_SYSTEM`, `PIPELINE_LIMITS`, `PipelineValidationError`,
|
|
961
|
+
`PipelineNodeError` and every pipeline type - the same names as the main entry, and the Node
|
|
962
|
+
sibling's `@dudko.dev/agent/pipeline-engine` is the same file. It is a copy of the engine the main
|
|
963
|
+
entry carries, not the same objects: an error thrown by one is not `instanceof` the other's class -
|
|
964
|
+
compare `error.name`. More: [docs/capabilities.md](docs/capabilities.md#pipelines-a-graph-of-agents).
|
|
965
|
+
|
|
873
966
|
## Configuration (highlights)
|
|
874
967
|
|
|
875
968
|
| Option | Default | Purpose |
|
|
@@ -906,7 +999,7 @@ Loading a definition someone else wrote: [docs/security.md](docs/security.md#pip
|
|
|
906
999
|
| `describeState` | — | serialize world state into prompt context |
|
|
907
1000
|
| `memory` | — | `ContextStore` (`IndexedDBStore` / `MemoryStore`); recent turns are read back into the planner prompt |
|
|
908
1001
|
| `sessionId` | — | names the stored conversation in `memory`, and the bucket `agent.sessionUsage()` counts into |
|
|
909
|
-
| `persistence` | — | checkpoint runs (`IndexedDBRunStore` / `MemoryRunStore`) so `run(goal, { resumeFromRunId })` continues after a reload — see [Resuming](docs/capabilities.md#resuming-an-interrupted-run) |
|
|
1002
|
+
| `persistence` | — | checkpoint runs (`IndexedDBRunStore` / `MemoryRunStore`) so `run(goal, { resumeFromRunId })` continues after a reload; hooks `onRunStart` / `onStepComplete` / `onRunComplete` / `onRunResume` (a resume's new `attempt`, before any event) / `loadRun` — see [Resuming](docs/capabilities.md#resuming-an-interrupted-run) |
|
|
910
1003
|
| `maxIterations` / `maxStepsPerTask` / `maxRevisions` | 8 / 4 / 2 | loop caps |
|
|
911
1004
|
| `chatTimeoutMs` | 120000 | per-call watchdog; for the executor, the whole step (its tool calls included). Stopped while a tool call waits for a person (an approval, an MCP question): the step goes on with the time it had left - see [Tool consent](docs/capabilities.md#tool-consent-and-autopilot) |
|
|
912
1005
|
| `temperature` | provider default | sampling temperature for every stage |
|