@oona/vlo 0.1.0 → 0.1.1

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
@@ -1,9 +1,23 @@
1
1
  # @oona/vlo
2
2
 
3
- [Vlo](https://github.com/oonalab/vlo) is an event-sourced durable execution engine for
4
- workflows and agents. A workflow is a pure reducer `(state, event) → (state, commands)`; the
5
- Rust kernel (bundled as wasm) folds events, and your Postgres or a SQLite file is both the
6
- journal and the task queue. Nothing suspends, so there is no code replay.
3
+ [Vlo](https://github.com/oonalab/vlo) is durable execution for workflows and AI agents, as
4
+ a library on the database you already run. It keeps long-running work alive through
5
+ crashes and restarts, with no cluster, broker or vendor platform.
6
+
7
+ - **Tiny.** A 298 KB wasm kernel inside your process. Nothing to stand up.
8
+ - **Performant.** One transaction per step. A run with 20,000 events resumes as fast as a
9
+ run with 38.
10
+ - **Reliable.** Nothing is acknowledged before it is saved, and every checkpoint is
11
+ hash-checked.
12
+ - **Efficient.** A waiting run holds no compute. An agent that reaches its budget parks
13
+ instead of burning money.
14
+ - **Built for the edge.** The kernel has no I/O and runs anywhere wasm runs. It runs on
15
+ Node today (Cloud Run, Vercel, containers); the edge host is not built yet.
16
+
17
+ One design principle makes all five possible: a workflow is a pure reducer,
18
+ `(state, event) → (state, commands)`. Each step is saved in one transaction to your
19
+ Postgres or a SQLite file, which is also the task queue. Between steps a run is only rows,
20
+ so there is nothing to keep alive and nothing to replay.
7
21
 
8
22
  ```sh
9
23
  pnpm add @oona/vlo zod # Node ≥ 22.5
@@ -12,7 +26,7 @@ pnpm add @oona/vlo zod # Node ≥ 22.5
12
26
  | Entry | What it gives you |
13
27
  |---|---|
14
28
  | `@oona/vlo` | authoring: `activity`, `signal`, `defineWorkflow`, `cmd`, `sequence`, `fanOut`, `waitFor`, `defineWorker`, `defineConfig`, `env` |
15
- | `@oona/vlo/agent` | agent loop: `decision`, `agentLoop`, `budgetTopup` |
29
+ | `@oona/vlo/agent` | agent loop: `decision`, `agentLoop`, `budgetTopup`, `approvalSignal` |
16
30
  | `@oona/vlo/host` | runtime: `createHost`, `serve`, `handler`, `createClient`, `drainHost`, `runPullWorker`, journals, blob stores, errors |
17
31
  | `@oona/vlo/testing` | `journalConformance`, `fakeClock` |
18
32
  | `vlo` (bin) | `vlo dev`, `vlo serve`, `vlo doctor`, `vlo deploy` |
@@ -30,24 +44,40 @@ export default defineWorkflow("hello", sequence([step(greet, (input) => input)])
30
44
 
31
45
  ## An agent
32
46
 
33
- `@oona/vlo/agent` is decide → act → evaluate as a pure reducer, with a budget that parks the
34
- run on a top-up signal instead of failing it.
47
+ `@oona/vlo/agent` builds a decide → tool → evaluate loop that survives crashes and stays
48
+ inside a budget.
49
+
50
+ ```ts
51
+ import { defineWorkflow } from "@oona/vlo";
52
+ import { agentLoop } from "@oona/vlo/agent";
53
+
54
+ export default defineWorkflow(
55
+ "research",
56
+ agentLoop({ decide, tools: { search, write }, evaluate, threshold: 0.9, budget: { tokens: 50_000 } }),
57
+ );
58
+ ```
35
59
 
36
- - `decision()` declares the activity that chooses the next tool from an observation.
37
- - `agentLoop()` builds a workflow that runs decision, tool and evaluator steps until the
38
- decision returns `DONE`, the iteration cap is hit, or the budget is spent.
39
- - `budgetTopup()` declares the signal that resumes a parked run with more budget.
60
+ - `decision()` declares the activity behind which your model call lives. Its output is
61
+ limited to the tools you registered, or `"done"`.
62
+ - `agentLoop()` builds the workflow. It runs until the decision returns `"done"`, the score
63
+ clears the threshold, or the iteration cap is hit.
64
+ - `budgetTopup()` declares the signal that resumes a run parked on a spent budget.
65
+ - `approval: { tools: [...] }` makes the named tools wait for a person's yes or no;
66
+ `approvalSignal(i)` is the signal that answers call `i`.
40
67
 
41
- Usage is accounted by the kernel on every event, so the budget check is deterministic and
42
- survives restarts. Nothing in this entry does I/O: `agentLoop` returns a workflow definition
43
- you hand to `defineWorkflow`.
68
+ Every decision, tool call and score is one journaled event, so an agent continues from its
69
+ last event after a crash. The kernel meters usage on every event, including failed
70
+ attempts; a run that reaches its budget parks and keeps its work until someone tops it up.
44
71
 
45
72
  ## Documentation
46
73
 
47
- - [Getting started](https://github.com/oonalab/vlo/blob/main/docs/getting-started.md)
48
- - [Concepts](https://github.com/oonalab/vlo/blob/main/docs/concepts.md)
49
- - [Agents](https://github.com/oonalab/vlo/blob/main/docs/agents.md)
50
- - [Full index](https://github.com/oonalab/vlo/blob/main/docs/README.md)
74
+ - [Getting started](https://oonalab.github.io/vlo/getting-started)
75
+ - [Why Vlo](https://oonalab.github.io/vlo/why-vlo), with what it does not have yet
76
+ - [Build an agent harness](https://oonalab.github.io/vlo/agent-harness)
77
+ - [Recipes](https://oonalab.github.io/vlo/recipes) and [FAQ](https://oonalab.github.io/vlo/faq)
78
+ - [Performance](https://oonalab.github.io/vlo/performance) and [Reliability](https://oonalab.github.io/vlo/reliability)
79
+ - [Full index](https://oonalab.github.io/vlo/)
80
+ - [API reference](https://oonalab.github.io/vlo/api/)
51
81
  - [Examples](https://github.com/oonalab/vlo/tree/main/examples): the smallest program, a
52
82
  fan-out pipeline with a human approval, and a budgeted agent loop.
53
83
 
package/dist/agent.d.ts CHANGED
@@ -39,7 +39,8 @@ interface Observation {
39
39
  error?: string;
40
40
  score?: number;
41
41
  }
42
- type AgentPhase = "decide" | "tool" | "evaluate" | "parked" | "done";
42
+ /** `approval` is a gated tool call waiting for a person; `parked` is a spent budget waiting for a top-up. */
43
+ type AgentPhase = "decide" | "approval" | "tool" | "evaluate" | "parked" | "done";
43
44
  interface AgentState {
44
45
  phase: AgentPhase;
45
46
  goal: Json;
@@ -48,7 +49,7 @@ interface AgentState {
48
49
  memory: Observation[];
49
50
  candidate?: Json;
50
51
  score?: number;
51
- /** The tool dispatched this iteration, so its result can be attributed to it. */
52
+ /** The tool chosen this iteration (awaiting approval or dispatched), so its result can be attributed to it. */
52
53
  pending?: {
53
54
  tool: string;
54
55
  args: Json;
@@ -77,6 +78,44 @@ interface DecisionOptions<I extends z.ZodType> {
77
78
  timeoutMs?: number;
78
79
  }
79
80
  export declare function decision<I extends z.ZodType>(name: string, options: DecisionOptions<I>): Activity<z.infer<I>, Decision>;
81
+ /** Prefix of the signal a gated tool call waits on; the iteration is appended. */
82
+ export declare const DEFAULT_APPROVAL_SIGNAL = "agent.tool_approval";
83
+ /**
84
+ * The reply to an approval request. An empty payload approves, so a signed link's
85
+ * confirmation form is enough; `approved: false` rejects.
86
+ */
87
+ interface ToolApproval {
88
+ /** `false` rejects the call. Absent or `true` approves it. */
89
+ approved?: boolean | undefined;
90
+ /** Why, shown to the decider when the call is rejected. */
91
+ reason?: string | undefined;
92
+ /** Who replied. */
93
+ by?: string | undefined;
94
+ }
95
+ /** What `agentLoop({ approval })` takes. */
96
+ interface ApprovalOptions {
97
+ /** Names of the tools that need a yes before they run. Each must be a key of `tools`. */
98
+ tools: readonly string[];
99
+ /** Signal name prefix. Default {@link DEFAULT_APPROVAL_SIGNAL}. */
100
+ name?: string | undefined;
101
+ /** How long to wait for a reply. Without one the run waits until somebody answers. */
102
+ timeoutMs?: number | undefined;
103
+ /**
104
+ * What an unanswered request becomes: `"reject"` (default) tells the decider the call was
105
+ * not approved and carries on; `"fail"` fails the run.
106
+ */
107
+ onTimeout?: "reject" | "fail" | undefined;
108
+ }
109
+ /**
110
+ * The signal the gated call of `iteration` waits on. Pass it to `client.signal` or
111
+ * `client.signalLink`; the iteration is the suffix of the wait's step id, `approve#<i>`.
112
+ *
113
+ * @example
114
+ * ```ts
115
+ * await client.signal(runId, approvalSignal(2), { approved: false, reason: "wrong audience" });
116
+ * ```
117
+ */
118
+ export declare function approvalSignal(iteration: number, name?: string): SignalDef<ToolApproval>;
80
119
  export declare const DEFAULT_TOPUP_SIGNAL = "agent.budget_topup";
81
120
  /** What a top-up grants. Every field is added to the matching ceiling. */
82
121
  interface BudgetTopup {
@@ -99,9 +138,14 @@ interface AgentLoopOptions {
99
138
  threshold?: number | undefined;
100
139
  budget: Budget;
101
140
  topup?: SignalDef<BudgetTopup> | undefined;
141
+ /**
142
+ * Tools that wait for a person's yes before they run. A rejected call becomes an
143
+ * observation and the decider chooses again. See {@link ApprovalOptions}.
144
+ */
145
+ approval?: ApprovalOptions | undefined;
102
146
  maxIterations?: number | undefined;
103
147
  /** Observations kept in state; older ones are dropped so the checkpoint stays bounded. */
104
148
  memoryLimit?: number | undefined;
105
149
  }
106
150
  export declare function agentLoop(options: AgentLoopOptions): WorkflowDef<AgentState, Json>;
107
- export type { AgentLoopOptions, AgentPhase, AgentResult, AgentState, Budget, BudgetTopup, Decision, DecisionOptions, Observation, Spent };
151
+ export type { AgentLoopOptions, AgentPhase, AgentResult, AgentState, ApprovalOptions, Budget, BudgetTopup, Decision, DecisionOptions, Observation, Spent, ToolApproval };
package/dist/agent.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import { d as activity, f as signal } from "./domain-Bs8TeDCv.js";
2
2
  import { z } from "zod";
3
- import { d as WorkflowFailure, m as cmd } from "./src-DVCYkPA7.js";
3
+ import { d as WorkflowFailure, g as signalTimeoutStepId, m as cmd } from "./src-DVCYkPA7.js";
4
4
  // src/agent/decision.ts
5
5
  /**
6
6
  * `decision` — the decider is an ordinary activity whose output is a typed, journaled
@@ -34,6 +34,49 @@ function decision(name, options) {
34
34
  ...options.timeoutMs !== void 0 ? { timeoutMs: options.timeoutMs } : {}
35
35
  });
36
36
  }
37
+ // src/agent/approval.ts
38
+ /**
39
+ * Tool approval: a person says yes or no before a gated tool runs.
40
+ *
41
+ * The wait is an ordinary signal wait, so a run holds no compute while somebody decides.
42
+ * Each gated call waits on its own signal name, `<name>:<iteration>`, which is what makes an
43
+ * approval single-use: a duplicate, a late reply or a signed link for one call can never
44
+ * approve the next one.
45
+ */
46
+ /** Prefix of the signal a gated tool call waits on; the iteration is appended. */
47
+ const DEFAULT_APPROVAL_SIGNAL = "agent.tool_approval";
48
+ const APPROVAL_SCHEMA = z.object({
49
+ approved: z.boolean().optional(),
50
+ reason: z.string().optional(),
51
+ by: z.string().optional()
52
+ });
53
+ /**
54
+ * The signal the gated call of `iteration` waits on. Pass it to `client.signal` or
55
+ * `client.signalLink`; the iteration is the suffix of the wait's step id, `approve#<i>`.
56
+ *
57
+ * @example
58
+ * ```ts
59
+ * await client.signal(runId, approvalSignal(2), { approved: false, reason: "wrong audience" });
60
+ * ```
61
+ */
62
+ function approvalSignal(iteration, name = DEFAULT_APPROVAL_SIGNAL) {
63
+ return signal(`${name}:${iteration}`, APPROVAL_SCHEMA);
64
+ }
65
+ /**
66
+ * Reads a reply. No payload approves (a signed link's form sends none); a payload that is
67
+ * not a {@link ToolApproval} rejects, because an approval nobody can read is not one.
68
+ */
69
+ function readApproval(payload) {
70
+ const parsed = APPROVAL_SCHEMA.safeParse(payload ?? {});
71
+ if (!parsed.success) return {
72
+ approved: false,
73
+ reason: "the approval reply was not valid"
74
+ };
75
+ return {
76
+ ...parsed.data,
77
+ approved: parsed.data.approved !== false
78
+ };
79
+ }
37
80
  // src/agent/budget.ts
38
81
  /**
39
82
  * The budget: ceilings on what one run may spend, and the signal that raises them.
@@ -90,7 +133,8 @@ function asJson(value) {
90
133
  * Nothing loops at runtime: every arrow below is one journaled event folded into state, so
91
134
  * the run survives a crash mid-thought and replays deterministically. The budget is a
92
135
  * reducer decision over the usage the kernel banks on each event — exhaustion parks the run
93
- * on a top-up signal instead of failing it.
136
+ * on a top-up signal instead of failing it. A gated tool waits the same way, on a person's
137
+ * yes or no, before it is dispatched.
94
138
  */
95
139
  const DEFAULT_MAX_ITERATIONS = 50;
96
140
  const DEFAULT_MEMORY_LIMIT = 20;
@@ -99,7 +143,8 @@ const STEP_ID = {
99
143
  decide: (i) => `decide#${i}`,
100
144
  tool: (i) => `tool#${i}`,
101
145
  evaluate: (i) => `evaluate#${i}`,
102
- topup: (i) => `topup#${i}`
146
+ topup: (i) => `topup#${i}`,
147
+ approve: (i) => `approve#${i}`
103
148
  };
104
149
  function agentLoop(options) {
105
150
  const cfg = compile(options);
@@ -115,7 +160,8 @@ function agentLoop(options) {
115
160
  on: {
116
161
  started: (state) => decide(cfg, state),
117
162
  task_done: (state, event) => onTaskDone(cfg, state, event),
118
- signal: (state, event) => onSignal(cfg, state, event)
163
+ signal: (state, event) => onSignal(cfg, state, event),
164
+ timer: (state, event) => onTimer(cfg, state, event)
119
165
  }
120
166
  };
121
167
  }
@@ -126,6 +172,8 @@ function compile(options) {
126
172
  const memoryLimit = options.memoryLimit ?? 20;
127
173
  if (maxIterations < 1) throw new TypeError("agentLoop: maxIterations must be >= 1");
128
174
  if (memoryLimit < 1) throw new TypeError("agentLoop: memoryLimit must be >= 1");
175
+ const gated = options.approval?.tools ?? [];
176
+ for (const name of gated) if (!tools.has(name)) throw new TypeError(`agentLoop: approval names an unknown tool "${name}"`);
129
177
  return {
130
178
  decide: erase(options.decide),
131
179
  tools,
@@ -133,6 +181,12 @@ function compile(options) {
133
181
  threshold: options.threshold,
134
182
  budget: options.budget,
135
183
  topup: options.topup ?? budgetTopup(),
184
+ approval: options.approval === void 0 ? void 0 : {
185
+ tools: new Set(gated),
186
+ name: options.approval.name ?? "agent.tool_approval",
187
+ timeoutMs: options.approval.timeoutMs,
188
+ onTimeout: options.approval.onTimeout ?? "reject"
189
+ },
136
190
  maxIterations,
137
191
  memoryLimit
138
192
  };
@@ -156,7 +210,7 @@ function decide(cfg, state) {
156
210
  * already left behind — is folded and ignored, exactly as the `sequence` helper does.
157
211
  */
158
212
  function onTaskDone(cfg, state, event) {
159
- if (state.phase === "parked" || state.phase === "done") return [state, []];
213
+ if (state.phase === "parked" || state.phase === "approval" || state.phase === "done") return [state, []];
160
214
  if (event.step_id !== STEP_ID[state.phase](state.iteration)) return [state, []];
161
215
  const at = {
162
216
  ...state,
@@ -194,15 +248,81 @@ function onDecided(cfg, state, event) {
194
248
  error
195
249
  }));
196
250
  }
197
- const args = parsed.data;
198
- return [{
251
+ const pending = {
252
+ tool: decision.tool,
253
+ args: parsed.data
254
+ };
255
+ if (cfg.approval?.tools.has(decision.tool)) return askApproval(cfg.approval, {
199
256
  ...state,
200
- phase: "tool",
201
- pending: {
202
- tool: decision.tool,
203
- args
204
- }
205
- }, [cmd.task(target, args, { id: STEP_ID.tool(state.iteration) })]];
257
+ pending
258
+ }, decision.rationale);
259
+ return dispatch(target, {
260
+ ...state,
261
+ pending
262
+ });
263
+ }
264
+ /** Runs the tool the decider picked; `state.pending` already names it. */
265
+ function dispatch(target, state) {
266
+ const at = {
267
+ ...state,
268
+ phase: "tool"
269
+ };
270
+ return [at, [cmd.task(target, at.pending?.args ?? null, { id: STEP_ID.tool(at.iteration) })]];
271
+ }
272
+ /**
273
+ * A gated tool: park on this call's own signal and tell whoever is listening what is being
274
+ * asked. The run holds no compute while somebody decides.
275
+ */
276
+ function askApproval(approval, state, rationale) {
277
+ const at = {
278
+ ...state,
279
+ phase: "approval"
280
+ };
281
+ const context = asJson({
282
+ tool: at.pending?.tool,
283
+ args: at.pending?.args ?? null,
284
+ iteration: at.iteration,
285
+ ...rationale !== void 0 ? { rationale } : {}
286
+ });
287
+ return [at, cmd.awaitHuman(approvalSignal(at.iteration, approval.name), {
288
+ id: STEP_ID.approve(at.iteration),
289
+ context,
290
+ ...approval.timeoutMs !== void 0 ? { timeoutMs: approval.timeoutMs } : {}
291
+ })];
292
+ }
293
+ /** A person answered: run the tool, or tell the decider it was turned down. */
294
+ function onApproval(cfg, state, event) {
295
+ const at = {
296
+ ...state,
297
+ spent: spentOf(event)
298
+ };
299
+ const pending = at.pending;
300
+ const target = pending === void 0 ? void 0 : cfg.tools.get(pending.tool);
301
+ if (pending === void 0 || target === void 0) return advance(cfg, at);
302
+ const reply = readApproval(event.payload);
303
+ if (reply.approved) return dispatch(target, at);
304
+ const who = reply.by !== void 0 ? ` by ${reply.by}` : "";
305
+ const why = reply.reason !== void 0 ? `: ${reply.reason}` : "";
306
+ return advance(cfg, remember(cfg, at, {
307
+ ...pending,
308
+ error: `rejected${who}${why}`
309
+ }));
310
+ }
311
+ /** Nobody answered in time. */
312
+ function onTimer(cfg, state, event) {
313
+ const waiting = signalTimeoutStepId(STEP_ID.approve(state.iteration));
314
+ if (state.phase !== "approval" || event.step_id !== waiting) return [state, []];
315
+ const tool = state.pending?.tool ?? "tool";
316
+ if (cfg.approval?.onTimeout === "fail") throw new WorkflowFailure(`agent: approval timed out for "${tool}"`, { step_id: STEP_ID.approve(state.iteration) });
317
+ const at = {
318
+ ...state,
319
+ spent: spentOf(event)
320
+ };
321
+ return advance(cfg, remember(cfg, at, {
322
+ tool,
323
+ ...at.pending !== void 0 ? { args: at.pending.args } : {},
324
+ error: "approval timed out"
325
+ }));
206
326
  }
207
327
  function onToolDone(cfg, state, event) {
208
328
  const output = event.output ?? null;
@@ -236,6 +356,7 @@ function onEvaluated(cfg, state, event) {
236
356
  return advance(cfg, at);
237
357
  }
238
358
  function onSignal(cfg, state, event) {
359
+ if (state.phase === "approval" && event.step_id === STEP_ID.approve(state.iteration)) return onApproval(cfg, state, event);
239
360
  if (state.phase !== "parked" || event.name !== cfg.topup.name) return [state, []];
240
361
  const granted = cfg.topup.schema.safeParse(event.payload);
241
362
  return decide(cfg, {
@@ -321,4 +442,4 @@ function readScore(output) {
321
442
  }
322
443
  throw new WorkflowFailure("agent: evaluate returned no numeric `score`", output);
323
444
  }
324
- export { DEFAULT_MAX_ITERATIONS, DEFAULT_MEMORY_LIMIT, DEFAULT_TOPUP_SIGNAL, DONE, agentLoop, budgetTopup, decision };
445
+ export { DEFAULT_APPROVAL_SIGNAL, DEFAULT_MAX_ITERATIONS, DEFAULT_MEMORY_LIMIT, DEFAULT_TOPUP_SIGNAL, DONE, agentLoop, approvalSignal, budgetTopup, decision };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@oona/vlo",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Vlo: an event-sourced durable execution engine for workflows and agents. Workflows are pure reducers; the kernel is Rust compiled to wasm; your Postgres or SQLite is the journal.",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -10,7 +10,7 @@
10
10
  "url": "git+https://github.com/oonalab/vlo.git",
11
11
  "directory": "sdk/ts/sdk"
12
12
  },
13
- "homepage": "https://github.com/oonalab/vlo#readme",
13
+ "homepage": "https://oonalab.github.io/vlo/",
14
14
  "bugs": "https://github.com/oonalab/vlo/issues",
15
15
  "keywords": [
16
16
  "workflow",
@@ -88,6 +88,8 @@
88
88
  "tsdown": "^0.23.0",
89
89
  "tsx": "^4.19.0",
90
90
  "typedoc": "^0.28.20",
91
+ "typedoc-plugin-markdown": "^4.14.1",
92
+ "typedoc-vitepress-theme": "^1.1.4",
91
93
  "typescript": "^5.7.0",
92
94
  "vitest": "^4.1.9",
93
95
  "zod": "^4.0.0"