@restatedev/agents 0.7.0 → 0.8.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.
- package/README.md +29 -5
- package/dist/agentlib/agent.d.ts +32 -0
- package/dist/agentlib/agent.d.ts.map +1 -0
- package/dist/agentlib/agent.js +172 -0
- package/dist/agentlib/agent.js.map +1 -0
- package/dist/agentlib/index.d.ts +5 -0
- package/dist/agentlib/index.d.ts.map +1 -0
- package/dist/agentlib/index.js +15 -0
- package/dist/agentlib/index.js.map +1 -0
- package/dist/agentlib/messages.d.ts +39 -0
- package/dist/agentlib/messages.d.ts.map +1 -0
- package/dist/agentlib/messages.js +177 -0
- package/dist/agentlib/messages.js.map +1 -0
- package/dist/agentlib/model.d.ts +29 -0
- package/dist/agentlib/model.d.ts.map +1 -0
- package/dist/agentlib/model.js +131 -0
- package/dist/agentlib/model.js.map +1 -0
- package/dist/agentlib/options.d.ts +58 -0
- package/dist/agentlib/options.d.ts.map +1 -0
- package/dist/agentlib/options.js +2 -0
- package/dist/agentlib/options.js.map +1 -0
- package/dist/agentlib/runtime.d.ts +37 -0
- package/dist/agentlib/runtime.d.ts.map +1 -0
- package/dist/agentlib/runtime.js +216 -0
- package/dist/agentlib/runtime.js.map +1 -0
- package/dist/agentlib/state.d.ts +114 -0
- package/dist/agentlib/state.d.ts.map +1 -0
- package/dist/agentlib/state.js +52 -0
- package/dist/agentlib/state.js.map +1 -0
- package/dist/agentlib/steering.d.ts +23 -0
- package/dist/agentlib/steering.d.ts.map +1 -0
- package/dist/agentlib/steering.js +48 -0
- package/dist/agentlib/steering.js.map +1 -0
- package/dist/agentlib/tools.d.ts +33 -0
- package/dist/agentlib/tools.d.ts.map +1 -0
- package/dist/agentlib/tools.js +243 -0
- package/dist/agentlib/tools.js.map +1 -0
- package/dist/agentlib/turn.d.ts +82 -0
- package/dist/agentlib/turn.d.ts.map +1 -0
- package/dist/agentlib/turn.js +253 -0
- package/dist/agentlib/turn.js.map +1 -0
- package/dist/common.d.ts +8 -0
- package/dist/common.d.ts.map +1 -1
- package/dist/common.js +12 -0
- package/dist/common.js.map +1 -1
- package/dist/companion.d.ts +2 -1
- package/dist/companion.d.ts.map +1 -1
- package/dist/companion.js.map +1 -1
- package/dist/deepseek/index.d.ts +2 -6
- package/dist/deepseek/index.d.ts.map +1 -1
- package/dist/deepseek/index.js +3 -14
- package/dist/deepseek/index.js.map +1 -1
- package/dist/index.d.ts +5 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -4
- package/dist/index.js.map +1 -1
- package/dist/opencode/index.d.ts.map +1 -1
- package/dist/opencode/index.js +11 -18
- package/dist/opencode/index.js.map +1 -1
- package/dist/tools.d.ts +53 -2
- package/dist/tools.d.ts.map +1 -1
- package/dist/tools.js +32 -15
- package/dist/tools.js.map +1 -1
- package/package.json +28 -4
- package/src/agentlib/README.md +229 -0
- package/src/agentlib/agent.ts +214 -0
- package/src/agentlib/index.ts +16 -0
- package/src/agentlib/messages.ts +207 -0
- package/src/agentlib/model.ts +150 -0
- package/src/agentlib/options.ts +62 -0
- package/src/agentlib/runtime.ts +252 -0
- package/src/agentlib/state.ts +93 -0
- package/src/agentlib/steering.ts +53 -0
- package/src/agentlib/tools.ts +353 -0
- package/src/agentlib/turn.ts +302 -0
- package/src/common.ts +15 -0
- package/src/companion.ts +2 -1
- package/src/deepseek/index.ts +5 -18
- package/src/index.ts +6 -4
- package/src/opencode/index.ts +12 -17
- package/src/tools.ts +118 -52
package/dist/tools.js
CHANGED
|
@@ -16,12 +16,17 @@ import { stopSignalOf, configured, ToolError } from './common.js';
|
|
|
16
16
|
import { callOf } from './calls.js';
|
|
17
17
|
import { companionHere, NoCompanion } from './companion.js';
|
|
18
18
|
const TOOL = Symbol.for('restate-agents.tool');
|
|
19
|
+
const SPEC = Symbol.for('restate-agents.tool-spec');
|
|
20
|
+
/** `t`, saying what it does: see {@link ToolSpec}. */
|
|
21
|
+
const withSpec = (t, spec) => Object.defineProperty(t, SPEC, { value: spec });
|
|
22
|
+
/** What tool `t` does: see {@link ToolSpec}. */
|
|
23
|
+
export const specOf = (t) => t[SPEC];
|
|
19
24
|
/** The JSON schema of `t`'s input, which a framework offers the model. */
|
|
20
25
|
export const jsonSchemaOf = (t) => z.toJSONSchema(t.input);
|
|
21
26
|
/** Whether `value` is a {@link Tool}, rather than a framework's own. */
|
|
22
27
|
export const isTool = (value) => typeof value === 'object' && value !== null && TOOL in value;
|
|
23
28
|
/** A result as text: a string as it is, nothing as "done", anything else as JSON. */
|
|
24
|
-
const text = (value) => typeof value === 'string' ? value : value === null || value === undefined ? 'done' : JSON.stringify(value);
|
|
29
|
+
export const text = (value) => typeof value === 'string' ? value : value === null || value === undefined ? 'done' : JSON.stringify(value);
|
|
25
30
|
/**
|
|
26
31
|
* A tool, for any framework's agent:
|
|
27
32
|
*
|
|
@@ -39,7 +44,9 @@ const text = (value) => typeof value === 'string' ? value : value === null || va
|
|
|
39
44
|
* the model to act on; and so are arguments that do not fit `input`, which
|
|
40
45
|
* `run` never sees.
|
|
41
46
|
*/
|
|
42
|
-
export const tool = (options) => ({
|
|
47
|
+
export const tool = (options) => withSpec(ownTool(options), { kind: 'run', run: options.run });
|
|
48
|
+
/** {@link tool}, without its spec: Restate's tools give their own. */
|
|
49
|
+
const ownTool = (options) => ({
|
|
43
50
|
[TOOL]: true,
|
|
44
51
|
name: options.name,
|
|
45
52
|
description: options.description,
|
|
@@ -98,7 +105,7 @@ async function once(name, input, context, body, options) {
|
|
|
98
105
|
}
|
|
99
106
|
}
|
|
100
107
|
/** Whether a target is keyed: a virtual object (key) or a workflow (id). */
|
|
101
|
-
const keyed = (target) => 'object' in target || 'workflow' in target;
|
|
108
|
+
export const keyed = (target) => 'object' in target || 'workflow' in target;
|
|
102
109
|
/**
|
|
103
110
|
* Call `method` of `service`, with JSON in and out, once per tool call (see
|
|
104
111
|
* {@link ToolContext}): the call's idempotency key makes the call a new
|
|
@@ -155,7 +162,7 @@ async function split(target, options, all, ctx) {
|
|
|
155
162
|
*
|
|
156
163
|
* Of a virtual object, the model chooses the key, unless `key` gives it.
|
|
157
164
|
*/
|
|
158
|
-
export const call = (target, handler, options) =>
|
|
165
|
+
export const call = (target, handler, options) => withSpec(ownTool({
|
|
159
166
|
name: options.name ?? `${target.name}_${handler}`,
|
|
160
167
|
description: options.description,
|
|
161
168
|
input: inputOf(target, options),
|
|
@@ -165,21 +172,23 @@ export const call = (target, handler, options) => tool({
|
|
|
165
172
|
workflow: 'workflow' in target,
|
|
166
173
|
...(await split(target, options, input, c.ctx)),
|
|
167
174
|
})),
|
|
168
|
-
});
|
|
175
|
+
}), { kind: 'call', target: target, handler, options });
|
|
169
176
|
/**
|
|
170
177
|
* A tool that sends to `handler` of `target`, without waiting for it: a
|
|
171
178
|
* one-way call, made once, after `delay` if given (such as `{ minutes: 5 }`).
|
|
172
179
|
*/
|
|
173
|
-
export const send = (target, handler, options) =>
|
|
180
|
+
export const send = (target, handler, options) => withSpec(ownTool({
|
|
174
181
|
name: options.name ?? `${target.name}_${handler}`,
|
|
175
182
|
description: options.description,
|
|
176
183
|
input: inputOf(target, options),
|
|
177
184
|
run: async (input, context) => once(`${target.name}/${handler}`, input, context, async ({ ctx, idempotencyKey }) => {
|
|
178
185
|
const { key, parameter } = await split(target, options, input, ctx);
|
|
179
186
|
ctx.send({ service: target.name, handler, key, input: parameter, delay: options.delay, idempotencyKey });
|
|
180
|
-
return
|
|
187
|
+
return sentTo(target.name, key, handler);
|
|
181
188
|
}),
|
|
182
|
-
});
|
|
189
|
+
}), { kind: 'send', target: target, handler, options });
|
|
190
|
+
/** What a send tool answers: where it sent. */
|
|
191
|
+
export const sentTo = (service, key, handler) => `sent to ${service}${key === undefined ? '' : `/${key}`}/${handler}`;
|
|
183
192
|
/**
|
|
184
193
|
* A tool that runs the workflow `target` (its `run` handler) to the end, and
|
|
185
194
|
* answers with its result. Each tool call is a workflow of its own, with an
|
|
@@ -188,7 +197,7 @@ export const send = (target, handler, options) => tool({
|
|
|
188
197
|
* ran) waits for the run it started, and a `key` that ran before gets that
|
|
189
198
|
* run's result ({@link runWorkflow}).
|
|
190
199
|
*/
|
|
191
|
-
export const workflow = (target, options) =>
|
|
200
|
+
export const workflow = (target, options) => withSpec(ownTool({
|
|
192
201
|
name: options.name ?? target.name,
|
|
193
202
|
description: options.description,
|
|
194
203
|
input: z.object(options.input?.shape ?? {}),
|
|
@@ -197,11 +206,19 @@ export const workflow = (target, options) => tool({
|
|
|
197
206
|
key: options.key === undefined ? `${c.ctx.key}-${c.callId}` : await configured(options.key, c.ctx),
|
|
198
207
|
input: options.input ? input : undefined,
|
|
199
208
|
})),
|
|
200
|
-
});
|
|
209
|
+
}), { kind: 'workflow', target: target, options });
|
|
201
210
|
export function subagent(agent, { description = agent.description, name: toolName = agent.name, handler, } = {}) {
|
|
202
|
-
return
|
|
211
|
+
return withSpec(subagentTool(agent.name, toolName, description, handler ?? 'chat'), {
|
|
212
|
+
kind: 'subagent',
|
|
213
|
+
agent: agent.name,
|
|
214
|
+
handler: handler ?? 'chat',
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
/** {@link subagent}'s tool, without its spec. */
|
|
218
|
+
function subagentTool(agentName, toolName, description, handler) {
|
|
219
|
+
return ownTool({
|
|
203
220
|
name: toolName,
|
|
204
|
-
description: `Hand a task to the ${
|
|
221
|
+
description: `Hand a task to the ${agentName} agent${description ? ` (${description})` : ''}, and get its answer. ` +
|
|
205
222
|
'Tasks of different names run at once; the same name continues the same task.',
|
|
206
223
|
input: z.object({
|
|
207
224
|
name: z
|
|
@@ -210,7 +227,7 @@ export function subagent(agent, { description = agent.description, name: toolNam
|
|
|
210
227
|
.describe('A short name for the task, such as "fizzbuzz"'),
|
|
211
228
|
task: z.string().describe('The task in full: the agent sees nothing else'),
|
|
212
229
|
}),
|
|
213
|
-
run: async ({ name, task }, context) => once(
|
|
230
|
+
run: async ({ name, task }, context) => once(agentName, { name, task }, context, (c) => invoke(c, { service: agentName, key: `${c.ctx.key}.${name}`, method: handler, parameter: task })),
|
|
214
231
|
});
|
|
215
232
|
}
|
|
216
233
|
/**
|
|
@@ -236,12 +253,12 @@ export function subagent(agent, { description = agent.description, name: toolNam
|
|
|
236
253
|
* the signal is dropped then, unless it has `"keep": true`, which keeps it
|
|
237
254
|
* for the next wait for its name.
|
|
238
255
|
*/
|
|
239
|
-
export const signal = (name, options) =>
|
|
256
|
+
export const signal = (name, options) => withSpec(ownTool({
|
|
240
257
|
name: options.name ?? `wait_for_${name}`,
|
|
241
258
|
description: options.description,
|
|
242
259
|
input: z.object(options.input?.shape ?? {}),
|
|
243
260
|
run: async (input, context) => wait(context, name, input, { shown: options.input !== undefined }),
|
|
244
|
-
});
|
|
261
|
+
}), { kind: 'signal', name, shown: options.input !== undefined });
|
|
245
262
|
/**
|
|
246
263
|
* Wait for signal `name` as tool call `toolCall`, once however often it runs;
|
|
247
264
|
* `pending` shows `input` if `shown`. `rejoin` and `approval` are
|
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,yEAAyE;AACzE,2EAA2E;AAC3E,qEAAqE;AACrE,OAAO,KAAK,OAAO,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,+BAA+B,CAAC;AAC9D,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,aAAa,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAE5D,MAAM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E,EAAE,IAAI,EAAE,KAAK,IAAI,IAAI,EAAE,EAAE,KAAK,EAAE,KAAK,KAAK,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@restatedev/agents",
|
|
3
|
-
"version": "0.
|
|
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",
|
|
3
|
+
"version": "0.8.0",
|
|
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; and agentlib, journaled",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -19,6 +19,10 @@
|
|
|
19
19
|
"types": "./dist/index.d.ts",
|
|
20
20
|
"default": "./dist/index.js"
|
|
21
21
|
},
|
|
22
|
+
"./agentlib": {
|
|
23
|
+
"types": "./dist/agentlib/index.d.ts",
|
|
24
|
+
"default": "./dist/agentlib/index.js"
|
|
25
|
+
},
|
|
22
26
|
"./claude": {
|
|
23
27
|
"types": "./dist/claude/index.d.ts",
|
|
24
28
|
"default": "./dist/claude/index.js"
|
|
@@ -58,6 +62,8 @@
|
|
|
58
62
|
"@standard-schema/spec": "1.1.0"
|
|
59
63
|
},
|
|
60
64
|
"devDependencies": {
|
|
65
|
+
"@ai-sdk/anthropic": "4.0.14",
|
|
66
|
+
"@ai-sdk/openai": "4.0.13",
|
|
61
67
|
"@ai-sdk/provider": "3.0.8",
|
|
62
68
|
"@anthropic-ai/sdk": "1.8.0",
|
|
63
69
|
"@deepseek-ai/cordis": "4.1.0",
|
|
@@ -109,12 +115,16 @@
|
|
|
109
115
|
"@opencode/plugin": "2.2.7",
|
|
110
116
|
"@opencode/sdk": "2.2.7",
|
|
111
117
|
"@opencode/server": "2.2.7",
|
|
118
|
+
"@restatedev/agentlib": "0.1.0",
|
|
112
119
|
"@restatedev/restate-sdk": "1.18.2",
|
|
113
|
-
"@restatedev/
|
|
120
|
+
"@restatedev/restate-sdk-gen": "1.18.2",
|
|
121
|
+
"@restatedev/sessions": "0.8.0",
|
|
114
122
|
"effect": "4.1.0",
|
|
115
123
|
"zod": "4.6.7"
|
|
116
124
|
},
|
|
117
125
|
"peerDependencies": {
|
|
126
|
+
"@ai-sdk/anthropic": "^4.0.14",
|
|
127
|
+
"@ai-sdk/openai": "^4.0.13",
|
|
118
128
|
"@anthropic-ai/sdk": "^1.8.0",
|
|
119
129
|
"@deepseek-ai/cordis": "~4.1.0",
|
|
120
130
|
"@deepseek-ai/dsh-agent": "0.2.2-rc.2",
|
|
@@ -147,11 +157,19 @@
|
|
|
147
157
|
"@opencode/plugin": "2.2.7",
|
|
148
158
|
"@opencode/sdk": "2.2.7",
|
|
149
159
|
"@opencode/server": "2.2.7",
|
|
150
|
-
"@restatedev/
|
|
160
|
+
"@restatedev/agentlib": "~0.1.0",
|
|
161
|
+
"@restatedev/restate-sdk-gen": "1.18.2",
|
|
162
|
+
"@restatedev/sessions": "^0.8.0",
|
|
151
163
|
"effect": "4.1.0",
|
|
152
164
|
"zod": "^4.6.7"
|
|
153
165
|
},
|
|
154
166
|
"peerDependenciesMeta": {
|
|
167
|
+
"@ai-sdk/anthropic": {
|
|
168
|
+
"optional": true
|
|
169
|
+
},
|
|
170
|
+
"@ai-sdk/openai": {
|
|
171
|
+
"optional": true
|
|
172
|
+
},
|
|
155
173
|
"@anthropic-ai/sdk": {
|
|
156
174
|
"optional": true
|
|
157
175
|
},
|
|
@@ -248,6 +266,12 @@
|
|
|
248
266
|
"@opencode/server": {
|
|
249
267
|
"optional": true
|
|
250
268
|
},
|
|
269
|
+
"@restatedev/agentlib": {
|
|
270
|
+
"optional": true
|
|
271
|
+
},
|
|
272
|
+
"@restatedev/restate-sdk-gen": {
|
|
273
|
+
"optional": true
|
|
274
|
+
},
|
|
251
275
|
"effect": {
|
|
252
276
|
"optional": true
|
|
253
277
|
}
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
# agentlib
|
|
2
|
+
|
|
3
|
+
[agentlib](https://github.com/restatedev/agentlib) (`@restatedev/agentlib`)
|
|
4
|
+
is Restate's own agent library: an agent's loop as an operation of Restate's
|
|
5
|
+
generator SDK (`@restatedev/restate-sdk-gen`), with its tools, steering,
|
|
6
|
+
interruption, approvals, guardrails, compaction and limits. Restate journals
|
|
7
|
+
each model call and tool call it makes, and replays them.
|
|
8
|
+
|
|
9
|
+
Unlike the other frameworks here, an agentlib agent runs on the classic
|
|
10
|
+
Restate SDK, not in a session object: a virtual object whose `chat` handler
|
|
11
|
+
is journaled, and replayed after a crash, so that a model call or a tool
|
|
12
|
+
call that finished is not made again. Its conversation is in the object's
|
|
13
|
+
key/value state, not in a SQL database. It has the handlers and views of
|
|
14
|
+
every agent (`chat`, `messages`, `status`, `steer`, `stop`, `clear`, `sync`,
|
|
15
|
+
`signal`, `pending`, `notifications`, `watch`) and their companion, so that
|
|
16
|
+
a client (`@restatedev/agents/client`, `follow`) follows it as it follows
|
|
17
|
+
any other.
|
|
18
|
+
|
|
19
|
+
## Use
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
import { serve, tool } from '@restatedev/agents';
|
|
23
|
+
import * as agentlib from '@restatedev/agents/agentlib';
|
|
24
|
+
import { z } from 'zod';
|
|
25
|
+
|
|
26
|
+
const weather = tool({
|
|
27
|
+
name: 'get_weather',
|
|
28
|
+
description: 'The current weather in a city.',
|
|
29
|
+
input: z.object({ city: z.string() }),
|
|
30
|
+
run: ({ city }) => `Sunny and 21°C in ${city}`,
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
const assistant = agentlib.agent({
|
|
34
|
+
name: 'assistant',
|
|
35
|
+
system: 'Answer briefly.',
|
|
36
|
+
tools: [weather],
|
|
37
|
+
});
|
|
38
|
+
await serve(assistant);
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
The same `weather` works in an agent of any framework here; agentlib's own
|
|
42
|
+
tools work too, beside it.
|
|
43
|
+
|
|
44
|
+
See [`examples/basic/agentlib.ts`](../../../examples/basic/agentlib.ts),
|
|
45
|
+
with a transfer that waits for an approval.
|
|
46
|
+
|
|
47
|
+
```sh
|
|
48
|
+
npm install @restatedev/agents @restatedev/agentlib@0.1.0 @restatedev/restate-sdk-gen@1.18.2 \
|
|
49
|
+
@restatedev/restate-sdk@1.18.2 @ai-sdk/openai # or @ai-sdk/anthropic
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
| Option | What |
|
|
53
|
+
| ------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
54
|
+
| `model` | `openai/model-id` or `anthropic/model-id` (with `@ai-sdk/openai` or `@ai-sdk/anthropic`), or else `MODEL`, or else `openai/gpt-6-sol`; or a model of agentlib (`aiModel` of `@restatedev/agentlib/provider` for any provider of the AI SDK, `journaledModel` for one of your own) |
|
|
55
|
+
| `system` | The instructions (the system prompt): a text, or agentlib's function of the run's context that gives one |
|
|
56
|
+
| `tools` | The tools of `@restatedev/agents` (`tool()`, `call`, `send`, `workflow`, `signal`, `subagent`), as every agent takes them, and agentlib's own (`asyncTool`, `serviceTool`, `agentTool`, `handoff`, MCP's...) by the name the model calls them: `[weather, { transfer: asyncTool(...) }]` |
|
|
57
|
+
| `approval` | The tools of `@restatedev/agents` that wait for a person's approval before they run: their names, or a function of a call ([Approvals and signals](#approvals-and-signals)) |
|
|
58
|
+
| `history` | How the conversation the model gets stays short from turn to turn: `{ maxMessages, maxChars, retainMessages, model }`, or `false` ([A long conversation](#a-long-conversation)) |
|
|
59
|
+
| `output` | A zod schema: the answer as data, which `chat` answers with |
|
|
60
|
+
| `description` | What it is, for the UI, and for a parent's model: `subagent(agent)` tells it |
|
|
61
|
+
| `background` | It works unwatched (a subagent, say): its turn tells its companion at its end only, and takes no steered messages |
|
|
62
|
+
| `options` | Options of the object, beside the ones set here (its `retryPolicy`, as every agent's; its state preloads only `meta` and `taken`) |
|
|
63
|
+
|
|
64
|
+
Every other option of agentlib's `agent()` goes to it as it is:
|
|
65
|
+
`maxSteps`, `maxToolCalls`, `maxOutputTokens`, `compaction`,
|
|
66
|
+
`contextWindow`, `toolResults`, `skills`, `finalize`, and the guardrails
|
|
67
|
+
`beforeRun`, `beforeStep`, `beforeTool`, `afterTool` and `afterRun`.
|
|
68
|
+
|
|
69
|
+
## Tools
|
|
70
|
+
|
|
71
|
+
An agentlib agent takes the tools of `@restatedev/agents`, as every agent
|
|
72
|
+
does, and makes each agentlib's own, its calls the generator SDK's on the
|
|
73
|
+
classic SDK's context of its invocation:
|
|
74
|
+
|
|
75
|
+
| Tool | In an agentlib agent |
|
|
76
|
+
| ----------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
77
|
+
| `call(target, handler, …)` | A call of the handler, by its typed definition (a session object's, an agent's, or any of the classic SDK's): journaled, so a crash replays its answer; stopping the turn cancels it |
|
|
78
|
+
| `send(target, handler, …)` | A send, journaled: made once |
|
|
79
|
+
| `workflow(target, …)` | A run of the workflow, to its end: a workflow of its own per tool call, unless `key` gives its id; stopping the turn cancels it |
|
|
80
|
+
| `signal(name, …)` | A wait for the signal, which `pending` lists and `signal` resolves |
|
|
81
|
+
| `subagent(agent)` | A task for an agent of any framework (a pi agent, another agentlib agent...), at its key `<this key>.<task name>`: the same name continues the task; stopping the turn stops the sub-agent's turn |
|
|
82
|
+
| `tool({ name, description, input, run })` | `run`, as a journaled step (agentlib's `asyncTool` is one too): a crash replays its result, and an error that is no terminal error fails the attempt, which Restate retries |
|
|
83
|
+
|
|
84
|
+
As in every agent, arguments that do not fit a tool's `input` are the
|
|
85
|
+
model's to fix, and a terminal error (the tool's own, or a handler's it
|
|
86
|
+
calls) is the tool's answer, which the model sees. A `tool()`'s `run` gets
|
|
87
|
+
`ctx.key` and `ctx.request`, its `callId` and `idempotencyKey`, but no
|
|
88
|
+
`ctx.db` (an agentlib agent has no SQL database) and no `ctx.rpc` or
|
|
89
|
+
`ctx.send`: its calls are Restate's tools above, or agentlib's own. A
|
|
90
|
+
`tool()` that reaches for them fails the turn, saying so. A `key` given
|
|
91
|
+
as a function gets that context too, as a journaled step.
|
|
92
|
+
|
|
93
|
+
An agent of another framework hands an agentlib agent a task with
|
|
94
|
+
`subagent(assistant)`, as any agent; `deliver` and `webhook` send it
|
|
95
|
+
messages as they send any agent's.
|
|
96
|
+
|
|
97
|
+
agentlib's own `serviceTool`, and the generator SDK's typed `client`, take
|
|
98
|
+
the generator SDK's descriptors (`iface`, `service`, `object`), which a
|
|
99
|
+
definition of the classic SDK (a session object, an agent) is not: for
|
|
100
|
+
those, `call` and `subagent` above.
|
|
101
|
+
|
|
102
|
+
## Through crashes
|
|
103
|
+
|
|
104
|
+
A crash, a restart, a deployment or a suspension replays `chat`'s journal:
|
|
105
|
+
each model call (`aiModel` journals it, as a `run`) and each tool call that
|
|
106
|
+
finished returns what it returned, without being made again, and the run
|
|
107
|
+
goes on from where it got to. A tool's own I/O is journaled as agentlib
|
|
108
|
+
journals it (`asyncTool`'s `execute` is a `run`, with `callId` for an
|
|
109
|
+
idempotency key). [`e2e/agentlib.ts`](../../../e2e/agentlib.ts) kills the
|
|
110
|
+
service mid-turn and checks that the model was asked once per step.
|
|
111
|
+
|
|
112
|
+
agentlib saves a turn's messages when its run ends; until then, `messages`
|
|
113
|
+
shows the turn as it goes: its message, its tool calls with their results,
|
|
114
|
+
and the messages steered to it. Once the turn ends, its messages are as the
|
|
115
|
+
run saved them (the model's text beside its tool calls, and its answer,
|
|
116
|
+
come then), under the same ids.
|
|
117
|
+
|
|
118
|
+
## Approvals and signals
|
|
119
|
+
|
|
120
|
+
`approval` names the tools of `@restatedev/agents` whose calls wait for a
|
|
121
|
+
person's approval before they run (or is a function of a call, `{ name,
|
|
122
|
+
args }`, that says whether it does), as the DeepSeek Harness's option does:
|
|
123
|
+
|
|
124
|
+
```ts
|
|
125
|
+
agentlib.agent({ name: 'assistant', tools: [weather, transfer], approval: ['transfer'] });
|
|
126
|
+
```
|
|
127
|
+
|
|
128
|
+
Such a call waits for the signal `approval`, as do agentlib's own tools
|
|
129
|
+
with `needsApproval`, its `humanApprovalTool`, and a tool's
|
|
130
|
+
`context.approve`: `pending` lists the wait, with the tool and its input,
|
|
131
|
+
and `signal` approves it (`true`, `{"approved": true}`, or a text such as
|
|
132
|
+
`approved`, `yes` or `ok`) or denies it (anything else), and the model is
|
|
133
|
+
told it was denied.
|
|
134
|
+
|
|
135
|
+
```sh
|
|
136
|
+
curl localhost:8080/assistant/alice/pending
|
|
137
|
+
# [{"id": "inv_1f…:assistant:approval:call_01:0", "name": "approval", "input": {"tool": "transfer", "input": {"to": "Bob", "euros": 50}}, "since": "…"}]
|
|
138
|
+
curl localhost:8080/assistant/alice/signal --json '{"name": "approval", "value": "approved"}'
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
## Steering and stopping
|
|
142
|
+
|
|
143
|
+
A message sent to `steer` while a turn runs reaches the run as agentlib's
|
|
144
|
+
steering (`controls.steering`) at the turn's next publish (a tool call's
|
|
145
|
+
start or end): agentlib places it after the current round of tool calls,
|
|
146
|
+
and the model answers it in the same turn. One that comes too late (the
|
|
147
|
+
model writes its final answer) is answered as a turn of its own, after the
|
|
148
|
+
turn. `stop` cancels the turn's invocation, as for every agent: the run
|
|
149
|
+
ends cancelled, with its open tool calls, and the next turn's model sees
|
|
150
|
+
the turn's message, the messages steered to it that it took, and that it
|
|
151
|
+
ended `Cancelled: …` (not its tool calls, whose results may be missing).
|
|
152
|
+
|
|
153
|
+
## Models
|
|
154
|
+
|
|
155
|
+
`openai/…` and `anthropic/…` are agentlib's `aiModel` on the AI SDK's
|
|
156
|
+
provider (`@ai-sdk/openai`, on OpenAI's Responses API, and
|
|
157
|
+
`@ai-sdk/anthropic`), loaded when the first message comes. Any other
|
|
158
|
+
provider of the AI SDK works as a model you give:
|
|
159
|
+
|
|
160
|
+
```ts
|
|
161
|
+
import { aiModel } from '@restatedev/agentlib/provider';
|
|
162
|
+
import { google } from '@ai-sdk/google';
|
|
163
|
+
|
|
164
|
+
agentlib.agent({ name: 'assistant', model: aiModel({ model: google('<model-id>') }) });
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
A provider's refusal that a retry does not change (a missing or wrong API
|
|
168
|
+
key, an unknown model, a request it rejects: an answer 4xx) ends the message
|
|
169
|
+
with HTTP 424, as for every agent, and the conversation shows it unanswered.
|
|
170
|
+
Any other failure of a model by name (an outage, a rate limit) fails the attempt, and Restate retries it, as
|
|
171
|
+
for every agent: the model has no retry limit of its own. A model you give
|
|
172
|
+
retries as you set it (`aiModel`'s `retry`; agentlib's default is 3
|
|
173
|
+
attempts, then the message fails, `Failed: …`). agentlib 0.1.0 asks
|
|
174
|
+
Anthropic for strict tools, which it refuses with bounded numbers (agentlib's
|
|
175
|
+
own `read_tool_result` has them): an `anthropic/…` model is sent the tools'
|
|
176
|
+
schemas without their numbers' bounds, which the tools still check.
|
|
177
|
+
|
|
178
|
+
## A long conversation
|
|
179
|
+
|
|
180
|
+
The model gets the conversation as agentlib's `LazyStateConversation` keeps
|
|
181
|
+
it: at a turn's start, once its messages since the last summary pass 64
|
|
182
|
+
(or 64 000 characters), the earliest are summarized by the agent's model,
|
|
183
|
+
and the latest 12 stay as they are, from a message of the user's on. The
|
|
184
|
+
summary is kept, and the turns after build on it, so the model's input
|
|
185
|
+
stays bounded, and so does what each turn loads. `history` sets it:
|
|
186
|
+
|
|
187
|
+
```ts
|
|
188
|
+
agentlib.agent({
|
|
189
|
+
name: 'assistant',
|
|
190
|
+
history: { maxMessages: 200, maxChars: 200_000, retainMessages: 40 },
|
|
191
|
+
});
|
|
192
|
+
agentlib.agent({ name: 'assistant', history: false }); // the whole conversation, every turn
|
|
193
|
+
```
|
|
194
|
+
|
|
195
|
+
`history`'s `model` summarizes with another model than the agent's (a
|
|
196
|
+
cheaper one, say). `messages` keeps every turn as it was said, whatever
|
|
197
|
+
the model gets. Within a turn, agentlib's own `compaction` and
|
|
198
|
+
`contextWindow` keep a long run within the model's window.
|
|
199
|
+
|
|
200
|
+
## State
|
|
201
|
+
|
|
202
|
+
The conversation is in the object's state: the model's, in chunks of 32
|
|
203
|
+
(`t/<n>`) with its count and summary (`t/meta`), and the messages as
|
|
204
|
+
clients read them, one key each (`c/<id>`), beside `meta`. An invocation
|
|
205
|
+
starts with `meta`, `taken` and `t/meta` alone, and reads the rest as it
|
|
206
|
+
needs it: `messages`, a page; `chat`, the messages since the summary. Each
|
|
207
|
+
read is journaled with what it read, as any state read of a journaled
|
|
208
|
+
handler is: a turn's journal has the conversation it loaded.
|
|
209
|
+
|
|
210
|
+
## Not here
|
|
211
|
+
|
|
212
|
+
- **`window`, `budget`, `summarize`, `schema`** (the conversation of turns,
|
|
213
|
+
and tables of your own): there is no SQL database; `history` keeps a
|
|
214
|
+
long conversation short ([A long conversation](#a-long-conversation)).
|
|
215
|
+
- **`ctx.db`, `ctx.rpc` and `ctx.send` in a `tool()`**: see [Tools](#tools).
|
|
216
|
+
- **A killed turn** (out of retries, or killed by an operator) is closed by
|
|
217
|
+
the next message, `Ended: …`, not by the companion as it finds it gone.
|
|
218
|
+
|
|
219
|
+
## Packages
|
|
220
|
+
|
|
221
|
+
`@restatedev/agentlib` (0.1.x) and `@restatedev/restate-sdk-gen`
|
|
222
|
+
(1.18.2, the SDK @restatedev/sessions pins) are optional peer
|
|
223
|
+
dependencies, as are `@ai-sdk/openai` and `@ai-sdk/anthropic`. agentlib
|
|
224
|
+
runs on the copy of `@restatedev/restate-sdk` it finds, which must be
|
|
225
|
+
@restatedev/sessions' own (1.18.2): install `@restatedev/restate-sdk@1.18.2`
|
|
226
|
+
with it, as above, and npm installs one for all of them. On two copies (npm
|
|
227
|
+
puts a newer SDK beside sessions' own for agentlib, without it), an agent
|
|
228
|
+
refuses to start, saying so; `@restatedev/agents` asks for no SDK of its
|
|
229
|
+
own, so a project of another framework keeps whichever SDK it has.
|