@restatedev/agents 0.1.0 → 0.3.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 +25 -41
- package/dist/calls.d.ts +2 -5
- package/dist/calls.d.ts.map +1 -1
- package/dist/calls.js +3 -9
- package/dist/calls.js.map +1 -1
- package/dist/claude/index.d.ts +0 -1
- package/dist/claude/index.d.ts.map +1 -1
- package/dist/claude/index.js +15 -14
- package/dist/claude/index.js.map +1 -1
- package/dist/client.d.ts +2 -4
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js.map +1 -1
- package/dist/common.d.ts +25 -39
- package/dist/common.d.ts.map +1 -1
- package/dist/common.js +77 -105
- package/dist/common.js.map +1 -1
- package/dist/deepseek/index.d.ts +0 -1
- package/dist/deepseek/index.d.ts.map +1 -1
- package/dist/deepseek/index.js +8 -26
- package/dist/deepseek/index.js.map +1 -1
- package/dist/index.d.ts +3 -10
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -28
- package/dist/index.js.map +1 -1
- package/dist/langgraph/index.d.ts +0 -1
- package/dist/langgraph/index.d.ts.map +1 -1
- package/dist/langgraph/index.js +11 -13
- package/dist/langgraph/index.js.map +1 -1
- package/dist/log.d.ts +2 -2
- package/dist/log.d.ts.map +1 -1
- package/dist/log.js +13 -12
- package/dist/log.js.map +1 -1
- package/dist/object.d.ts +7 -19
- package/dist/object.d.ts.map +1 -1
- package/dist/object.js +10 -24
- package/dist/object.js.map +1 -1
- package/dist/opencode/index.d.ts +0 -1
- package/dist/opencode/index.d.ts.map +1 -1
- package/dist/opencode/index.js +14 -42
- package/dist/opencode/index.js.map +1 -1
- package/dist/pi/index.d.ts +0 -1
- package/dist/pi/index.d.ts.map +1 -1
- package/dist/pi/index.js +8 -28
- package/dist/pi/index.js.map +1 -1
- package/dist/signals.d.ts +17 -60
- package/dist/signals.d.ts.map +1 -1
- package/dist/signals.js +93 -97
- package/dist/signals.js.map +1 -1
- package/dist/webhook.d.ts +2 -4
- package/dist/webhook.d.ts.map +1 -1
- package/dist/webhook.js +2 -4
- package/dist/webhook.js.map +1 -1
- package/package.json +3 -3
- package/src/calls.ts +6 -12
- package/src/claude/index.ts +15 -15
- package/src/client.ts +1 -4
- package/src/common.ts +88 -109
- package/src/deepseek/index.ts +6 -29
- package/src/index.ts +3 -39
- package/src/langgraph/index.ts +15 -16
- package/src/log.ts +14 -13
- package/src/object.ts +20 -43
- package/src/opencode/index.ts +13 -49
- package/src/pi/index.ts +7 -28
- package/src/signals.ts +98 -140
- package/src/webhook.ts +2 -4
package/README.md
CHANGED
|
@@ -15,6 +15,8 @@ once, and each tool call is made once.
|
|
|
15
15
|
- [Your own session object](#your-own-session-object)
|
|
16
16
|
- [Build your own](#build-your-own)
|
|
17
17
|
- [Words](#words)
|
|
18
|
+
- [Turn semantics](TURN-SEMANTICS.md): how a message is answered, retried,
|
|
19
|
+
stopped or killed, and what a client sees meanwhile
|
|
18
20
|
|
|
19
21
|
## Start here
|
|
20
22
|
|
|
@@ -53,9 +55,10 @@ curl localhost:8080/assistant/alice/messages # t
|
|
|
53
55
|
|
|
54
56
|
`assistant` is a virtual object: each key (`alice`, `bob`) is a
|
|
55
57
|
conversation of its own, with a database of its own, and answers one
|
|
56
|
-
message at a time. `serve`
|
|
57
|
-
`signals` object every agent uses (its
|
|
58
|
-
|
|
58
|
+
message at a time. `serve` (@restatedev/sessions' `restate.serve`) serves it
|
|
59
|
+
on PORT (default 9080), with the `signals` object every agent uses (its
|
|
60
|
+
waits, and what it is doing), which each agent brings with it; an endpoint
|
|
61
|
+
of your own (`restate.endpoint()`) binds `signals` too.
|
|
59
62
|
`RESTATE_SERVE_ONLY=triage,planner` serves only the services it names, so
|
|
60
63
|
that one program (or image) deploys in parts; `signals` too, in one of them
|
|
61
64
|
(`RESTATE_SERVE_ONLY=triage,planner,signals`): the agents reach it through
|
|
@@ -66,7 +69,7 @@ Restate, wherever it is.
|
|
|
66
69
|
The same agent runs on each of them: `agent({ name, ...options })`, with
|
|
67
70
|
the handler `chat` (a message in, the answer out), and the views
|
|
68
71
|
`messages` (the conversation so far), `status` (what it is doing), `stop`
|
|
69
|
-
|
|
72
|
+
(the message it answers), `clear` (forget it all), `sync`,
|
|
70
73
|
`notifications` and `watch` (to follow it), and `signal` and `pending`
|
|
71
74
|
([Signals](#signals)).
|
|
72
75
|
|
|
@@ -113,11 +116,11 @@ system prompt for Claude and LangGraph, and is added to the framework's own
|
|
|
113
116
|
|
|
114
117
|
Every agent takes these too, beside its framework's options:
|
|
115
118
|
|
|
116
|
-
| Option | What
|
|
117
|
-
| ------------- |
|
|
118
|
-
| `description` | What it is, for the UI, and for a parent's model: `subagent(agent)` tells it
|
|
119
|
-
| `background` | It works unwatched (a subagent, say): its turn tells its `signals` at its end only, not at each step, so a follower sees each turn once it ended
|
|
120
|
-
| `schema` | Tables of your own in its database ([Build your own](#build-your-own))
|
|
119
|
+
| Option | What |
|
|
120
|
+
| ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
121
|
+
| `description` | What it is, for the UI, and for a parent's model: `subagent(agent)` tells it |
|
|
122
|
+
| `background` | It works unwatched (a subagent, say): its turn tells its `signals` at its end only, not at each step, so a follower sees each turn once it ended |
|
|
123
|
+
| `schema` | Tables of your own in its database ([Build your own](#build-your-own)) |
|
|
121
124
|
|
|
122
125
|
## Calling an agent
|
|
123
126
|
|
|
@@ -130,7 +133,8 @@ curl localhost:8080/assistant/alice/chat -d 'Hi, I am Alice' # "Hello Alic
|
|
|
130
133
|
```
|
|
131
134
|
|
|
132
135
|
A key answers one message at a time: a message sent while another is
|
|
133
|
-
answered waits for it
|
|
136
|
+
answered waits for it ([turn semantics](TURN-SEMANTICS.md) spells out how a
|
|
137
|
+
turn starts, ends, and is retried). A message that fails for good answers with an error:
|
|
134
138
|
HTTP 424 if the model's provider refused it (a missing or wrong API key, an
|
|
135
139
|
unknown model), 500 otherwise. A refused message is over: the next message
|
|
136
140
|
is answered on its own, not after it.
|
|
@@ -175,32 +179,15 @@ An attempt that ends before its turn does, while its process lives on
|
|
|
175
179
|
work too, a model's request included: it can store nothing more, and the
|
|
176
180
|
next attempt goes on with the turn, which is not cancelled.
|
|
177
181
|
|
|
178
|
-
**
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
the invocation that answers the message (to attach to), and whether it
|
|
183
|
-
steers one:
|
|
184
|
-
|
|
185
|
-
```sh
|
|
186
|
-
curl localhost:8080/assistant/alice/steer -d 'Only Monday, please' # {"invocationId": "inv_1f…", "steered": true}
|
|
187
|
-
```
|
|
188
|
-
|
|
189
|
-
A turn that ends before it takes a message (no tool call came) answers it
|
|
190
|
-
as a message of its own, once it ended; with no message answered, `steer`
|
|
191
|
-
is a message of its own (`"steered": false`, and its invocation). Claude's
|
|
192
|
-
and LangGraph's turns take no steering: their messages are answered next.
|
|
193
|
-
A stopped turn answers none of them.
|
|
194
|
-
|
|
195
|
-
A steered message waits in the agent's `signals` object (`steer`), and the
|
|
196
|
-
turn reads it there after each tool call (`steering`), and gives it to the
|
|
197
|
-
framework by its id, which the framework keeps: a retried attempt neither
|
|
198
|
-
loses nor repeats one.
|
|
182
|
+
**A message while it works.** A message sent while the agent answers
|
|
183
|
+
another waits for it: Restate answers a key's messages one at a time, in
|
|
184
|
+
order. To change course, stop the turn (`stop`) and send the message that
|
|
185
|
+
replaces it.
|
|
199
186
|
|
|
200
187
|
**Forget a conversation.** `clear` starts a key over, such as for a UI's
|
|
201
188
|
New chat button: it stops the message being answered (as `stop`), then
|
|
202
189
|
forgets the conversation, the key's database, and what its
|
|
203
|
-
`signals` hold (waits
|
|
190
|
+
`signals` hold (waits and kept signals). It answers as `stop`
|
|
204
191
|
does. The next message starts anew; its ids and cursors go on from where
|
|
205
192
|
the forgotten conversation got to, so a follower (`follow`, `sync`) reads on,
|
|
206
193
|
and drops the messages it kept from before `first` (which a page and each
|
|
@@ -330,7 +317,6 @@ const sent = await restate
|
|
|
330
317
|
.objectSendClient(agent('assistant'), 'alice')
|
|
331
318
|
.chat('Plan my week', clients.rpc.sendOpts({ idempotencyKey: 'msg-1' }));
|
|
332
319
|
const { answering, waiting } = await alice.status(); // while it works
|
|
333
|
-
await alice.steer('Only Monday, please'); // typed while it works
|
|
334
320
|
await alice.stop(); // the Stop button
|
|
335
321
|
const { messages } = await alice.messages({ limit: 20 }); // the tool calls so far
|
|
336
322
|
const answer = await restate.result(sent); // once it answered
|
|
@@ -362,7 +348,7 @@ with their outputs.
|
|
|
362
348
|
(`Messages`, `Status`, `Waiting`...); `agent<H>(name)` types a session
|
|
363
349
|
object of your own with its handlers `H`.
|
|
364
350
|
[`examples/ui`](../examples/ui/app.ts) is a chat page on it: the
|
|
365
|
-
conversation as the agent works, its approvals
|
|
351
|
+
conversation as the agent works, its approvals and Stop.
|
|
366
352
|
|
|
367
353
|
## Tools
|
|
368
354
|
|
|
@@ -451,7 +437,7 @@ curl localhost:8080/support/alice/signal --json '{"id": "inv_1f…:toolu_01", "v
|
|
|
451
437
|
curl localhost:8080/support/alice/signal --json '{"name": "approval", "value": "approved", "keep": true}'
|
|
452
438
|
```
|
|
453
439
|
|
|
454
|
-
A wait ends with its agent's invocation: a cancelled one leaves `pending`.
|
|
440
|
+
A wait ends with its agent's invocation: a cancelled or killed one leaves `pending`.
|
|
455
441
|
The waits are kept by the `signals` object, keyed `<agent>:<key>`, which
|
|
456
442
|
`serve` serves beside the agents. See
|
|
457
443
|
[`examples/intermediate/support.ts`](../examples/intermediate/support.ts).
|
|
@@ -508,11 +494,9 @@ await serve(issues, triage);
|
|
|
508
494
|
| `message` | What of the body the agents read; by default, all of it |
|
|
509
495
|
| `description` | What it is, for the UI |
|
|
510
496
|
|
|
511
|
-
A delivery
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
that ends, or is stopped, before it takes it answers it after: a delivery is
|
|
515
|
-
never dropped, as a steer to a stopped turn is.
|
|
497
|
+
A delivery is a message of its own to the agent's `chat`, which it answers
|
|
498
|
+
after the message it works on, if any, also one that is stopped: a delivery
|
|
499
|
+
is never dropped.
|
|
516
500
|
|
|
517
501
|
The same delivery is yours from any handler (a session object's, or a
|
|
518
502
|
service's or workflow's of the SDK), for events of other kinds (a queue, a
|
|
@@ -633,7 +617,7 @@ journal in Restate's UI. Its `options` (such as `retryPolicy`) and
|
|
|
633
617
|
`metadata` add to these. It is a `restate.sessionObject` of
|
|
634
618
|
[`@restatedev/sessions`](../sessions/README.md): `handlers` run one at a time per
|
|
635
619
|
key, and `views` beside them. Its own cannot be named `signal`, `pending`,
|
|
636
|
-
`status`, `stop`, `
|
|
620
|
+
`status`, `stop`, `notifications` or `watch`, views every agent's
|
|
637
621
|
session object has, nor `sync`, `clear` or `erase`, which an agent has (one with a
|
|
638
622
|
`messages` view). A view of yours reads the database too: `ctx.db` is the
|
|
639
623
|
database as committed, beside a message being answered.
|
package/dist/calls.d.ts
CHANGED
|
@@ -1,13 +1,11 @@
|
|
|
1
1
|
import type * as restate from '@restatedev/sessions';
|
|
2
|
-
/** What the calls need of a handler's context. */
|
|
3
|
-
type CallsContext = Pick<restate.SessionContext, 'db' | 'request'>;
|
|
4
2
|
/**
|
|
5
3
|
* The call of tool `tool` with `input` that tool call `callId` makes: the
|
|
6
4
|
* one it made before (a run again), or the one an earlier attempt made with
|
|
7
5
|
* the same tool and input (made again under a new id), or else a new one.
|
|
8
6
|
* `run(id)` makes it with its own id, and stores that it answered.
|
|
9
7
|
*/
|
|
10
|
-
export declare function callOf(ctx:
|
|
8
|
+
export declare function callOf(ctx: restate.SessionContext, tool: string, input: unknown, callId: string): Promise<{
|
|
11
9
|
id: string;
|
|
12
10
|
/**
|
|
13
11
|
* It answered, with `failed` if a terminal error answered it: kept until
|
|
@@ -24,6 +22,5 @@ export declare function callOf(ctx: CallsContext, tool: string, input: unknown,
|
|
|
24
22
|
* otherwise take one an earlier attempt made, and the model has the result
|
|
25
23
|
* of.
|
|
26
24
|
*/
|
|
27
|
-
export declare function settle(ctx:
|
|
28
|
-
export {};
|
|
25
|
+
export declare function settle(ctx: restate.SessionContext, stored: (id: string, failed?: string) => boolean): Promise<void>;
|
|
29
26
|
//# sourceMappingURL=calls.d.ts.map
|
package/dist/calls.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"calls.d.ts","sourceRoot":"","sources":["../src/calls.ts"],"names":[],"mappings":"AAoBA,OAAO,KAAK,KAAK,OAAO,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"calls.d.ts","sourceRoot":"","sources":["../src/calls.ts"],"names":[],"mappings":"AAoBA,OAAO,KAAK,KAAK,OAAO,MAAM,sBAAsB,CAAC;AA6DrD;;;;;GAKG;AACH,wBAAsB,MAAM,CAAC,GAAG,EAAE,OAAO,CAAC,cAAc,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM;;IAiBlG;;;OAGG;sBACqB,MAAM;GAMjC;AAED;;;;;;;;GAQG;AACH,wBAAsB,MAAM,CAAC,GAAG,EAAE,OAAO,CAAC,cAAc,EAAE,MAAM,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,KAAK,OAAO,iBAMzG"}
|
package/dist/calls.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Schema } from '@restatedev/sessions/internal';
|
|
1
|
+
import { Schema, ScopeKey } from '@restatedev/sessions/internal';
|
|
2
2
|
import { randomUUID } from 'node:crypto';
|
|
3
3
|
/** The table of the {@link Calls}: one row, of the invocation whose calls they are. */
|
|
4
4
|
const SCHEMA = new Schema('restate-agents.calls', [
|
|
@@ -24,16 +24,10 @@ async function load(ctx, invocation) {
|
|
|
24
24
|
: { invocation, calls: [] };
|
|
25
25
|
}
|
|
26
26
|
/** Each attempt's id, and its calls, by its context. */
|
|
27
|
-
const
|
|
27
|
+
const ATTEMPT = new ScopeKey('the calls of an attempt');
|
|
28
28
|
/** The attempt of `ctx`: its id, and the calls of its invocation. */
|
|
29
29
|
function attemptOf(ctx) {
|
|
30
|
-
|
|
31
|
-
if (!attempt) {
|
|
32
|
-
const calls = load(ctx, ctx.request.id);
|
|
33
|
-
attempt = { id: randomUUID(), calls };
|
|
34
|
-
attempts.set(ctx, attempt);
|
|
35
|
-
}
|
|
36
|
-
return attempt;
|
|
30
|
+
return ATTEMPT.of(ctx, () => ({ id: randomUUID(), calls: load(ctx, ctx.request.id) }));
|
|
37
31
|
}
|
|
38
32
|
/**
|
|
39
33
|
* The call of tool `tool` with `input` that tool call `callId` makes: the
|
package/dist/calls.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"calls.js","sourceRoot":"","sources":["../src/calls.ts"],"names":[],"mappings":"AAqBA,OAAO,EAAE,MAAM,EAAE,MAAM,+BAA+B,CAAC;
|
|
1
|
+
{"version":3,"file":"calls.js","sourceRoot":"","sources":["../src/calls.ts"],"names":[],"mappings":"AAqBA,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,+BAA+B,CAAC;AACjE,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAoBzC,uFAAuF;AACvF,MAAM,MAAM,GAAG,IAAI,MAAM,CAAC,sBAAsB,EAAE;IAChD;;;;IAIE;CACH,CAAC,CAAC;AAKH,oEAAoE;AACpE,KAAK,UAAU,KAAK,CAAC,GAAiB,EAAE,EAAE,UAAU,EAAE,KAAK,EAAS;IAClE,MAAM,GAAG,CAAC,EAAE,CAAC,OAAO,CAAC,sFAAsF,EAAE;QAC3G,UAAU;QACV,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC;KACtB,CAAC,CAAC;AACL,CAAC;AAED,qFAAqF;AACrF,KAAK,UAAU,IAAI,CAAC,GAAiB,EAAE,UAAkB;IACvD,MAAM,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IAC5B,MAAM,GAAG,GAAG,MAAM,GAAG,CAAC,EAAE,CAAC,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IAAI,IAAI,CAAC,MAAM,KAAK,KAAK,CAAC,KAAK,CAAC,MAAM;QAAE,OAAO;IAC/C,KAAK,CAAC,KAAK,GAAG,IAAI,CAAC;IACnB,MAAM,KAAK,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;AAC1B,CAAC"}
|
package/dist/claude/index.d.ts
CHANGED
|
@@ -64,7 +64,6 @@ export declare const agent: <P extends string, O extends z.ZodObject | undefined
|
|
|
64
64
|
pending: (ctx: restate.ViewContext) => Promise<import("../signals.ts").Waiting[]>;
|
|
65
65
|
status: (ctx: restate.ViewContext) => Promise<import("../object.ts").Status>;
|
|
66
66
|
stop: (ctx: restate.ViewContext) => Promise<import("../object.ts").Stopped>;
|
|
67
|
-
steer: (ctx: restate.ViewContext, text: string) => Promise<import("../signals.ts").Steered>;
|
|
68
67
|
notifications: (ctx: restate.ViewContext) => Promise<import("../signals.ts").Notifications>;
|
|
69
68
|
watch: (ctx: restate.ViewContext, watch: import("../signals.ts").Watch) => Promise<import("../signals.ts").Notifications>;
|
|
70
69
|
} & {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/claude/index.ts"],"names":[],"mappings":"AAyBA,OAAO,KAAK,OAAO,MAAM,sBAAsB,CAAC;AAEhD,OAAO,SAAS,MAAM,mBAAmB,CAAC;AAC1C,OAAO,KAAK,EAAE,gBAAgB,EAAE,kBAAkB,EAAE,MAAM,8CAA8C,CAAC;AACzG,OAAO,EAML,KAAK,SAAS,EAef,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,KAAK,MAAM,EAAc,MAAM,cAAc,CAAC;AACvD,OAAO,KAAK,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAC7B,OAAO,EAAE,KAAK,UAAU,EAAiB,MAAM,cAAc,CAAC;AAC9D,OAAO,EAAwB,KAAK,IAAI,IAAI,OAAO,EAAE,MAAM,aAAa,CAAC;AAGzE,4EAA4E;AAC5E,eAAO,MAAM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,MAAM,CAAC,EAAE,CAAC,CAAC;CACZ;AAqED;;;;;GAKG;AACH,eAAO,MAAM,MAAM,GAAI,CAAC,SAAS,CAAC,CAAC,SAAS,GAAG,SAAS,GAAG,SAAS,OAC7D,OAAO,CAAC,cAAc,QACrB,MAAM,YACH,OAAO,CAAC,CAAC,CAAC,KAClB,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,CAAqF,CAAC;AAE1G;;;;;GAKG;AACH,eAAO,MAAM,IAAI,GAAI,CAAC,SAAS,CAAC,CAAC,SAAS,GAAG,SAAS,GAAG,SAAS,YAAW,SAAS,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;;;;;CAGjG,CAAC;AAMF;;;;GAIG;AACH,eAAO,MAAM,QAAQ,gIAA0B,CAAC;AA4BhD,6HAA6H;AAC7H,eAAO,MAAM,KAAK,GAAI,CAAC,SAAS,MAAM,EAAE,CAAC,SAAS,CAAC,CAAC,SAAS,GAAG,SAAS,GAAG,SAAS,yDAMlF,OAAO,CAAC,CAAC,CAAC,GAAG,UAAU,CAAC,CAAC,CAAC;;;;;;;;;;;;;;EAQzB,CAAC"}
|
package/dist/claude/index.js
CHANGED
|
@@ -24,8 +24,9 @@
|
|
|
24
24
|
// - A reply cut off at `maxTokens`, or declined, ends the prompt: its tool
|
|
25
25
|
// calls do not run, and the handler fails with a terminal error.
|
|
26
26
|
import * as restate from '@restatedev/sessions';
|
|
27
|
+
import { ScopeKey } from '@restatedev/sessions/internal';
|
|
27
28
|
import Anthropic from '@anthropic-ai/sdk';
|
|
28
|
-
import { aborted, AttemptEnded, CANCELLED, chatHandler, CLAUDE_MODEL, configured, fromTool, messagesHandler, modelIdOf, modelOf, nextPromptId,
|
|
29
|
+
import { aborted, AttemptEnded, CANCELLED, chatHandler, CLAUDE_MODEL, configured, fromTool, messagesHandler, modelIdOf, modelOf, nextPromptId, refusalOf, stopSignalOf, storedAnswer, toolCallEnded, toolCallStarted, transcribing, Transcript, UNANSWERED, } from '../common.js';
|
|
29
30
|
import { withOutput } from '../output.js';
|
|
30
31
|
import { sessionObject } from '../object.js';
|
|
31
32
|
import { isTool, jsonSchemaOf } from '../tools.js';
|
|
@@ -41,7 +42,7 @@ export const callId = (context) => {
|
|
|
41
42
|
* to the model as the tool's result, so each one is kept, for `check()` to
|
|
42
43
|
* throw once the tools ran.
|
|
43
44
|
*/
|
|
44
|
-
function failing(tools) {
|
|
45
|
+
function failing(ctx, tools) {
|
|
45
46
|
let failure;
|
|
46
47
|
return {
|
|
47
48
|
tools: tools.map((tool) => ({
|
|
@@ -51,7 +52,7 @@ function failing(tools) {
|
|
|
51
52
|
return await tool.run(args, context);
|
|
52
53
|
}
|
|
53
54
|
catch (e) {
|
|
54
|
-
fromTool(e);
|
|
55
|
+
fromTool(ctx, e);
|
|
55
56
|
failure ??= e;
|
|
56
57
|
throw e;
|
|
57
58
|
}
|
|
@@ -73,7 +74,7 @@ const textOf = (content) => content
|
|
|
73
74
|
* the clients that follow the conversation).
|
|
74
75
|
*/
|
|
75
76
|
async function run(ctx, { client, model, maxTokens, effort, system, tools: all }, conversation, id, signal) {
|
|
76
|
-
const { tools, check } = failing(all);
|
|
77
|
+
const { tools, check } = failing(ctx, all);
|
|
77
78
|
const runner = client.beta.messages.toolRunner({
|
|
78
79
|
model,
|
|
79
80
|
max_tokens: maxTokens,
|
|
@@ -146,13 +147,13 @@ const native = (t, ctx) => ({
|
|
|
146
147
|
parse: (args) => args,
|
|
147
148
|
run: (args, context) => t.run(args, { ctx, callId: callId(context) }),
|
|
148
149
|
});
|
|
149
|
-
/** The client of
|
|
150
|
-
|
|
150
|
+
/** The client of an agent without one of its own, on the context of the turn it answers. */
|
|
151
|
+
const CLIENT = new ScopeKey('the Anthropic client');
|
|
151
152
|
/** {@link prompt}, answering with the agent's text. */
|
|
152
|
-
const promptText = (ctx, text, options) => transcribing(ctx, () => transcribe(ctx
|
|
153
|
+
const promptText = (ctx, text, options) => transcribing(ctx, () => transcribe(ctx), () => answerOnce(ctx, text, options));
|
|
153
154
|
const answerOnce = async (ctx, text, { model: named, system, tools = [], client, maxTokens = 16_000, effort }) => {
|
|
154
155
|
const agent = {
|
|
155
|
-
client: client ?? (
|
|
156
|
+
client: client ?? CLIENT.of(ctx, () => new Anthropic()),
|
|
156
157
|
model: modelIdOf(modelOf(named, CLAUDE_MODEL), 'anthropic'),
|
|
157
158
|
maxTokens,
|
|
158
159
|
effort,
|
|
@@ -195,7 +196,7 @@ const answerOnce = async (ctx, text, { model: named, system, tools = [], client,
|
|
|
195
196
|
}
|
|
196
197
|
// Refused for good (a wrong API key): the prompt ends unanswered, and
|
|
197
198
|
// fails as terminal. An earlier one's, this one goes on.
|
|
198
|
-
const refused =
|
|
199
|
+
const refused = refusalOf(ctx, error);
|
|
199
200
|
if (!refused)
|
|
200
201
|
throw error;
|
|
201
202
|
await conversation.close(pending, UNANSWERED);
|
|
@@ -235,11 +236,11 @@ export const messages = () => messagesHandler();
|
|
|
235
236
|
* attempt), as far as it was read: the conversation only grows, so each
|
|
236
237
|
* read adds the messages stored since.
|
|
237
238
|
*/
|
|
238
|
-
const
|
|
239
|
-
/** The conversation in `
|
|
240
|
-
const transcribe = async (
|
|
241
|
-
const
|
|
242
|
-
|
|
239
|
+
const TRANSCRIPT = new ScopeKey('the transcript');
|
|
240
|
+
/** The conversation in the database of `ctx`, as `messages` gives it. */
|
|
241
|
+
const transcribe = async (ctx) => {
|
|
242
|
+
const { db } = ctx;
|
|
243
|
+
const read = TRANSCRIPT.of(ctx, () => ({ seq: 0, transcript: new Transcript() }));
|
|
243
244
|
const { transcript } = read;
|
|
244
245
|
for (const [seq, m] of await (await Conversation.open(db)).since(read.seq)) {
|
|
245
246
|
read.seq = seq;
|
package/dist/claude/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/claude/index.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,4EAA4E;AAC5E,2CAA2C;AAC3C,EAAE;A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AI,CAAC,CAAC;QAC7F,CAAC;IACH,CAAC;IACD,OAAO,UAAU,CAAC;AACpB,CAAC,CAAC;AAEF,6HAA6H;AAC7H,MAAM,CAAC,MAAM,KAAK,GAAG,CAAkE,EACrF,IAAI,EACJ,WAAW,EACX,MAAM,EACN,UAAU,EACV,GAAG,OAAO,EACiB,EAAE,EAAE,CAC/B,aAAa,CAAC;IACZ,IAAI;IACJ,WAAW;IACX,MAAM;IACN,UAAU;IACV,QAAQ,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,EAAE;IACjC,KAAK,EAAE,EAAE,QAAQ,EAAE,QAAQ,EAAE,EAAE;CAChC,CAAC,CAAC"}
|
package/dist/client.d.ts
CHANGED
|
@@ -2,8 +2,8 @@ import * as clients from '@restatedev/restate-sdk-clients';
|
|
|
2
2
|
import type { VirtualObjectDefinition } from '@restatedev/restate-sdk-core';
|
|
3
3
|
import type { ChatMessage, Messages, MessagesRequest, Part, Turn } from './common.ts';
|
|
4
4
|
import type { Status, Stopped, Synced, SyncRequest } from './object.ts';
|
|
5
|
-
import type { Notifications, Resolved, Signal,
|
|
6
|
-
export type { ChatMessage, Messages, MessagesRequest, Notifications, Part, Resolved, Signal, Status,
|
|
5
|
+
import type { Notifications, Resolved, Signal, Waiting, Watch } from './signals.ts';
|
|
6
|
+
export type { ChatMessage, Messages, MessagesRequest, Notifications, Part, Resolved, Signal, Status, Stopped, Synced, SyncRequest, Turn, Waiting, Watch, };
|
|
7
7
|
/** The handlers of an agent (`agent()` of any framework), as Restate's client calls them. */
|
|
8
8
|
export interface Agent {
|
|
9
9
|
/** Answer `message`. */
|
|
@@ -18,8 +18,6 @@ export interface Agent {
|
|
|
18
18
|
stop(ctx: unknown): Promise<Stopped>;
|
|
19
19
|
/** Forget the conversation (stopping the message it answers): its database and state too. */
|
|
20
20
|
clear(ctx: unknown): Promise<Stopped>;
|
|
21
|
-
/** Add `message` to the message it answers, at its next tool call (or answer it as a message of its own). */
|
|
22
|
-
steer(ctx: unknown, message: string): Promise<Steered>;
|
|
23
21
|
/** What its tools wait for. */
|
|
24
22
|
pending(ctx: unknown): Promise<Waiting[]>;
|
|
25
23
|
/** Resolve a wait: by its id, or the oldest for a name. */
|
package/dist/client.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,OAAO,MAAM,iCAAiC,CAAC;AAC3D,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AAC5E,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,eAAe,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AACtF,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACxE,OAAO,KAAK,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"client.d.ts","sourceRoot":"","sources":["../src/client.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,OAAO,MAAM,iCAAiC,CAAC;AAC3D,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,8BAA8B,CAAC;AAC5E,OAAO,KAAK,EAAE,WAAW,EAAE,QAAQ,EAAE,eAAe,EAAE,IAAI,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AACtF,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AACxE,OAAO,KAAK,EAAE,aAAa,EAAE,QAAQ,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,cAAc,CAAC;AAEpF,YAAY,EACV,WAAW,EACX,QAAQ,EACR,eAAe,EACf,aAAa,EACb,IAAI,EACJ,QAAQ,EACR,MAAM,EACN,MAAM,EACN,OAAO,EACP,MAA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gBACrB,QAAQ,EAAE,MAAM,CAAC,QAAQ;gBACzB,KAAK,EAAE,MAAM,CAAC,KAAK,IAAI,CAAC;gBACxB,MAAM,EAAE,MAAM,CAAC,MAAM;gBACrB,OAAO,EAAE,MAAM,CAAC,MAAM,CAAC,OAAO;aAC/B,CAAC;QACJ,CAAC;QACD,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC;QACvB,2DAA2D;QAC3D,QAAQ,GAAG,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC;IACvD,CAAC;AACH,CAAC"}
|
package/dist/common.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import * as restate from '@restatedev/sessions';
|
|
2
2
|
import type { Said } from './log.ts';
|
|
3
|
-
import { type Steer } from './signals.ts';
|
|
4
3
|
/**
|
|
5
4
|
* A value, or a function of the invocation's context that gives it: the
|
|
6
5
|
* same for every message, or each user's (from the object's database, say).
|
|
@@ -88,25 +87,24 @@ export declare class AttemptEnded extends Error {
|
|
|
88
87
|
* {@link AttemptEnded} once the attempt ends first (the work stops, and
|
|
89
88
|
* answers nothing).
|
|
90
89
|
*/
|
|
91
|
-
export declare const stopSignalOf: (ctx:
|
|
92
|
-
/**
|
|
93
|
-
|
|
94
|
-
/** Give it `message`, for its next step: once, by the message's id, however often it is given. */
|
|
95
|
-
steer(message: Steer): Promise<void>;
|
|
96
|
-
/** Whether it has message `id`: given in this attempt, or an earlier one. */
|
|
97
|
-
has(id: string): Promise<boolean>;
|
|
98
|
-
}
|
|
99
|
-
/** Agent `name` runs in the background: see `background` in object.ts. */
|
|
100
|
-
export declare const inBackground: (name: string) => undefined;
|
|
90
|
+
export declare const stopSignalOf: (ctx: restate.SessionContext) => AbortSignal | undefined;
|
|
91
|
+
/** What `clear` also empties, beside the agent's database. */
|
|
92
|
+
type Clear = (ctx: restate.SessionContext) => Promise<void>;
|
|
101
93
|
/**
|
|
102
94
|
* The `messages` view `view` of a framework that keeps a conversation apart
|
|
103
95
|
* (OpenCode, in a database of its own): `clear` empties it too, as an agent
|
|
104
96
|
* with this view is cleared.
|
|
105
97
|
*/
|
|
106
|
-
export declare const alsoClearing: <V extends object>(view: V, clear:
|
|
107
|
-
/**
|
|
108
|
-
|
|
109
|
-
|
|
98
|
+
export declare const alsoClearing: <V extends object>(view: V, clear: Clear) => V;
|
|
99
|
+
/**
|
|
100
|
+
* `definition` is an agent's: whether it runs in the background, and its
|
|
101
|
+
* `messages` view, whose clearing (`alsoClearing`) its `clear` does too.
|
|
102
|
+
*/
|
|
103
|
+
export declare const isAgent: <D extends object>(definition: D, { background, messages }: {
|
|
104
|
+
background?: boolean | undefined;
|
|
105
|
+
messages?: object | undefined;
|
|
106
|
+
}) => D;
|
|
107
|
+
/** Clear what the agent of `ctx` keeps beside its database. */
|
|
110
108
|
export declare const cleared: (ctx: restate.SessionContext) => Promise<void | undefined>;
|
|
111
109
|
/**
|
|
112
110
|
* A tool call of the turn of `ctx` starts: {@link publish} it, which forgets
|
|
@@ -115,20 +113,8 @@ export declare const cleared: (ctx: restate.SessionContext) => Promise<void | un
|
|
|
115
113
|
* them alone.
|
|
116
114
|
*/
|
|
117
115
|
export declare function toolCallStarted(ctx: restate.SessionContext): Promise<void>;
|
|
118
|
-
/**
|
|
119
|
-
|
|
120
|
-
* it, and give `conversation` the messages steered to the turn since, which it
|
|
121
|
-
* does not have yet: its next step takes them. Without a conversation (a
|
|
122
|
-
* framework that takes no steering), they wait for the turn's end.
|
|
123
|
-
*/
|
|
124
|
-
export declare function toolCallEnded(ctx: restate.SessionContext, conversation?: Steerable): Promise<void>;
|
|
125
|
-
/**
|
|
126
|
-
* Count the messages steered to the turn of `ctx` that `conversation` has,
|
|
127
|
-
* such as those an earlier attempt gave it. A framework calls it once a
|
|
128
|
-
* prompt is answered; the turn's other messages are answered as messages of
|
|
129
|
-
* their own, when it ends.
|
|
130
|
-
*/
|
|
131
|
-
export declare function settleSteering(ctx: restate.SessionContext, conversation: Pick<Steerable, 'has'>): Promise<void>;
|
|
116
|
+
/** A tool call of the turn of `ctx` (a `chat` handler's) ended: {@link publish} it, unless the agent runs in the background. */
|
|
117
|
+
export declare function toolCallEnded(ctx: restate.SessionContext): Promise<void>;
|
|
132
118
|
/** A promise that rejects with `signal`'s reason once it aborts. */
|
|
133
119
|
export declare const aborted: (signal: AbortSignal) => Promise<never>;
|
|
134
120
|
/**
|
|
@@ -147,11 +133,8 @@ export declare const aborted: (signal: AbortSignal) => Promise<never>;
|
|
|
147
133
|
* attempt that ends first (`attemptCompletedSignal`) aborts it too, with an
|
|
148
134
|
* {@link AttemptEnded}: the work stops, and the next attempt goes on with it.
|
|
149
135
|
*
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
* answered as messages of their own, unless it was cancelled. It publishes
|
|
153
|
-
* when it starts and ends ({@link publish}), for the clients that follow the
|
|
154
|
-
* conversation.
|
|
136
|
+
* It publishes when it starts and ends ({@link publish}), for the clients
|
|
137
|
+
* that follow the conversation.
|
|
155
138
|
*/
|
|
156
139
|
export declare const chatHandler: <A = string>(answer: (ctx: restate.SessionContext, message: string) => Promise<A>) => {
|
|
157
140
|
input: restate.Serde<string>;
|
|
@@ -165,12 +148,14 @@ export declare class ToolError extends Error {
|
|
|
165
148
|
constructor(tool: string, cause: unknown);
|
|
166
149
|
}
|
|
167
150
|
/**
|
|
168
|
-
* `error` is a tool's
|
|
169
|
-
* that failed, whose error is never taken for
|
|
170
|
-
* (a tool that calls a model API may fail as
|
|
171
|
-
* {@link ToolError}s.
|
|
151
|
+
* `error` is a tool's, in the attempt of `ctx`: a framework's own tool
|
|
152
|
+
* (Claude's, LangChain's...) that failed, whose error is never taken for
|
|
153
|
+
* the model's provider refusing (a tool that calls a model API may fail as
|
|
154
|
+
* one does). `tool()`'s are {@link ToolError}s.
|
|
172
155
|
*/
|
|
173
|
-
export declare function fromTool(error: unknown): void;
|
|
156
|
+
export declare function fromTool(ctx: restate.SessionContext, error: unknown): void;
|
|
157
|
+
/** {@link refusal}, but not of an error a framework's tool failed with in the attempt of `ctx` ({@link fromTool}). */
|
|
158
|
+
export declare function refusalOf(ctx: restate.SessionContext, error: unknown): restate.TerminalError | undefined;
|
|
174
159
|
/**
|
|
175
160
|
* `error` as a terminal error ({@link REFUSED}), if a retry does not change
|
|
176
161
|
* it: a model the agent cannot take, or its provider's refusal.
|
|
@@ -281,4 +266,5 @@ export declare function transcribing<T>(ctx: restate.SessionContext, read: Read,
|
|
|
281
266
|
* what was stored so far, and stores nothing.
|
|
282
267
|
*/
|
|
283
268
|
export declare const messagesHandler: () => (ctx: restate.ViewContext, request?: MessagesRequest) => Promise<Messages>;
|
|
269
|
+
export {};
|
|
284
270
|
//# sourceMappingURL=common.d.ts.map
|
package/dist/common.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../src/common.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,OAAO,MAAM,sBAAsB,CAAC;AAIhD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"common.d.ts","sourceRoot":"","sources":["../src/common.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,OAAO,MAAM,sBAAsB,CAAC;AAIhD,OAAO,KAAK,EAAE,IAAI,EAAE,MAAM,UAAU,CAAC;AAGrC;;;;;;GAMG;AACH,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,OAAO,CAAC,cAAc,KAAK,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;AAEjF,2CAA2C;AAC3C,eAAO,MAAM,UAAU,GAAU,CAAC,SAAS,SAAS,CAAC,CAAC,CAAC,OAAO,OAAO,CAAC,cAAc,KAAG,OAAO,CAAC,CAAC,CACO,CAAC;AAKxG;;;;GAIG;AACH,eAAO,MAAM,YAAY,QAAS,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