@restatedev/agents 0.5.0 → 0.6.0

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.
Files changed (96) hide show
  1. package/README.md +69 -17
  2. package/dist/calls.d.ts +20 -1
  3. package/dist/calls.d.ts.map +1 -1
  4. package/dist/calls.js +46 -7
  5. package/dist/calls.js.map +1 -1
  6. package/dist/claude/index.d.ts +11 -11
  7. package/dist/claude/index.d.ts.map +1 -1
  8. package/dist/claude/index.js +9 -6
  9. package/dist/claude/index.js.map +1 -1
  10. package/dist/client.d.ts +1 -1
  11. package/dist/client.d.ts.map +1 -1
  12. package/dist/common.d.ts +62 -23
  13. package/dist/common.d.ts.map +1 -1
  14. package/dist/common.js +67 -38
  15. package/dist/common.js.map +1 -1
  16. package/dist/{signals.d.ts → companion.d.ts} +106 -43
  17. package/dist/companion.d.ts.map +1 -0
  18. package/dist/companion.js +463 -0
  19. package/dist/companion.js.map +1 -0
  20. package/dist/conversation.d.ts +103 -5
  21. package/dist/conversation.d.ts.map +1 -1
  22. package/dist/conversation.js +295 -75
  23. package/dist/conversation.js.map +1 -1
  24. package/dist/deepseek/index.d.ts +11 -11
  25. package/dist/deepseek/index.d.ts.map +1 -1
  26. package/dist/deepseek/index.js +23 -26
  27. package/dist/deepseek/index.js.map +1 -1
  28. package/dist/index.d.ts +8 -4
  29. package/dist/index.d.ts.map +1 -1
  30. package/dist/index.js +7 -3
  31. package/dist/index.js.map +1 -1
  32. package/dist/langgraph/checkpointer.d.ts +2 -0
  33. package/dist/langgraph/checkpointer.d.ts.map +1 -1
  34. package/dist/langgraph/checkpointer.js +1 -1
  35. package/dist/langgraph/checkpointer.js.map +1 -1
  36. package/dist/langgraph/graph.d.ts.map +1 -1
  37. package/dist/langgraph/graph.js +32 -13
  38. package/dist/langgraph/graph.js.map +1 -1
  39. package/dist/langgraph/index.d.ts +11 -11
  40. package/dist/langgraph/index.d.ts.map +1 -1
  41. package/dist/langgraph/index.js +19 -13
  42. package/dist/langgraph/index.js.map +1 -1
  43. package/dist/langgraph/nodes.d.ts +2 -1
  44. package/dist/langgraph/nodes.d.ts.map +1 -1
  45. package/dist/langgraph/nodes.js +23 -20
  46. package/dist/langgraph/nodes.js.map +1 -1
  47. package/dist/object.d.ts +24 -22
  48. package/dist/object.d.ts.map +1 -1
  49. package/dist/object.js +14 -11
  50. package/dist/object.js.map +1 -1
  51. package/dist/opencode/index.d.ts +11 -11
  52. package/dist/opencode/index.d.ts.map +1 -1
  53. package/dist/opencode/index.js +25 -27
  54. package/dist/opencode/index.js.map +1 -1
  55. package/dist/pi/index.d.ts +11 -11
  56. package/dist/pi/index.d.ts.map +1 -1
  57. package/dist/pi/index.js +16 -17
  58. package/dist/pi/index.js.map +1 -1
  59. package/dist/steering.d.ts +2 -1
  60. package/dist/steering.d.ts.map +1 -1
  61. package/dist/steering.js +2 -2
  62. package/dist/steering.js.map +1 -1
  63. package/dist/tools.d.ts +21 -0
  64. package/dist/tools.d.ts.map +1 -1
  65. package/dist/tools.js +54 -14
  66. package/dist/tools.js.map +1 -1
  67. package/dist/webhook.js +1 -1
  68. package/dist/webhook.js.map +1 -1
  69. package/package.json +3 -3
  70. package/src/calls.ts +52 -11
  71. package/src/claude/README.md +4 -2
  72. package/src/claude/index.ts +9 -7
  73. package/src/client.ts +1 -1
  74. package/src/common.ts +99 -40
  75. package/src/companion.ts +674 -0
  76. package/src/conversation.ts +353 -101
  77. package/src/deepseek/README.md +7 -1
  78. package/src/deepseek/index.ts +22 -24
  79. package/src/index.ts +10 -4
  80. package/src/langgraph/README.md +8 -5
  81. package/src/langgraph/checkpointer.ts +1 -1
  82. package/src/langgraph/graph.ts +30 -16
  83. package/src/langgraph/index.ts +24 -17
  84. package/src/langgraph/nodes.ts +24 -20
  85. package/src/object.ts +43 -40
  86. package/src/opencode/README.md +5 -2
  87. package/src/opencode/index.ts +26 -27
  88. package/src/pi/README.md +6 -1
  89. package/src/pi/index.ts +16 -15
  90. package/src/steering.ts +8 -7
  91. package/src/tools.ts +60 -18
  92. package/src/webhook.ts +1 -1
  93. package/dist/signals.d.ts.map +0 -1
  94. package/dist/signals.js +0 -383
  95. package/dist/signals.js.map +0 -1
  96. package/src/signals.ts +0 -590
package/dist/tools.js CHANGED
@@ -6,11 +6,15 @@
6
6
  // A tool runs with the agent's context, and with the id of the model's tool
7
7
  // call: Restate calls carry an idempotency key made of the invocation id and
8
8
  // that id, so a tool call run again after a crash makes the same call, once.
9
+ // A workflow's `run` is the exception: it runs once per workflow id, and
10
+ // Restate refuses a second call of it whatever its idempotency key, so the
11
+ // tool waits for the run by its invocation id ({@link runWorkflow}).
9
12
  import * as restate from '@restatedev/sessions';
13
+ import { attach, start } from '@restatedev/sessions/internal';
10
14
  import { z } from 'zod';
11
15
  import { stopSignalOf, configured, ToolError } from './common.js';
12
16
  import { callOf } from './calls.js';
13
- import { signals, signalsOf } from './signals.js';
17
+ import { companionHere, NoCompanion } from './companion.js';
14
18
  const TOOL = Symbol.for('restate-agents.tool');
15
19
  /** The JSON schema of `t`'s input, which a framework offers the model. */
16
20
  export const jsonSchemaOf = (t) => z.toJSONSchema(t.input);
@@ -60,6 +64,10 @@ export const tool = (options) => ({
60
64
  throw turn.reason;
61
65
  if (error instanceof restate.CancelledError)
62
66
  throw error;
67
+ // An object without a companion, waiting for a signal: a programming error, which fails the turn once,
68
+ // rather than an answer for the model to act on.
69
+ if (error instanceof NoCompanion)
70
+ throw error;
63
71
  // A terminal error is the tool's answer, which the model can act on; any
64
72
  // other error fails the attempt, which Restate retries.
65
73
  if (error instanceof restate.TerminalError)
@@ -91,14 +99,35 @@ async function once(name, input, context, body, options) {
91
99
  }
92
100
  /** Whether a target is keyed: a virtual object (key) or a workflow (id). */
93
101
  const keyed = (target) => 'object' in target || 'workflow' in target;
94
- /** Call `method` of `service`, with JSON in and out, once per tool call (see {@link ToolContext}). */
95
- const invoke = ({ ctx, idempotencyKey }, target) => ctx.rpc({
96
- service: target.service,
97
- handler: target.method,
98
- key: target.key,
99
- input: target.parameter,
100
- idempotencyKey,
101
- });
102
+ /**
103
+ * Call `method` of `service`, with JSON in and out, once per tool call (see
104
+ * {@link ToolContext}): the call's idempotency key makes the call a new
105
+ * attempt makes again (after a crash, or a suspension) the one the first
106
+ * made, whose result it gets. A workflow's `run` runs instead ({@link runWorkflow}).
107
+ */
108
+ const invoke = ({ ctx, idempotencyKey }, target) => target.workflow && target.method === 'run'
109
+ ? runWorkflow(ctx, { service: target.service, key: target.key, input: target.parameter })
110
+ : ctx.rpc({
111
+ service: target.service,
112
+ handler: target.method,
113
+ key: target.key,
114
+ input: target.parameter,
115
+ idempotencyKey,
116
+ });
117
+ /**
118
+ * Run workflow `service` (its `run` handler) with id `key` and `input` to its
119
+ * end, and resolve to its result: a call of it, whose result it does not wait
120
+ * for, then a wait for the run by the call's invocation id. A workflow's
121
+ * `run` runs once per id: Restate refuses a second call of it, whatever the
122
+ * call's idempotency key, but that call's invocation id is the run's. So a
123
+ * new attempt (after a crash, or a suspension while the run went on) that
124
+ * makes the call again waits for the run an earlier attempt started, and
125
+ * only the first starts one; and a fixed id that ran before gets its run's
126
+ * result. It is a call, not a send: stopping the turn cancels the run, as it
127
+ * cancels the turn's other calls (`cancelCalls`). The Python SDK's
128
+ * `run_workflow` sends instead, and so leaves the run going.
129
+ */
130
+ export const runWorkflow = async (ctx, { service, key, input }) => attach(ctx, await start(ctx, { service, handler: 'run', key, input }));
102
131
  /** The tool's input: the handler's, and the key if the model chooses it. */
103
132
  function inputOf(target, { input, key }) {
104
133
  const shape = input?.shape ?? {};
@@ -130,7 +159,12 @@ export const call = (target, handler, options) => tool({
130
159
  name: options.name ?? `${target.name}_${handler}`,
131
160
  description: options.description,
132
161
  input: inputOf(target, options),
133
- run: async (input, context) => once(`${target.name}/${handler}`, input, context, async (c) => invoke(c, { service: target.name, method: handler, ...(await split(target, options, input, c.ctx)) })),
162
+ run: async (input, context) => once(`${target.name}/${handler}`, input, context, async (c) => invoke(c, {
163
+ service: target.name,
164
+ method: handler,
165
+ workflow: 'workflow' in target,
166
+ ...(await split(target, options, input, c.ctx)),
167
+ })),
134
168
  });
135
169
  /**
136
170
  * A tool that sends to `handler` of `target`, without waiting for it: a
@@ -150,16 +184,18 @@ export const send = (target, handler, options) => tool({
150
184
  * A tool that runs the workflow `target` (its `run` handler) to the end, and
151
185
  * answers with its result. Each tool call is a workflow of its own, with an
152
186
  * id made of the agent's key and the tool call's id, unless `key` gives one.
187
+ * A tool call made again (after a crash, or a suspension while the workflow
188
+ * ran) waits for the run it started, and a `key` that ran before gets that
189
+ * run's result ({@link runWorkflow}).
153
190
  */
154
191
  export const workflow = (target, options) => tool({
155
192
  name: options.name ?? target.name,
156
193
  description: options.description,
157
194
  input: z.object(options.input?.shape ?? {}),
158
- run: async (input, context) => once(target.name, input, context, async (c) => invoke(c, {
195
+ run: async (input, context) => once(target.name, input, context, async (c) => runWorkflow(c.ctx, {
159
196
  service: target.name,
160
- method: 'run',
161
197
  key: options.key === undefined ? `${c.ctx.key}-${c.callId}` : await configured(options.key, c.ctx),
162
- parameter: options.input ? input : undefined,
198
+ input: options.input ? input : undefined,
163
199
  })),
164
200
  });
165
201
  export function subagent(agent, { description = agent.description, name: toolName = agent.name, handler, } = {}) {
@@ -211,7 +247,11 @@ export const signal = (name, options) => tool({
211
247
  * `pending` shows `input` if `shown`. `rejoin` and `approval` are
212
248
  * {@link callOf}'s.
213
249
  */
214
- const wait = (toolCall, name, input, { shown, rejoin, approval }) => once(`signal/${name}`, input, toolCall, async ({ ctx, idempotencyKey: id }) => ctx.rpc(signals, signalsOf(ctx), { idempotencyKey: id }).wait({ id, name, ...(shown ? { input } : {}) }), { rejoin, approval });
250
+ const wait = async (toolCall, name, input, { shown, rejoin, approval }) => {
251
+ // Before the call is recorded: an object without a companion fails the turn, once (`NoCompanion`).
252
+ const companion = companionHere(toolCall.ctx, 'a wait for a signal');
253
+ return once(`signal/${name}`, input, toolCall, async ({ ctx, idempotencyKey: id }) => ctx.rpc(companion, ctx.key, { idempotencyKey: id }).wait({ id, name, ...(shown ? { input } : {}) }), { rejoin, approval });
254
+ };
215
255
  /**
216
256
  * Wait for the signal `name` to the agent, for the model's tool call
217
257
  * `callId`, and answer with its value: what a {@link signal} tool does, for
package/dist/tools.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"tools.js","sourceRoot":"","sources":["../src/tools.ts"],"names":[],"mappings":"AAAA,4EAA4E;AAC5E,4EAA4E;AAC5E,wEAAwE;AACxE,sCAAsC;AACtC,EAAE;AACF,4EAA4E;AAC5E,6EAA6E;AAC7E,6EAA6E;AAC7E,OAAO,KAAK,OAAO,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,YAAY,EAAkB,UAAU,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAClF,OAAO,EAAE,MAAM,EAAE,MAAM,YAAY,CAAC;AACpC,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAElD,MAAM,IAAI,GAAG,MAAM,CAAC,GAAG,CAAC,qBAAqB,CAAC,CAAC;AAmC/C,0EAA0E;AAC1E,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,CAAO,EAAE,EAAE,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,KAAK,CAA4B,CAAC;AAE5F,wEAAwE;AACxE,MAAM,CAAC,MAAM,MAAM,GAAG,CAAC,KAAc,EAAiB,EAAE,CAAC,OAAO,KAAK,KAAK,QAAQ,IAAI,KAAK,KAAK,IAAI,IAAI,IAAI,IAAI,KAAK,CAAC;AAEtH,qFAAqF;AACrF,MAAM,IAAI,GAAG,CAAC,KAAc,EAAE,EAAE,CAC9B,OAAO,KAAK,KAAK,QAAQ,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK,KAAK,IAAI,IAAI,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,CA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ACH,MAAM,IAAI,GAAG,KAAK,EAChB,QAAkB,EAClB,IAAY,EACZ,KAAc,EACd,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAA4D,EACnE,EAAE;IACpB,mGAAmG;IACnG,MAAM,SAAS,GAAG,aAAa,CAAC,QAAQ,CAAC,GAAG,EAAE,qBAAqB,CAAC,CAAC;IACrE,OAAO,IAAI,CACT,UAAU,IAAI,EAAE,EAChB,KAAK,EACL,QAAQ,EACR,KAAK,EAAE,EAAE,GAAG,EAAE,cAAc,EAAE,EAAE,EAAE,EAAE,EAAE,CACpC,GAAG,CAAC,GAAG,CAAC,SAAS,EAAE,GAAG,CAAC,GAAG,EAAE,EAAE,cAAc,EAAE,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,EAAE,EAAE,EAAE,IAAI,EAAE,GAAG,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,EACrG,EAAE,MAAM,EAAE,QAAQ,EAAE,CACrB,CAAC;AACJ,CAAC,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,CACrB,GAA2B,EAC3B,MAAc,EACd,IAAY,EACZ,KAAe,EACf,EAAE,QAAQ,GAAG,KAAK,EAAE,MAAM,GAAG,KAAK,EAAE,GAA6C,EAAE,EACjE,EAAE,CAAC,IAAI,CAAC,EAAE,GAAG,EAAE,MAAM,EAAE,EAAE,IAAI,EAAE,KAAK,IAAI,IAAI,EAAE,EAAE,KAAK,EAAE,KAAK,KAAK,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAC"}
package/dist/webhook.js CHANGED
@@ -16,7 +16,7 @@
16
16
  // The other system posts to Restate's ingress, at `/<name>/webhook`.
17
17
  import { createHmac, timingSafeEqual } from 'node:crypto';
18
18
  import { sdk as restate } from '@restatedev/sessions/internal';
19
- import { deliver, hasCompanion } from './signals.js';
19
+ import { deliver, hasCompanion } from './companion.js';
20
20
  /**
21
21
  * The message an agent gets for a webhook's delivery: its body, as JSON, in
22
22
  * a `<webhook>` element that says which webhook, and which delivery.
@@ -1 +1 @@
1
- {"version":3,"file":"webhook.js","sourceRoot":"","sources":["../src/webhook.ts"],"names":[],"mappings":"AAAA,wEAAwE;AACxE,qEAAqE;AACrE,2EAA2E;AAC3E,yEAAyE;AACzE,sBAAsB;AACtB,EAAE;AACF,6BAA6B;AAC7B,sBAAsB;AACtB,wFAAwF;AACxF,4CAA4C;AAC5C,uBAAuB;AACvB,0CAA0C;AAC1C,QAAQ;AACR,iCAAiC;AACjC,EAAE;AACF,qEAAqE;AACrE,OAAO,EAAE,UAAU,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC1D,OAAO,EAAE,GAAG,IAAI,OAAO,EAAE,MAAM,+BAA+B,CAAC;AAC/D,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAoDrD;;;;;;;GAOG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,CAAC,IAAY,EAAE,QAAgB,EAAE,KAAc,EAAE,EAAE,CAC/E,kBAAkB,IAAI,eAAe,QAAQ,OAAO,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,IAAI,EAAE,CAAC,CAAC,cAAc,CAAC;AAEnG,8EAA8E;AAC9E,MAAM,MAAM,GAAG,CAAC,IAAgB,EAAE,SAA6B,EAAE,MAAc,EAAE,EAAE;IACjF,MAAM,QAAQ,GAAG,UAAU,CAAC,QAAQ,EAAE,MAAM,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,CAAC;IACpE,MAAM,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,SAAS,IAAI,EAAE,CAAC,CAAC,OAAO,CAAC,UAAU,EAAE,EAAE,CAAC,EAAE,KAAK,CAAC,CAAC;IAC5E,OAAO,KAAK,CAAC,MAAM,KAAK,QAAQ,CAAC,MA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,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC;gBAC9E,KAAK,MAAM,KAAK,IAAI,KAAK;oBAAE,OAAO,CAAC,GAAG,EAAE,KAAK,EAAE,EAAE,EAAE,IAAI,EAAE,EAAE,cAAc,EAAE,WAAW,IAAI,IAAI,QAAQ,EAAE,EAAE,CAAC,CAAC;YAC9G,CAAC,CACF;SACF;KACF,CAAC,CAAC;AACL,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@restatedev/agents",
3
- "version": "0.5.0",
3
+ "version": "0.6.0",
4
4
  "description": "Agent frameworks in Restate virtual objects, their state in the object's SQL database: pi, OpenCode, LangGraph, Claude (Anthropic SDK) and DeepSeek Harness",
5
5
  "license": "MIT",
6
6
  "repository": {
@@ -108,7 +108,7 @@
108
108
  "@opencode/sdk": "2.2.6",
109
109
  "@opencode/server": "2.2.6",
110
110
  "@restatedev/restate-sdk": "1.18.2",
111
- "@restatedev/sessions": "0.5.0",
111
+ "@restatedev/sessions": "0.6.0",
112
112
  "effect": "4.1.0",
113
113
  "zod": "4.6.5"
114
114
  },
@@ -144,7 +144,7 @@
144
144
  "@opencode/plugin": "2.2.6",
145
145
  "@opencode/sdk": "2.2.6",
146
146
  "@opencode/server": "2.2.6",
147
- "@restatedev/sessions": "^0.5.0",
147
+ "@restatedev/sessions": "^0.6.0",
148
148
  "effect": "4.1.0",
149
149
  "zod": "^4.6.5"
150
150
  },
package/src/calls.ts CHANGED
@@ -11,7 +11,7 @@
11
11
  // task), which it waits for again, or whose answer it gets.
12
12
  //
13
13
  // A call is kept until the framework's transcript has its result under the
14
- // last id it was made with ({@link settleCalls}, at each publish, and before each
14
+ // last id it was made with ({@link settleCalls}, after each commit of steps, and before each
15
15
  // tool call): one that answered just before a crash, whose result the
16
16
  // framework had not stored, is made again as the same call. An error there
17
17
  // is not its result (the DeepSeek Harness gives the call it interrupted
@@ -54,8 +54,11 @@ interface Calls {
54
54
  calls: Call[];
55
55
  }
56
56
 
57
- /** The table of the {@link Calls}: one row, of the invocation whose calls they are. */
58
- const SCHEMA = new Schema('restate-agents.calls', [
57
+ /**
58
+ * The table of the {@link Calls}: one row, of the invocation whose calls they are. `answerOnce` applies it with
59
+ * the conversation's, in one commit, as a key's first turn starts.
60
+ */
61
+ export const SCHEMA = new Schema('restate-agents.calls', [
59
62
  `CREATE TABLE restate_agent_calls (
60
63
  row INTEGER PRIMARY KEY CHECK (row = 0),
61
64
  invocation TEXT NOT NULL,
@@ -66,8 +69,33 @@ const SCHEMA = new Schema('restate-agents.calls', [
66
69
  /** What the calls need of a handler's context. */
67
70
  type CallsContext = Pick<restate.SessionContext, 'db' | 'request'>;
68
71
 
69
- /** Store `calls`, committed before the call they record is made. */
70
- async function store(ctx: CallsContext, { invocation, calls }: Calls) {
72
+ /** What writes the rows the conversation of the attempt's turn holds back, by its context. */
73
+ const HELD = new ScopeKey<() => Promise<void>>('the held rows of the conversation');
74
+
75
+ /**
76
+ * Have {@link flushHeld} write, with `flush`, the rows that the conversation
77
+ * of the attempt's turn holds back (`Conversation.hold`): `answerOnce` does.
78
+ */
79
+ export const holding = (ctx: restate.SessionContext, flush: () => Promise<void>) => HELD.set(ctx, flush);
80
+
81
+ /**
82
+ * Write the rows that the conversation of the attempt's turn holds back, if
83
+ * any (see `Conversation.hold`). Call it before what another party sees, or
84
+ * what outlives the attempt: a publish, a Restate call, send or wait. A held
85
+ * row is lost in a crash, and the retried attempt makes it again; what was
86
+ * seen or called must not depend on it.
87
+ */
88
+ export async function flushHeld(ctx: restate.SessionContext) {
89
+ await HELD.get(ctx)?.();
90
+ }
91
+
92
+ /**
93
+ * Store `calls`, committed before the call they record is made. The rows the
94
+ * conversation holds back are written first: the call outlives the attempt,
95
+ * and what led to it must too.
96
+ */
97
+ async function store(ctx: restate.SessionContext, { invocation, calls }: Calls) {
98
+ await flushHeld(ctx);
71
99
  await ctx.db.execute('INSERT OR REPLACE INTO restate_agent_calls (row, invocation, calls) VALUES (0, ?, ?)', [
72
100
  invocation,
73
101
  JSON.stringify(calls),
@@ -85,12 +113,25 @@ async function load(ctx: CallsContext, invocation: string): Promise<Calls> {
85
113
  : { invocation, calls: [] };
86
114
  }
87
115
 
88
- /** Each attempt's id, and its calls, by its context. */
89
- const ATTEMPT = new ScopeKey<{ id: string; calls: Promise<Calls> }>('the calls of an attempt');
116
+ /** Each attempt's id, and its calls, by its context, once they are being read. */
117
+ const ATTEMPT = new ScopeKey<{ id: string; calls?: Promise<Calls> }>('the calls of an attempt');
90
118
 
91
- /** The attempt of `ctx`: its id, and the calls of its invocation (loaded once, shared by calls made at once). */
92
- function attemptOf(ctx: restate.SessionContext) {
93
- return ATTEMPT.of(ctx, () => ({ id: randomUUID(), calls: load(ctx, ctx.request.id) }));
119
+ /**
120
+ * The attempt of `ctx`: its id, and the calls of its invocation (loaded once,
121
+ * shared by calls made at once). A load that fails (its schema's commit
122
+ * cancelled, say) is not kept: the next asks again, so that a stopped turn's
123
+ * close reads the calls as stored, rather than fail on the load it found.
124
+ */
125
+ function attemptOf(ctx: restate.SessionContext): { id: string; calls: Promise<Calls> } {
126
+ const attempt = ATTEMPT.of(ctx, () => ({ id: randomUUID() }));
127
+ if (attempt.calls === undefined) {
128
+ const calls = load(ctx, ctx.request.id);
129
+ attempt.calls = calls;
130
+ calls.catch(() => {
131
+ if (attempt.calls === calls) attempt.calls = undefined;
132
+ });
133
+ }
134
+ return attempt as { id: string; calls: Promise<Calls> };
94
135
  }
95
136
 
96
137
  /** `value` as JSON with its objects' keys sorted: the same input, however its keys came, is the same call. */
@@ -178,7 +219,7 @@ export async function callOf(
178
219
  * Forget the calls that answered whose result the framework stored: those
179
220
  * of which `stored(id, failed)` is true for the last id they were made with,
180
221
  * `failed` the error that answered the call, if one did. Called
181
- * at each publish, and before each tool call, with the transcript as the
222
+ * after each commit of steps, and before each tool call, with the transcript as the
182
223
  * framework stored it: also in an attempt that made no call yet, which would
183
224
  * otherwise take one an earlier attempt made, and the model has the result
184
225
  * of.
@@ -68,8 +68,10 @@ stored.
68
68
 
69
69
  - **Each reply is stored before its tools run, and their results before the
70
70
  next request.** So a crash during the tools resumes them with the same tool
71
- call ids, without asking the model again; and a stored final reply is the
72
- answer, without asking the model for it again.
71
+ call ids, without asking the model again. The final reply, which no tool
72
+ waits for, is stored with the turn's answer, in one commit: a crash before
73
+ it asks the model again. A paused reply (`pause_turn`, a server tool's long
74
+ turn) is stored before the model goes on from it.
73
75
  - **A tool is idempotent by its tool call id** (`callId` of `tool()`'s
74
76
  `run`, or `callId(context)` for the SDK's tools), which it passes on, such
75
77
  as in an idempotency key.
@@ -46,10 +46,9 @@ import {
46
46
  modelIdOf,
47
47
  modelOf,
48
48
  RETURNED_UNRECORDED,
49
+ toolCallStarted,
49
50
  stopSignalOf,
50
51
  type Summarize,
51
- toolCallEnded,
52
- toolCallStarted,
53
52
  NO_ANSWER,
54
53
  } from '../common.ts';
55
54
  import { answerOnce, type Items, type Parsed, type Run } from '../conversation.ts';
@@ -192,9 +191,9 @@ interface Agent {
192
191
 
193
192
  /**
194
193
  * The run of `agent` on the conversation: from the stored turn on, each
195
- * reply stored before its tools run, and their results after; each round of
196
- * tool calls published as it starts and ends (for the clients that follow
197
- * the conversation). At each step (before a request that follows the
194
+ * reply with tool calls stored before its tools run, and their results
195
+ * after; each such write published as it commits, by the conversation (for
196
+ * the clients that follow it), and the final reply stored with the answer. At each step (before a request that follows the
198
197
  * prompt or the tools' results), it takes the messages steered to the turn
199
198
  * (`takeSteers`): the request then goes out from the conversation's
200
199
  * history, which has them after the tools' results.
@@ -240,7 +239,6 @@ const runOf =
240
239
  await turn.append(results);
241
240
  runner.pushMessages(results);
242
241
  }
243
- await toolCallEnded(ctx);
244
242
  await step();
245
243
  }
246
244
  let paused = false;
@@ -252,17 +250,21 @@ const runOf =
252
250
  // Paused (a server tool's long turn): a step of the turn, not a reply to
253
251
  // end it with, and the model goes on from it.
254
252
  if (message.stop_reason === 'pause_turn') {
253
+ // Stored before the model goes on: a crash in a server tool's long turn goes on from it, rather than
254
+ // ask the whole of it again.
255
255
  await turn.append(said);
256
+ await conversation.flush();
256
257
  paused = true;
257
258
  break;
258
259
  }
260
+ // A reply with tool calls commits, and is published, before its tools run; the final reply commits with
261
+ // the turn's answer.
259
262
  await turn.appendReply([said]);
260
263
  if (!message.content.some((c) => c.type === 'tool_use')) return textOf(message.content);
261
264
  await toolCallStarted(ctx);
262
265
  const results = await runner.generateToolResponse();
263
266
  check();
264
267
  if (results) await turn.append(results);
265
- await toolCallEnded(ctx);
266
268
  await step();
267
269
  }
268
270
  if (!paused) throw new Error('the tool runner ended without a reply');
package/src/client.ts CHANGED
@@ -16,7 +16,7 @@ import * as clients from '@restatedev/restate-sdk-clients';
16
16
  import type { VirtualObjectDefinition } from '@restatedev/restate-sdk-core';
17
17
  import type { Answering, ChatMessage, Messages, MessagesRequest, Part } from './common.ts';
18
18
  import type { Status, Stopped, Synced, SyncRequest } from './object.ts';
19
- import type { Notifications, Resolved, Signal, Steered, Steering, Waiting, Watch } from './signals.ts';
19
+ import type { Notifications, Resolved, Signal, Steered, Steering, Waiting, Watch } from './companion.ts';
20
20
 
21
21
  export type {
22
22
  Answering,
package/src/common.ts CHANGED
@@ -5,8 +5,34 @@
5
5
  // budget.
6
6
  import * as restate from '@restatedev/sessions';
7
7
  import { cancelCalls, cancelled, definitionOf, Link, ScopeKey } from '@restatedev/sessions/internal';
8
- import { settleCalls } from './calls.ts';
9
- import { type Published, type Steer, signals, signalsOf } from './signals.ts';
8
+ import { flushHeld, settleCalls } from './calls.ts';
9
+ import { companionHere, type Published, type Steer } from './companion.ts';
10
+
11
+ /**
12
+ * The context of an agent's handler: a session context, from an object that
13
+ * has a companion.
14
+ *
15
+ * The agent's own surface takes it: the handlers and views of
16
+ * `sessionObject()` and of a framework's `agent()`, a `chat` handler's
17
+ * answer, and what only an agent does with a context ({@link chatTurn},
18
+ * {@link publish}). The layer a handler belongs to is then in its
19
+ * signature, where the person writing it reads it, rather than found out in
20
+ * the middle of a turn, after a model round-trip, looking like a tool
21
+ * failure.
22
+ *
23
+ * It is a signpost, not a fence: it adds nothing to a session context, so
24
+ * the two are the same type to the compiler, and `NoCompanion` stays the
25
+ * guard that stops a wait from an object without a companion.
26
+ */
27
+ export interface AgentContext extends restate.SessionContext {}
28
+
29
+ /**
30
+ * The context of an agent's view: a view context, from an object that has a
31
+ * companion. What {@link AgentContext} is to a handler, for the views that
32
+ * read what the agent is doing, or tell its companion to (`status`,
33
+ * `pending`, `signal`, `steer`, `watch`).
34
+ */
35
+ export interface AgentViewContext extends restate.ViewContext {}
10
36
 
11
37
  /**
12
38
  * A value, or a function of the invocation's context that gives it: the
@@ -273,16 +299,19 @@ export const settingsOf = (ctx: restate.SessionContext): Settings =>
273
299
  /** Whether the agent of `ctx` runs in the background. */
274
300
  const unfollowed = (ctx: restate.SessionContext) => agentOf(ctx)?.background === true;
275
301
 
276
- /** The `signals` object of the agent of `ctx`. */
277
- const signalsOfAgent = (ctx: restate.SessionContext) => ctx.rpc(signals, signalsOf(ctx));
302
+ /**
303
+ * The companion of the agent of `ctx`, for `needs`: its own, at its key. An
304
+ * object without one fails with a terminal error (`NoCompanion`).
305
+ */
306
+ const companionOfAgent = (ctx: restate.SessionContext, needs: string) => ctx.rpc(companionHere(ctx, needs), ctx.key);
278
307
 
279
308
  /**
280
309
  * The messages steered to a `chat` turn that it has not taken yet, as the
281
310
  * companion last published them. The companion answers them to every
282
- * `publish`, which a turn makes at each tool call's start and end: so the
283
- * turn knows of them without a call of its own, and finds them at its next
284
- * step (`takeSteers`). The newest revision wins, as tool calls that run at
285
- * once publish at once.
311
+ * `publish` (and `start`), which a turn makes as it starts and after each
312
+ * write of its steps that commits: so the turn knows of them without a call
313
+ * of its own, and finds them at its next step (`takeSteers`). The newest
314
+ * revision wins, as writes that run at once publish at once.
286
315
  */
287
316
  export class Inbox {
288
317
  revision = -1;
@@ -321,35 +350,54 @@ export const inboxOf = (ctx: restate.SessionContext) => INBOX.get(ctx);
321
350
  * increases, and the clients that follow it read it again; while a framework
322
351
  * answers ({@link answering}), the calls whose results it stored are
323
352
  * forgotten first. It is a call to Restate, so it also sends what the
324
- * handler wrote before, for them to read.
353
+ * handler wrote before, for them to read: the rows the conversation holds
354
+ * back are written first (`flushHeld`), as the clients read them once told.
355
+ *
356
+ * Only a `chat` turn ({@link chatTurn}: after each commit of its steps) and
357
+ * `settle` publish, on an object with a companion: one without fails with a
358
+ * terminal error (`NoCompanion`), rather than call a companion nobody serves.
325
359
  */
326
- export const publish = async (ctx: restate.SessionContext) => {
327
- const stored = ANSWERING.get(ctx);
328
- if (stored) await settled(ctx, stored);
329
- const published = await signalsOfAgent(ctx).publish();
360
+ export const publish = async (ctx: AgentContext) => {
361
+ const companion = companionOfAgent(ctx, 'a publish');
362
+ await flushHeld(ctx);
363
+ const published = await companion.publish();
330
364
  INBOX.get(ctx)?.saw(published);
331
365
  };
332
366
 
333
- /** A step of a turn of `ctx`: {@link publish} it, unless the agent runs in the background, which publishes the turn's end only. */
334
- export const stepped = async (ctx: restate.SessionContext) => {
335
- if (!unfollowed(ctx)) await publish(ctx);
336
- };
367
+ /**
368
+ * What the turn running on `ctx` makes after each commit of its steps (a
369
+ * reply with tool calls, the tools' results), if anything: set by
370
+ * {@link chatTurn}, for a followed turn, to publish. The conversation takes
371
+ * it as it is, without knowing what it does (`answerOnce` hands it to
372
+ * `Conversation.hold`); a turn run outside a `chat` turn (a handler of your
373
+ * own that calls a framework's `prompt()`) has none: it stores its steps,
374
+ * and publishes nothing.
375
+ */
376
+ const AFTER_STEPS = new ScopeKey<() => Promise<void>>('afterSteps');
377
+
378
+ /** What the turn running on `ctx` makes after each commit of its steps, if anything: see {@link AFTER_STEPS}. */
379
+ export const afterStepsOf = (ctx: restate.SessionContext): (() => Promise<void>) | undefined => AFTER_STEPS.get(ctx);
337
380
 
338
381
  /**
339
- * A tool call of the turn of `ctx` starts: {@link publish} it, which forgets
340
- * the calls whose results are stored (calls.ts) before the tool makes its
341
- * own. In the background, which publishes the turn's end only, it forgets
342
- * them alone.
382
+ * A tool call of the turn of `ctx` starts: forget the calls whose results are
383
+ * stored (calls.ts) before the tool makes its own. It publishes nothing: a
384
+ * followed `chat` turn publishes once the call is stored (with its reply),
385
+ * and once its result is ({@link afterStepsOf}).
343
386
  */
344
387
  export async function toolCallStarted(ctx: restate.SessionContext) {
345
- if (!unfollowed(ctx)) return publish(ctx);
346
- const stored = ANSWERING.get(ctx);
347
- if (stored) await settled(ctx, stored);
388
+ await settleAnswered(ctx);
348
389
  }
349
390
 
350
- /** A tool call of the turn of `ctx` (a `chat` handler's) ended: {@link publish} it, unless the agent runs in the background. */
351
- export async function toolCallEnded(ctx: restate.SessionContext) {
352
- await stepped(ctx);
391
+ /**
392
+ * Forget the call records (calls.ts) whose results the turn answering on
393
+ * `ctx` has stored ({@link answering}), if one does: after each commit of its
394
+ * steps (`answerOnce` does, before what the turn asked for then, such as a
395
+ * `chat` turn's publish, for every turn, in a `chat` turn or not), as a tool
396
+ * call starts, and as the turn ends.
397
+ */
398
+ export async function settleAnswered(ctx: restate.SessionContext) {
399
+ const stored = ANSWERING.get(ctx);
400
+ if (stored) await settled(ctx, stored);
353
401
  }
354
402
 
355
403
  /** Whether a tool call's result is stored: `stored(callId, failed)`, `failed` the error the call answered with. */
@@ -371,8 +419,9 @@ function settled(ctx: restate.SessionContext, stored: Stored): Promise<void> {
371
419
 
372
420
  /**
373
421
  * Run `work`, a framework's turn on the conversation of turns, forgetting
374
- * the calls whose results it stores as it goes: each publish while it runs
375
- * (a tool call's start and end), and its end, forget the Restate calls of
422
+ * the calls whose results it stores as it goes: each write of its steps
423
+ * that commits ({@link settleAnswered}), each tool call's start, and its
424
+ * end, forget the Restate calls of
376
425
  * the tool calls whose results `stored` says are stored (calls.ts).
377
426
  */
378
427
  export async function answering<T>(ctx: restate.SessionContext, stored: Stored, work: () => Promise<T>): Promise<T> {
@@ -403,14 +452,14 @@ export const aborted = (signal: AbortSignal) =>
403
452
  });
404
453
 
405
454
  /** A `chat` handler's answer to a message: a framework's prompt, say. */
406
- export type Chat<A = unknown> = (ctx: restate.SessionContext, message: string) => Promise<A>;
455
+ export type Chat<A = unknown> = (ctx: AgentContext, message: string) => Promise<A>;
407
456
 
408
457
  /**
409
458
  * Whether a `chat` handler's turns take steered messages: for every message,
410
459
  * or for each, as the invocation's context says (a framework's options that
411
460
  * a function gives, say).
412
461
  */
413
- export type Steers = boolean | ((ctx: restate.SessionContext) => boolean | Promise<boolean>);
462
+ export type Steers = boolean | ((ctx: AgentContext) => boolean | Promise<boolean>);
414
463
 
415
464
  /** What makes a `chat` handler (`chatHandler`): its answer, and whether it takes steered messages. */
416
465
  const CHAT = new Link<{ answer: Chat; steers: Steers }>('restate-agents.chat');
@@ -434,8 +483,9 @@ export const chatOf = (entry: object) => CHAT.of(entry);
434
483
  * attempt that ends first (`attemptCompletedSignal`) aborts it too, with an
435
484
  * {@link AttemptEnded}: the work stops, and the next attempt goes on with it.
436
485
  *
437
- * It publishes when it starts and ends ({@link publish}), for the clients
438
- * that follow the conversation.
486
+ * It publishes when it starts (its companion's `start` does) and ends
487
+ * ({@link publish}), for the clients that follow the conversation, unless
488
+ * the agent runs in the background, which publishes the end only.
439
489
  *
440
490
  * As the `chat` handler of an agent, it also answers each message sent to
441
491
  * the agent's `steer` view that no turn took, as a turn of its own (the
@@ -448,7 +498,7 @@ export const chatHandler = <A = string>(answer: Chat<A>, { steers = false }: { s
448
498
  input: messageSerde,
449
499
  accept: '*/*',
450
500
  explicitCancellation: true,
451
- handler: (ctx: restate.SessionContext, text: string): Promise<A> => chatTurn(ctx, text, answer, steers),
501
+ handler: (ctx: AgentContext, text: string): Promise<A> => chatTurn(ctx, text, answer, steers),
452
502
  },
453
503
  { answer, steers },
454
504
  );
@@ -460,7 +510,7 @@ export const chatHandler = <A = string>(answer: Chat<A>, { steers = false }: { s
460
510
  * in the background).
461
511
  */
462
512
  export async function chatTurn<A>(
463
- ctx: restate.SessionContext,
513
+ ctx: AgentContext,
464
514
  text: string,
465
515
  answer: Chat<A>,
466
516
  steers: Steers = false,
@@ -473,20 +523,28 @@ export async function chatTurn<A>(
473
523
  const steering = !unfollowed(ctx) && (typeof steers === 'function' ? await steers(ctx) : steers);
474
524
  // Before the first publish, which may answer messages steered to the turn already (a retried attempt's).
475
525
  if (steering) INBOX.set(ctx, new Inbox());
476
- await ctx.rpc(signals, signalsOf(ctx)).start({
526
+ // A followed turn's start is its first publish: the companion makes it, and returns what `publish` returns.
527
+ const followed = !unfollowed(ctx);
528
+ const companion = companionOfAgent(ctx, 'a chat turn');
529
+ const started = await companion.start({
477
530
  invocationId,
478
531
  since: new Date().toISOString(),
479
532
  ...(settles ? { settles } : {}),
480
533
  ...(steering ? { steers: steering } : {}),
534
+ ...(followed ? { publishes: true } : {}),
481
535
  });
482
- await stepped(ctx);
536
+ INBOX.get(ctx)?.saw(started);
537
+ // A followed turn publishes after each commit of its steps, for its
538
+ // followers to read them there: the conversation makes what the turn sets
539
+ // here (`afterStepsOf`), without knowing it publishes. A background turn
540
+ // publishes its end only.
541
+ if (followed) AFTER_STEPS.set(ctx, () => publish(ctx));
483
542
  // The log takes the turn's last change, then the companion closes the
484
543
  // turn, which publishes it: one revision. The close is a call the turn
485
544
  // waits for, so that it is done before the turn ends (see `awaitTurn`).
486
545
  const end = async () => {
487
- const stored = ANSWERING.get(ctx);
488
- if (stored) await settled(ctx, stored);
489
- await signalsOfAgent(ctx).close(invocationId);
546
+ await settleAnswered(ctx);
547
+ await companion.close(invocationId);
490
548
  };
491
549
  const turn = new AbortController();
492
550
  TURN.set(ctx, turn.signal);
@@ -517,6 +575,7 @@ export async function chatTurn<A>(
517
575
  } finally {
518
576
  // An attempt's signal aborts at every attempt's end, the turn's too.
519
577
  attempt.removeEventListener('abort', attemptEnded);
578
+ AFTER_STEPS.delete(ctx);
520
579
  }
521
580
  await end();
522
581
  return answered;