@restatedev/agents 0.3.0 → 0.5.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 +107 -53
- package/dist/calls.d.ts +29 -5
- package/dist/calls.d.ts.map +1 -1
- package/dist/calls.js +77 -10
- package/dist/calls.js.map +1 -1
- package/dist/claude/index.d.ts +36 -7
- package/dist/claude/index.d.ts.map +1 -1
- package/dist/claude/index.js +232 -151
- package/dist/claude/index.js.map +1 -1
- package/dist/client.d.ts +12 -3
- package/dist/client.d.ts.map +1 -1
- package/dist/client.js.map +1 -1
- package/dist/common.d.ts +151 -70
- package/dist/common.d.ts.map +1 -1
- package/dist/common.js +246 -204
- package/dist/common.js.map +1 -1
- package/dist/conversation.d.ts +478 -0
- package/dist/conversation.d.ts.map +1 -0
- package/dist/conversation.js +1256 -0
- package/dist/conversation.js.map +1 -0
- package/dist/deepseek/index.d.ts +38 -5
- package/dist/deepseek/index.d.ts.map +1 -1
- package/dist/deepseek/index.js +322 -106
- package/dist/deepseek/index.js.map +1 -1
- package/dist/deepseek/persistence.d.ts +9 -3
- package/dist/deepseek/persistence.d.ts.map +1 -1
- package/dist/deepseek/persistence.js +12 -6
- package/dist/deepseek/persistence.js.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -3
- package/dist/index.js.map +1 -1
- package/dist/langgraph/checkpointer.d.ts +16 -2
- package/dist/langgraph/checkpointer.d.ts.map +1 -1
- package/dist/langgraph/checkpointer.js +133 -26
- package/dist/langgraph/checkpointer.js.map +1 -1
- package/dist/langgraph/context.d.ts +10 -0
- package/dist/langgraph/context.d.ts.map +1 -0
- package/dist/langgraph/context.js +21 -0
- package/dist/langgraph/context.js.map +1 -0
- package/dist/langgraph/errors.d.ts +16 -0
- package/dist/langgraph/errors.d.ts.map +1 -0
- package/dist/langgraph/errors.js +30 -0
- package/dist/langgraph/errors.js.map +1 -0
- package/dist/langgraph/graph.d.ts +25 -0
- package/dist/langgraph/graph.d.ts.map +1 -0
- package/dist/langgraph/graph.js +346 -0
- package/dist/langgraph/graph.js.map +1 -0
- package/dist/langgraph/index.d.ts +65 -12
- package/dist/langgraph/index.d.ts.map +1 -1
- package/dist/langgraph/index.js +227 -171
- package/dist/langgraph/index.js.map +1 -1
- package/dist/langgraph/nodes.d.ts +70 -0
- package/dist/langgraph/nodes.d.ts.map +1 -0
- package/dist/langgraph/nodes.js +145 -0
- package/dist/langgraph/nodes.js.map +1 -0
- package/dist/messages.d.ts +18 -0
- package/dist/messages.d.ts.map +1 -0
- package/dist/messages.js +182 -0
- package/dist/messages.js.map +1 -0
- package/dist/object.d.ts +65 -23
- package/dist/object.d.ts.map +1 -1
- package/dist/object.js +123 -35
- package/dist/object.js.map +1 -1
- package/dist/opencode/db.d.ts +51 -10
- package/dist/opencode/db.d.ts.map +1 -1
- package/dist/opencode/db.js +122 -34
- package/dist/opencode/db.js.map +1 -1
- package/dist/opencode/index.d.ts +105 -21
- package/dist/opencode/index.d.ts.map +1 -1
- package/dist/opencode/index.js +827 -279
- package/dist/opencode/index.js.map +1 -1
- package/dist/output.d.ts +15 -7
- package/dist/output.d.ts.map +1 -1
- package/dist/output.js +44 -26
- package/dist/output.js.map +1 -1
- package/dist/pi/index.d.ts +39 -11
- package/dist/pi/index.d.ts.map +1 -1
- package/dist/pi/index.js +281 -77
- package/dist/pi/index.js.map +1 -1
- package/dist/pi/storage.d.ts +29 -4
- package/dist/pi/storage.d.ts.map +1 -1
- package/dist/pi/storage.js +18 -6
- package/dist/pi/storage.js.map +1 -1
- package/dist/signals.d.ts +74 -4
- package/dist/signals.d.ts.map +1 -1
- package/dist/signals.js +144 -15
- package/dist/signals.js.map +1 -1
- package/dist/steering.d.ts +31 -0
- package/dist/steering.d.ts.map +1 -0
- package/dist/steering.js +45 -0
- package/dist/steering.js.map +1 -0
- package/dist/tools.d.ts +28 -0
- package/dist/tools.d.ts.map +1 -1
- package/dist/tools.js +34 -5
- package/dist/tools.js.map +1 -1
- package/package.json +42 -13
- package/src/calls.ts +107 -15
- package/src/claude/README.md +41 -20
- package/src/claude/index.ts +266 -178
- package/src/client.ts +14 -3
- package/src/common.ts +317 -232
- package/src/conversation.ts +1547 -0
- package/src/deepseek/README.md +78 -11
- package/src/deepseek/index.ts +384 -137
- package/src/deepseek/persistence.ts +11 -8
- package/src/index.ts +13 -4
- package/src/langgraph/README.md +115 -25
- package/src/langgraph/checkpointer.ts +168 -28
- package/src/langgraph/context.ts +27 -0
- package/src/langgraph/errors.ts +26 -0
- package/src/langgraph/graph.ts +396 -0
- package/src/langgraph/index.ts +326 -181
- package/src/langgraph/nodes.ts +243 -0
- package/src/messages.ts +244 -0
- package/src/object.ts +169 -38
- package/src/opencode/README.md +172 -66
- package/src/opencode/db.ts +204 -40
- package/src/opencode/index.ts +1010 -325
- package/src/output.ts +52 -31
- package/src/pi/README.md +18 -3
- package/src/pi/index.ts +346 -78
- package/src/pi/storage.ts +20 -7
- package/src/signals.ts +225 -19
- package/src/steering.ts +67 -0
- package/src/tools.ts +61 -8
- package/dist/claude/conversation.d.ts +0 -33
- package/dist/claude/conversation.d.ts.map +0 -1
- package/dist/claude/conversation.js +0 -95
- package/dist/claude/conversation.js.map +0 -1
- package/dist/log.d.ts +0 -29
- package/dist/log.d.ts.map +0 -1
- package/dist/log.js +0 -146
- package/dist/log.js.map +0 -1
- package/src/claude/conversation.ts +0 -114
- package/src/log.ts +0 -194
package/src/deepseek/README.md
CHANGED
|
@@ -21,12 +21,14 @@ const assistant = deepseek.agent({ name: 'assistant', system: 'Answer briefly.',
|
|
|
21
21
|
await serve(assistant);
|
|
22
22
|
```
|
|
23
23
|
|
|
24
|
-
| Option
|
|
25
|
-
|
|
|
26
|
-
| `model`
|
|
27
|
-
| `system`
|
|
28
|
-
| `tools`
|
|
29
|
-
| `
|
|
24
|
+
| Option | What |
|
|
25
|
+
| ------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
26
|
+
| `model` | `provider/model-id`; or else `MODEL`, or else `deepseek/deepseek-flash` (see below) |
|
|
27
|
+
| `system` | The system prompt |
|
|
28
|
+
| `tools` | `tool()`s and Restate's tools of `@restatedev/agents`, or the harness's `defineTool`s |
|
|
29
|
+
| `approval` | The tool calls that wait for a person's approval before they run: the names of their tools, or a function of a call (see [Approvals](#approvals)) |
|
|
30
|
+
| `output` | A zod object: the answer as data, which the agent replies with as JSON, and `chat` answers with (see [Structured answers](../../README.md#structured-answers)) |
|
|
31
|
+
| `compaction` | When the model's input is condensed: `@deepseek-ai/dsh-compaction-basic`'s settings, such as `thresholdRatio` (by default 0.8 of the model's context window) |
|
|
30
32
|
|
|
31
33
|
## Models
|
|
32
34
|
|
|
@@ -50,6 +52,57 @@ invocation's context (each user's system prompt, say). `deepseek.prompt(ctx,
|
|
|
50
52
|
text, options)` answers a prompt in a handler of your own, once, however
|
|
51
53
|
often the handler runs; each prompt of an invocation is a prompt of its own.
|
|
52
54
|
|
|
55
|
+
## Approvals
|
|
56
|
+
|
|
57
|
+
The harness can ask a person before a tool call runs. `approval` names the
|
|
58
|
+
calls that ask: by their tools, or as a function of a call (its tool's
|
|
59
|
+
`name`, and its `args`):
|
|
60
|
+
|
|
61
|
+
```ts
|
|
62
|
+
deepseek.agent({ name: 'bank', tools: [transfer, audit], approval: ['transfer'] });
|
|
63
|
+
deepseek.agent({
|
|
64
|
+
name: 'bank',
|
|
65
|
+
tools: [transfer, audit],
|
|
66
|
+
approval: ({ name, args }) => name === 'transfer' && (args as { amount: number }).amount > 100,
|
|
67
|
+
});
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
Such a call waits, before it runs, for the signal `approval`
|
|
71
|
+
(`deepseek.APPROVAL`) to the agent, as a `signal()` tool waits
|
|
72
|
+
([Signals](../../README.md#signals)): without holding a process, for as
|
|
73
|
+
long as it takes. `pending` lists the wait, with the call's tool and
|
|
74
|
+
arguments, and `signal` answers it, by its id, or as the oldest wait for
|
|
75
|
+
`approval`:
|
|
76
|
+
|
|
77
|
+
```sh
|
|
78
|
+
curl localhost:8080/bank/alice/pending
|
|
79
|
+
# [{"id": "inv_1f…:call_01", "name": "approval", "input": {"tool": "transfer", "args": {"from": 1, "to": 2, "amount": 500}}, "since": "…"}]
|
|
80
|
+
curl localhost:8080/bank/alice/signal --json '{"id": "inv_1f…:call_01", "value": "approved"}'
|
|
81
|
+
curl localhost:8080/bank/alice/signal --json '{"name": "approval", "value": "no"}'
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
`true`, `{"approved": true}`, or a text such as `approved`, `yes` or `ok`
|
|
85
|
+
approves the call, once; anything else denies it, and the tool never runs.
|
|
86
|
+
The model gets the harness's denial (`Error: the user rejected tool
|
|
87
|
+
"transfer"`): the text of a denial does not reach it.
|
|
88
|
+
|
|
89
|
+
It is the harness's own approval: a policy of its tool runtime
|
|
90
|
+
(`tools/pre-execute`) asks, and its approval service
|
|
91
|
+
(`@deepseek-ai/dsh-user-approval`, mounted with `approval`) puts the
|
|
92
|
+
question to its answerer, the wait. The log keeps each question and its
|
|
93
|
+
decision (`approval/asked`, `approval/decided`), and the model is told, in
|
|
94
|
+
the harness's runtime context, that a call may ask for an approval.
|
|
95
|
+
|
|
96
|
+
A crash while a call waits, or a suspension (a wait that outlasts
|
|
97
|
+
Restate's inactivity timeout restarts the handler), asks the model again
|
|
98
|
+
([below](#through-crashes)): it makes the call again under a new id, and
|
|
99
|
+
the call, with the same arguments, joins the wait. The person is asked
|
|
100
|
+
once, and the tool runs once, after the decision. A call with other
|
|
101
|
+
arguments, such as a transfer retried with `retryOf` after a crash left its
|
|
102
|
+
outcome unknown, is a call of its own, and asks anew. A turn stopped while
|
|
103
|
+
the call waits, or while the approved tool runs, ends the call as
|
|
104
|
+
cancelled: its approval is not its outcome.
|
|
105
|
+
|
|
53
106
|
## Through crashes
|
|
54
107
|
|
|
55
108
|
The persistence ([`persistence.ts`](persistence.ts),
|
|
@@ -78,10 +131,23 @@ it, and leaves the model to decide what to do about it. So:
|
|
|
78
131
|
without a result, as above.
|
|
79
132
|
- **A failed turn fails the attempt**: a model request that failed, or a
|
|
80
133
|
checkpoint that could not store the log, and Restate retries.
|
|
81
|
-
- **A message is answered once per invocation
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
134
|
+
- **A message is answered once per invocation** (`answerOnce`): a retried
|
|
135
|
+
attempt continues its own prompt (`CONTINUE`, a step of its turn), and
|
|
136
|
+
returns the answer once it has one. A turn a killed invocation left is
|
|
137
|
+
closed (`ended`) in the agent's conversation of turns, never continued,
|
|
138
|
+
and the harness's next turn is told how it ended.
|
|
139
|
+
|
|
140
|
+
The harness keeps its own event log, and its model's input is the harness's;
|
|
141
|
+
each flush of the log copies the turn's new messages (the model's replies,
|
|
142
|
+
the tools' results) into the agent's conversation of turns, in the same
|
|
143
|
+
transaction: what `messages` shows
|
|
144
|
+
([docs/conversation.md](../../docs/conversation.md)). The harness's input
|
|
145
|
+
stays within the model's context window: as it nears the window (or
|
|
146
|
+
overflows it), the harness condenses the oldest history into a summary, one
|
|
147
|
+
more model request, after trimming tool results that are too long
|
|
148
|
+
(`@deepseek-ai/dsh-compaction-basic`, with the token meter and the tool
|
|
149
|
+
result pruner). The log keeps every event, and `messages` every message; a
|
|
150
|
+
crash while condensing is condensed again by the retry.
|
|
85
151
|
|
|
86
152
|
## Run
|
|
87
153
|
|
|
@@ -101,7 +167,8 @@ which makes a fresh tool call id for every call, as a model does
|
|
|
101
167
|
|
|
102
168
|
- [`test/deepseek.test.ts`](../../test/deepseek.test.ts):
|
|
103
169
|
each point above, with crashes that stop an attempt in a tool call, or
|
|
104
|
-
at any of its state requests;
|
|
170
|
+
at any of its state requests; approvals (approved, denied, waited for
|
|
171
|
+
through a crash, at any state request, and cancelled); and
|
|
105
172
|
`messages`. Without the checkpoint policy four of its tests fail, and with
|
|
106
173
|
a transfer tool that ignores `retryOf` three do.
|
|
107
174
|
- [`test/deepseek.ts`](../../test/deepseek.ts): the
|