@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.
Files changed (136) hide show
  1. package/README.md +107 -53
  2. package/dist/calls.d.ts +29 -5
  3. package/dist/calls.d.ts.map +1 -1
  4. package/dist/calls.js +77 -10
  5. package/dist/calls.js.map +1 -1
  6. package/dist/claude/index.d.ts +36 -7
  7. package/dist/claude/index.d.ts.map +1 -1
  8. package/dist/claude/index.js +232 -151
  9. package/dist/claude/index.js.map +1 -1
  10. package/dist/client.d.ts +12 -3
  11. package/dist/client.d.ts.map +1 -1
  12. package/dist/client.js.map +1 -1
  13. package/dist/common.d.ts +151 -70
  14. package/dist/common.d.ts.map +1 -1
  15. package/dist/common.js +246 -204
  16. package/dist/common.js.map +1 -1
  17. package/dist/conversation.d.ts +478 -0
  18. package/dist/conversation.d.ts.map +1 -0
  19. package/dist/conversation.js +1256 -0
  20. package/dist/conversation.js.map +1 -0
  21. package/dist/deepseek/index.d.ts +38 -5
  22. package/dist/deepseek/index.d.ts.map +1 -1
  23. package/dist/deepseek/index.js +322 -106
  24. package/dist/deepseek/index.js.map +1 -1
  25. package/dist/deepseek/persistence.d.ts +9 -3
  26. package/dist/deepseek/persistence.d.ts.map +1 -1
  27. package/dist/deepseek/persistence.js +12 -6
  28. package/dist/deepseek/persistence.js.map +1 -1
  29. package/dist/index.d.ts +2 -2
  30. package/dist/index.d.ts.map +1 -1
  31. package/dist/index.js +2 -3
  32. package/dist/index.js.map +1 -1
  33. package/dist/langgraph/checkpointer.d.ts +16 -2
  34. package/dist/langgraph/checkpointer.d.ts.map +1 -1
  35. package/dist/langgraph/checkpointer.js +133 -26
  36. package/dist/langgraph/checkpointer.js.map +1 -1
  37. package/dist/langgraph/context.d.ts +10 -0
  38. package/dist/langgraph/context.d.ts.map +1 -0
  39. package/dist/langgraph/context.js +21 -0
  40. package/dist/langgraph/context.js.map +1 -0
  41. package/dist/langgraph/errors.d.ts +16 -0
  42. package/dist/langgraph/errors.d.ts.map +1 -0
  43. package/dist/langgraph/errors.js +30 -0
  44. package/dist/langgraph/errors.js.map +1 -0
  45. package/dist/langgraph/graph.d.ts +25 -0
  46. package/dist/langgraph/graph.d.ts.map +1 -0
  47. package/dist/langgraph/graph.js +346 -0
  48. package/dist/langgraph/graph.js.map +1 -0
  49. package/dist/langgraph/index.d.ts +65 -12
  50. package/dist/langgraph/index.d.ts.map +1 -1
  51. package/dist/langgraph/index.js +227 -171
  52. package/dist/langgraph/index.js.map +1 -1
  53. package/dist/langgraph/nodes.d.ts +70 -0
  54. package/dist/langgraph/nodes.d.ts.map +1 -0
  55. package/dist/langgraph/nodes.js +145 -0
  56. package/dist/langgraph/nodes.js.map +1 -0
  57. package/dist/messages.d.ts +18 -0
  58. package/dist/messages.d.ts.map +1 -0
  59. package/dist/messages.js +182 -0
  60. package/dist/messages.js.map +1 -0
  61. package/dist/object.d.ts +65 -23
  62. package/dist/object.d.ts.map +1 -1
  63. package/dist/object.js +123 -35
  64. package/dist/object.js.map +1 -1
  65. package/dist/opencode/db.d.ts +51 -10
  66. package/dist/opencode/db.d.ts.map +1 -1
  67. package/dist/opencode/db.js +122 -34
  68. package/dist/opencode/db.js.map +1 -1
  69. package/dist/opencode/index.d.ts +105 -21
  70. package/dist/opencode/index.d.ts.map +1 -1
  71. package/dist/opencode/index.js +827 -279
  72. package/dist/opencode/index.js.map +1 -1
  73. package/dist/output.d.ts +15 -7
  74. package/dist/output.d.ts.map +1 -1
  75. package/dist/output.js +44 -26
  76. package/dist/output.js.map +1 -1
  77. package/dist/pi/index.d.ts +39 -11
  78. package/dist/pi/index.d.ts.map +1 -1
  79. package/dist/pi/index.js +281 -77
  80. package/dist/pi/index.js.map +1 -1
  81. package/dist/pi/storage.d.ts +29 -4
  82. package/dist/pi/storage.d.ts.map +1 -1
  83. package/dist/pi/storage.js +18 -6
  84. package/dist/pi/storage.js.map +1 -1
  85. package/dist/signals.d.ts +74 -4
  86. package/dist/signals.d.ts.map +1 -1
  87. package/dist/signals.js +144 -15
  88. package/dist/signals.js.map +1 -1
  89. package/dist/steering.d.ts +31 -0
  90. package/dist/steering.d.ts.map +1 -0
  91. package/dist/steering.js +45 -0
  92. package/dist/steering.js.map +1 -0
  93. package/dist/tools.d.ts +28 -0
  94. package/dist/tools.d.ts.map +1 -1
  95. package/dist/tools.js +34 -5
  96. package/dist/tools.js.map +1 -1
  97. package/package.json +42 -13
  98. package/src/calls.ts +107 -15
  99. package/src/claude/README.md +41 -20
  100. package/src/claude/index.ts +266 -178
  101. package/src/client.ts +14 -3
  102. package/src/common.ts +317 -232
  103. package/src/conversation.ts +1547 -0
  104. package/src/deepseek/README.md +78 -11
  105. package/src/deepseek/index.ts +384 -137
  106. package/src/deepseek/persistence.ts +11 -8
  107. package/src/index.ts +13 -4
  108. package/src/langgraph/README.md +115 -25
  109. package/src/langgraph/checkpointer.ts +168 -28
  110. package/src/langgraph/context.ts +27 -0
  111. package/src/langgraph/errors.ts +26 -0
  112. package/src/langgraph/graph.ts +396 -0
  113. package/src/langgraph/index.ts +326 -181
  114. package/src/langgraph/nodes.ts +243 -0
  115. package/src/messages.ts +244 -0
  116. package/src/object.ts +169 -38
  117. package/src/opencode/README.md +172 -66
  118. package/src/opencode/db.ts +204 -40
  119. package/src/opencode/index.ts +1010 -325
  120. package/src/output.ts +52 -31
  121. package/src/pi/README.md +18 -3
  122. package/src/pi/index.ts +346 -78
  123. package/src/pi/storage.ts +20 -7
  124. package/src/signals.ts +225 -19
  125. package/src/steering.ts +67 -0
  126. package/src/tools.ts +61 -8
  127. package/dist/claude/conversation.d.ts +0 -33
  128. package/dist/claude/conversation.d.ts.map +0 -1
  129. package/dist/claude/conversation.js +0 -95
  130. package/dist/claude/conversation.js.map +0 -1
  131. package/dist/log.d.ts +0 -29
  132. package/dist/log.d.ts.map +0 -1
  133. package/dist/log.js +0 -146
  134. package/dist/log.js.map +0 -1
  135. package/src/claude/conversation.ts +0 -114
  136. package/src/log.ts +0 -194
@@ -0,0 +1,25 @@
1
+ import * as restate from '@restatedev/sessions';
2
+ import { type BaseMessage } from '@langchain/core/messages';
3
+ import { type Pregel, StateGraph } from '@langchain/langgraph';
4
+ import type { Run } from '../conversation.ts';
5
+ /** A graph of your own: a `StateGraph` (not compiled), or a compiled one such as LangChain's `createAgent` makes. */
6
+ export type AnyGraph = StateGraph<any, any, any, any, any, any, any, any, any, any> | Pregel<any, any, any, any, any, any, any, any, any, any, any>;
7
+ /** The graph's thread: there is one per key, as the key's database is its own. */
8
+ export declare const THREAD_ID = "chat";
9
+ /** Why a graph with static breakpoints is refused, and a run stopped at a subgraph's fails. */
10
+ export declare const BREAKPOINTS: string;
11
+ /**
12
+ * Throw a `TypeError` if `graph` has no `messages` in its state, or is
13
+ * compiled with static breakpoints. A subgraph's static breakpoints are found
14
+ * when one stops a run, which then fails: LangGraph has no public way to find
15
+ * every subgraph (a node may call one it makes).
16
+ */
17
+ export declare function check(graph: AnyGraph): void;
18
+ /** The name of the signal that answers LangGraph's `interrupt()`. */
19
+ export declare const INTERRUPT = "interrupt";
20
+ /**
21
+ * The run of a prompt: the graph's, on the key's thread, from the prompt to
22
+ * its answer. `context` is the graph's run context, if not the handler's.
23
+ */
24
+ export declare const graphRun: (ctx: restate.SessionContext, graph: AnyGraph, context?: unknown) => Run<BaseMessage>;
25
+ //# sourceMappingURL=graph.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graph.d.ts","sourceRoot":"","sources":["../../src/langgraph/graph.ts"],"names":[],"mappings":"AAwDA,OAAO,KAAK,OAAO,MAAM,sBAAsB,CAAC;AAChD,OAAO,EAAa,KAAK,WAAW,EAA6B,MAAM,0BAA0B,CAAC;AAGlG,OAAO,EAA+B,KAAK,MAAM,EAAsB,UAAU,EAAE,MAAM,sBAAsB,CAAC;AAEhH,OAAO,KAAK,EAAgB,GAAG,EAAQ,MAAM,oBAAoB,CAAC;AAMlE,qHAAqH;AACrH,MAAM,MAAM,QAAQ,GAEhB,UAAU,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,GAE5D,MAAM,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;AAElE,kFAAkF;AAClF,eAAO,MAAM,SAAS,SAAS,CAAC;AAGhC,+FAA+F;AAC/F,eAAO,MAAM,WAAW,QAEqE,CAAC;AAE9F;;;;;GAKG;AACH,wBAAgB,KAAK,CAAC,KAAK,EAAE,QAAQ,QAOpC;AAkID,qEAAqE;AACrE,eAAO,MAAM,SAAS,cAAc,CAAC;AAqFrC;;;GAGG;AACH,eAAO,MAAM,QAAQ,QACb,OAAO,CAAC,cAAc,SAAS,QAAQ,YAAY,OAAO,KAAG,GAAG,CAAC,WAAW,CAEV,CAAC"}
@@ -0,0 +1,346 @@
1
+ // An agent whose `chat` runs a LangGraph graph of your own:
2
+ // `langgraph.agent({ name, graph })`, as the Python SDK's
3
+ // restate/agents/langgraph/_graph.py.
4
+ //
5
+ // The graph's state has LangGraph's `messages` (`MessagesAnnotation`), and
6
+ // each message to the agent is a run of the graph on the key's thread, with
7
+ // the message as a new `HumanMessage`:
8
+ //
9
+ // - The graph's checkpoints are in the key's database (`SqlCheckpointSaver`),
10
+ // stored before each step runs (`durability: 'sync'`), and the prebuilt
11
+ // nodes (nodes.ts) and the tools of `tools()` get the handler's context
12
+ // there (context.ts). LangGraph's run context is the graph's own (`context`),
13
+ // else the handler's. A retried attempt resumes the run it cut off. A run
14
+ // that finishes prunes the thread to the latest checkpoint of each
15
+ // namespace, and what LangGraph rebuilds its delta channels from.
16
+ // - Any error of the run fails the attempt, and Restate retries it: none is
17
+ // taken for a model provider's refusal, as the built-in agent's model's
18
+ // can be, since a graph's models, tools and nodes are all its own. A
19
+ // `TerminalError` ends the turn, and so do LangGraph's own errors that a
20
+ // retry would meet again (errors.ts). A run that an invalid update ended
21
+ // leaves writes that LangGraph cannot apply: the next message starts its
22
+ // run from the checkpoint before them, as a new run discards them.
23
+ // - After each step, the AI and tool messages the step added are copied into
24
+ // the agent's conversation, by their ids, so that the `messages` view (and
25
+ // `watch`) shows the run as it goes. They are the messages after the run's
26
+ // prompt; if the graph trimmed the prompt away, those whose ids the
27
+ // conversation does not have. With `durability: 'sync'`, LangGraph streams
28
+ // a step's state only once its checkpoint is stored, so the conversation
29
+ // never gets ahead of the checkpoints; a crash between a checkpoint and its
30
+ // copy is made up by the next step's state, as messages are copied by id.
31
+ // The conversation is a log: a message the graph removes or edits later
32
+ // stays as it was copied.
33
+ // - The answer is the text of the run's last AI message. A graph that writes
34
+ // a `structuredResponse` in the run (LangChain's `createAgent` with a
35
+ // `responseFormat`) answers with it instead, as JSON, which `output`
36
+ // validates; one left from an earlier run is not the answer.
37
+ // - LangGraph's `interrupt()` waits for a signal: each pending interrupt is
38
+ // a wait named `interrupt`, which the agent's `pending` view lists with the
39
+ // interrupt's value, and which `signal` resolves (by the wait's id, or as
40
+ // the oldest `interrupt`). The run then resumes with `new Command({ resume
41
+ // })`, the signal's value as `interrupt()`'s result. The turn waits without
42
+ // holding a process; a retried attempt joins the same waits. Static
43
+ // breakpoints (`interruptBefore`, `interruptAfter`) have nothing to wait
44
+ // for: a compiled graph with them is refused, and a run that stops at a
45
+ // subgraph's fails.
46
+ // - A stopped run is not resumed: the next message starts a run of its own,
47
+ // from the state the graph had stored. What closed the stopped (or
48
+ // refused, or failed) run in the conversation comes first in the new run's
49
+ // input: the results of its cut-off tool calls, and the note that ends it,
50
+ // so that the graph's model knows. So does that run's message, if the graph
51
+ // never stored it.
52
+ //
53
+ // The graph's state is its own: its models read the state, not the
54
+ // conversation, so the agent's `window`, `budget` and `summarize` do not
55
+ // reach them. Trimming the state is the graph's job (a node that returns a
56
+ // `RemoveMessage` for each message to drop, say).
57
+ import * as restate from '@restatedev/sessions';
58
+ import { AIMessage, HumanMessage, ToolMessage } from '@langchain/core/messages';
59
+ import { mapStoredMessagesToChatMessages } from '@langchain/core/messages';
60
+ import { Command, InvalidUpdateError, StateGraph } from '@langchain/langgraph';
61
+ import { fromTool, stepped, stopSignalOf } from '../common.js';
62
+ import { signals, signalsOf } from '../signals.js';
63
+ import { SqlCheckpointSaver } from './checkpointer.js';
64
+ import { running } from './context.js';
65
+ import { terminalOf } from './errors.js';
66
+ /** The graph's thread: there is one per key, as the key's database is its own. */
67
+ export const THREAD_ID = 'chat';
68
+ const THREAD = { configurable: { thread_id: THREAD_ID } };
69
+ /** Why a graph with static breakpoints is refused, and a run stopped at a subgraph's fails. */
70
+ export const BREAKPOINTS = 'static breakpoints (interruptBefore, interruptAfter) stop a run with nothing to wait for, and leave its tool ' +
71
+ 'calls without results: pause the graph with interrupt() instead, which waits for a signal';
72
+ /**
73
+ * Throw a `TypeError` if `graph` has no `messages` in its state, or is
74
+ * compiled with static breakpoints. A subgraph's static breakpoints are found
75
+ * when one stops a run, which then fails: LangGraph has no public way to find
76
+ * every subgraph (a node may call one it makes).
77
+ */
78
+ export function check(graph) {
79
+ if (!('messages' in graph.channels)) {
80
+ throw new TypeError("the graph's state has no messages: build it on LangGraph's MessagesAnnotation");
81
+ }
82
+ if (!(graph instanceof StateGraph) && (graph.interruptBefore?.length || graph.interruptAfter?.length)) {
83
+ throw new TypeError(BREAKPOINTS);
84
+ }
85
+ }
86
+ /** `graph` compiled with its checkpoints in `saver`. */
87
+ function compiled(graph, saver) {
88
+ if (graph instanceof StateGraph)
89
+ return graph.compile({ checkpointer: saver });
90
+ // A copy, as `withConfig` makes one: the graph is shared by every key's runs.
91
+ const Compiled = graph.constructor;
92
+ // oxlint-disable-next-line typescript/no-misused-spread -- the graph's fields, as its constructor takes them
93
+ return new Compiled({ ...graph, checkpointer: saver });
94
+ }
95
+ /** The key, in each checkpoint's metadata, of the prompt whose run made it: the run's input may be trimmed away. */
96
+ const PROMPT = 'restate_prompt';
97
+ /** The state field of a structured answer, as LangChain's `createAgent` writes it. */
98
+ const STRUCTURED = 'structuredResponse';
99
+ /** The key, in each checkpoint's metadata, of the version the structured answer's channel had as its run began. */
100
+ const STRUCTURED_BEFORE = 'restate_structured_version';
101
+ /** The prefixes of the ids of the messages that the conversation gave the graph, rather than the graph made. */
102
+ const CARRIED = ['prompt:', 'closed:'];
103
+ /** The ids of the graph's messages that the conversation has: those copied from it. */
104
+ const knownOf = (conversation) => new Set(conversation.entries.flatMap((e) => (e.item.id === undefined ? [] : [e.item.id])));
105
+ /** The version of the graph's structured answer's channel, which changes each time it is written. */
106
+ async function structuredVersion(app) {
107
+ const stored = await app.checkpointer.getTuple(THREAD);
108
+ return String(stored?.checkpoint.channel_versions[STRUCTURED] ?? '');
109
+ }
110
+ /**
111
+ * The run's answer: the JSON of the structured answer it wrote, else its last
112
+ * AI message's text. A structured answer counts only if the run wrote it (its
113
+ * channel's version is not `before`): the state keeps an earlier run's. The
114
+ * text is read from the conversation, a log, as the graph may have trimmed
115
+ * its own history (the run's input and answer included).
116
+ */
117
+ async function answerOf(app, turn, state, before) {
118
+ const structured = state[STRUCTURED];
119
+ if (structured !== undefined && structured !== null && (await structuredVersion(app)) !== before) {
120
+ return JSON.stringify(structured);
121
+ }
122
+ const replies = turn.items.flatMap((e) => (AIMessage.isInstance(e.item) && e.item.id !== undefined ? [e.item] : []));
123
+ return replies.at(-1)?.text ?? '';
124
+ }
125
+ /**
126
+ * Copy the AI and tool messages of `messages` (the graph's state) that the
127
+ * conversation does not have yet: those after the run's prompt (whose id is
128
+ * `prompt`), as the state holds the earlier turns too; if the graph trimmed
129
+ * the prompt away, those whose ids are not `known`. `known` is the ids the
130
+ * conversation has, which this adds to; the messages the conversation gave
131
+ * the graph are not copied back. Then publish.
132
+ */
133
+ async function copied(ctx, turn, known, messages, prompt) {
134
+ const at = messages.findIndex((m) => m.id === prompt);
135
+ const fresh = messages
136
+ .slice(at + 1)
137
+ .filter((m) => (AIMessage.isInstance(m) || ToolMessage.isInstance(m)) &&
138
+ m.id !== undefined &&
139
+ !known.has(m.id) &&
140
+ !CARRIED.some((prefix) => m.id.startsWith(prefix)));
141
+ for (const message of fresh) {
142
+ if (AIMessage.isInstance(message))
143
+ await turn.appendReply([message]);
144
+ else
145
+ await turn.append(message);
146
+ known.add(message.id);
147
+ }
148
+ if (fresh.length > 0)
149
+ await stepped(ctx);
150
+ }
151
+ /** The id of a turn's prompt, as a `HumanMessage` in the graph: the conversation's id of the turn. */
152
+ const promptIdOf = (turn) => `prompt:${turn.id}`;
153
+ /** `message` with the id `id`. */
154
+ const withId = (message, id) => {
155
+ const stored = message.toDict();
156
+ return mapStoredMessagesToChatMessages([{ ...stored, data: { ...stored.data, id } }])[0];
157
+ };
158
+ /**
159
+ * What the conversation has of the previous prompt's run that the graph does
160
+ * not: what closed the run, if it was stopped, refused or failed (the results
161
+ * of its cut-off tool calls and the note that ends it, which only the
162
+ * conversation has: copied messages have the graph's ids, these have none),
163
+ * and the previous prompt itself, if the graph never stored it (its run
164
+ * copied nothing). Each gets an id of its own, so that it is carried once.
165
+ */
166
+ function closing(conversation, turn, messages) {
167
+ const turns = conversation.turns;
168
+ const at = turns.indexOf(turn);
169
+ if (at <= 0)
170
+ return [];
171
+ const previous = turns[at - 1];
172
+ const known = new Set(messages.map((m) => m.id));
173
+ const copiedAny = previous.items.some((e) => e.item.id !== undefined);
174
+ // Only a turn the conversation closed (stopped, refused, failed, ended) has messages the graph lacks.
175
+ const closed = previous.status !== undefined && previous.status !== 'answered';
176
+ const carried = [];
177
+ for (const entry of previous.entries) {
178
+ const item = entry.item;
179
+ if (entry.prompt !== undefined) {
180
+ if (!copiedAny && !known.has(promptIdOf(previous))) {
181
+ carried.push(new HumanMessage({ content: item.text, id: promptIdOf(previous) }));
182
+ }
183
+ }
184
+ else if (closed && !HumanMessage.isInstance(item) && item.id === undefined && !known.has(`closed:${entry.n}`)) {
185
+ carried.push(withId(item, `closed:${entry.n}`));
186
+ }
187
+ }
188
+ return carried;
189
+ }
190
+ /** The name of the signal that answers LangGraph's `interrupt()`. */
191
+ export const INTERRUPT = 'interrupt';
192
+ /**
193
+ * The pending interrupts of the run, each once: LangGraph keeps each on the
194
+ * task whose step raised it, a subgraph's included, and each graph above that
195
+ * task lists it again, under the same id.
196
+ */
197
+ function interruptsOf(snapshot) {
198
+ const pending = new Map();
199
+ for (const task of snapshot.tasks) {
200
+ for (const interrupted of task.interrupts ?? []) {
201
+ if (interrupted.id !== undefined && !pending.has(interrupted.id)) {
202
+ pending.set(interrupted.id, { id: interrupted.id, value: interrupted.value });
203
+ }
204
+ }
205
+ }
206
+ return [...pending.values()];
207
+ }
208
+ /**
209
+ * How many resume values the thread's pending writes hold: one more each
210
+ * time an `interrupt()` is answered, until its step ends. LangGraph gives an
211
+ * interrupt the id of its task's namespace, so a node's second `interrupt()`
212
+ * has its first's id: the count tells them apart.
213
+ */
214
+ async function resumesOf(ctx, saver) {
215
+ const rows = await ctx.db.values("SELECT type, value FROM restate_langgraph_writes WHERE thread_id = ? AND channel = '__resume__'", [THREAD_ID]);
216
+ let count = 0;
217
+ for (const [type, value] of rows) {
218
+ const resumes = await saver.serde.loadsTyped(String(type), value);
219
+ count += Array.isArray(resumes) ? resumes.length : 1;
220
+ }
221
+ return count;
222
+ }
223
+ /**
224
+ * Wait for a signal for each pending interrupt of `snapshot`, and return
225
+ * their values by interrupt id, or `undefined` if none is pending. Each
226
+ * wait's id is the turn's invocation id (the same in each attempt), the
227
+ * interrupt's id, and the count of resume values stored (see
228
+ * {@link resumesOf}): a retried attempt joins the same waits, and a turn that
229
+ * ends without them has them closed, as the companion closes the waits whose
230
+ * ids start with the turn's.
231
+ */
232
+ async function resumed(ctx, saver, snapshot) {
233
+ const pending = interruptsOf(snapshot);
234
+ if (pending.length === 0)
235
+ return undefined;
236
+ const resumes = await resumesOf(ctx, saver);
237
+ const values = await Promise.all(pending.map(({ id, value }) => {
238
+ const waitId = `${ctx.request.id}:interrupt:${id}:${resumes}`;
239
+ // As JSON, which the companion stores: the state may hold class instances.
240
+ const input = value === undefined ? undefined : JSON.parse(JSON.stringify(value));
241
+ return ctx
242
+ .rpc(signals, signalsOf(ctx), { idempotencyKey: waitId })
243
+ .wait({ id: waitId, name: INTERRUPT, ...(input === undefined ? {} : { input }) });
244
+ }));
245
+ return Object.fromEntries(pending.map(({ id }, i) => [id, values[i]]));
246
+ }
247
+ /** Whether a run stopped with steps to go and no interrupt: at a static breakpoint. */
248
+ const atBreakpoint = (paused) => paused.next.length > 0 && !paused.tasks.some((task) => (task.interrupts ?? []).length > 0);
249
+ /**
250
+ * The state of the graph's thread: where it stopped, and why (its tasks'
251
+ * interrupts). If the writes of the last step's tasks do not fit the state
252
+ * (an invalid update), it is the state of the checkpoint itself, which
253
+ * LangGraph shows without them: a run with new input discards them.
254
+ */
255
+ async function storedState(app) {
256
+ try {
257
+ return await app.getState(THREAD);
258
+ }
259
+ catch (error) {
260
+ if (!(error instanceof InvalidUpdateError))
261
+ throw error;
262
+ const latest = await app.checkpointer.getTuple(THREAD);
263
+ if (!latest)
264
+ throw error;
265
+ return app.getState(latest.config);
266
+ }
267
+ }
268
+ /**
269
+ * The run of a prompt: the graph's, on the key's thread, from the prompt to
270
+ * its answer. `context` is the graph's run context, if not the handler's.
271
+ */
272
+ export const graphRun = (ctx, graph, context) => (conversation) => running(ctx, () => runGraph(ctx, graph, context ?? ctx, conversation));
273
+ async function runGraph(ctx, graph, context, conversation) {
274
+ const turn = conversation.turn;
275
+ // The run's input: the turn's prompt, or the message that asked again within the turn, under an id of its own.
276
+ const step = turn.latestAsk();
277
+ const promptId = step === turn.prompt ? promptIdOf(turn) : `${promptIdOf(turn)}:again:${step.n}`;
278
+ const app = compiled(graph, new SqlCheckpointSaver(ctx.db));
279
+ const snapshot = await storedState(app);
280
+ let values = snapshot.values;
281
+ const messages = (values.messages ?? []);
282
+ const known = knownOf(conversation);
283
+ const metadata = (snapshot.metadata ?? {});
284
+ const asked = metadata[PROMPT] === promptId;
285
+ const stamped = metadata[STRUCTURED_BEFORE];
286
+ const before = asked ? (typeof stamped === 'string' ? stamped : '') : await structuredVersion(app);
287
+ // Each checkpoint of the run names its prompt, so that a retried attempt finds the run it cut off, and the
288
+ // version its structured answer had before it.
289
+ const saver = new SqlCheckpointSaver(ctx.db, { metadata: { [PROMPT]: promptId, [STRUCTURED_BEFORE]: before } });
290
+ const run = compiled(graph, saver);
291
+ const options = {
292
+ ...THREAD,
293
+ context,
294
+ durability: 'sync',
295
+ streamMode: 'values',
296
+ signal: stopSignalOf(ctx),
297
+ };
298
+ if (asked && snapshot.next.length === 0) {
299
+ // The run had finished, but its answer was not stored: that is the answer, rather than run again.
300
+ await copied(ctx, turn, known, messages, promptId);
301
+ await saver.prune([THREAD_ID]);
302
+ return answerOf(run, turn, values, before);
303
+ }
304
+ // A run cut off by a crash is resumed: first by the signals its pending interrupts wait for, if any. A new
305
+ // message (or one after a stopped run) starts a run, after what closed the previous run.
306
+ let start;
307
+ if (asked) {
308
+ const resumes = await resumed(ctx, saver, await storedState(run));
309
+ start = resumes === undefined ? null : new Command({ resume: resumes });
310
+ }
311
+ else {
312
+ const prompt = new HumanMessage({ content: step.item.text, id: promptId });
313
+ const closed = step === turn.prompt ? closing(conversation, turn, messages) : [];
314
+ start = { messages: [...closed, prompt] };
315
+ }
316
+ for (;;) {
317
+ try {
318
+ for await (const state of await run.stream(start, options)) {
319
+ values = state;
320
+ await copied(ctx, turn, known, (state.messages ?? []), promptId);
321
+ }
322
+ }
323
+ catch (error) {
324
+ // LangGraph's own error, which a retry would meet again: a run past its recursion limit, say.
325
+ const terminal = terminalOf(error);
326
+ if (terminal)
327
+ throw terminal;
328
+ // No refusal, whatever its name: a graph's models, tools and nodes are all its own.
329
+ fromTool(ctx, error);
330
+ throw error;
331
+ }
332
+ // The run stops at its interrupts: it goes on with the signals that answer them.
333
+ const paused = await storedState(run);
334
+ const resumes = await resumed(ctx, saver, paused);
335
+ if (resumes === undefined) {
336
+ // At a subgraph's static breakpoint, which check() does not look for: fail, rather than answer half done.
337
+ if (atBreakpoint(paused))
338
+ throw new restate.TerminalError(BREAKPOINTS);
339
+ // Only the latest checkpoint of each namespace is read again; a paused or cut-off run keeps it too.
340
+ await saver.prune([THREAD_ID]);
341
+ return answerOf(run, turn, values, before);
342
+ }
343
+ start = new Command({ resume: resumes });
344
+ }
345
+ }
346
+ //# sourceMappingURL=graph.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"graph.js","sourceRoot":"","sources":["../../src/langgraph/graph.ts"],"names":[],"mappings":"AAAA,4DAA4D;AAC5D,0DAA0D;AAC1D,sCAAsC;AACtC,EAAE;AACF,2EAA2E;AAC3E,4EAA4E;AAC5E,uCAAuC;AACvC,EAAE;AACF,8EAA8E;AAC9E,0EAA0E;AAC1E,0EAA0E;AAC1E,gFAAgF;AAChF,4EAA4E;AAC5E,qEAAqE;AACrE,oEAAoE;AACpE,4EAA4E;AAC5E,0EAA0E;AAC1E,uEAAuE;AACvE,2EAA2E;AAC3E,2EAA2E;AAC3E,2EAA2E;AAC3E,qEAAqE;AACrE,6EAA6E;AAC7E,6EAA6E;AAC7E,6EAA6E;AAC7E,sEAAsE;AACtE,6EAA6E;AAC7E,2EAA2E;AAC3E,8EAA8E;AAC9E,4EAA4E;AAC5E,0EAA0E;AAC1E,4BAA4B;AAC5B,6EAA6E;AAC7E,wEAAwE;AACxE,uEAAuE;AACvE,+DAA+D;AAC/D,4EAA4E;AAC5E,8EAA8E;AAC9E,4EAA4E;AAC5E,6EAA6E;AAC7E,8EAA8E;AAC9E,sEAAsE;AACtE,2EAA2E;AAC3E,0EAA0E;AAC1E,sBAAsB;AACtB,4EAA4E;AAC5E,qEAAqE;AACrE,6EAA6E;AAC7E,6EAA6E;AAC7E,8EAA8E;AAC9E,qBAAqB;AACrB,EAAE;AACF,mEAAmE;AACnE,yEAAyE;AACzE,2EAA2E;A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AAM,CAAC,GAAG,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,KAAK,CAAC,QAAQ,IAAI,EAAE,CAAkB,EAAE,QAAQ,CAAC,CAAC;YACpF,CAAC;QACH,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,8FAA8F;YAC9F,MAAM,QAAQ,GAAG,UAAU,CAAC,KAAK,CAAC,CAAC;YACnC,IAAI,QAAQ;gBAAE,MAAM,QAAQ,CAAC;YAC7B,oFAAoF;YACpF,QAAQ,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;YACrB,MAAM,KAAK,CAAC;QACd,CAAC;QACD,iFAAiF;QACjF,MAAM,MAAM,GAAG,MAAM,WAAW,CAAC,GAAG,CAAC,CAAC;QACtC,MAAM,OAAO,GAAG,MAAM,OAAO,CAAC,GAAG,EAAE,KAAK,EAAE,MAAM,CAAC,CAAC;QAClD,IAAI,OAAO,KAAK,SAAS,EAAE,CAAC;YAC1B,0GAA0G;YAC1G,IAAI,YAAY,CAAC,MAAM,CAAC;gBAAE,MAAM,IAAI,OAAO,CAAC,aAAa,CAAC,WAAW,CAAC,CAAC;YACvE,oGAAoG;YACpG,MAAM,KAAK,CAAC,KAAK,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC;YAC/B,OAAO,QAAQ,CAAC,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,MAAM,CAAC,CAAC;QAC7C,CAAC;QACD,KAAK,GAAG,IAAI,OAAO,CAAC,EAAE,MAAM,EAAE,OAAO,EAAE,CAAC,CAAC;IAC3C,CAAC;AACH,CAAC"}
@@ -1,13 +1,41 @@
1
- import * as restate from '@restatedev/sessions';
1
+ import type * as restate from '@restatedev/sessions';
2
2
  import type { BaseChatModel } from '@langchain/core/language_models/chat_models';
3
+ import { type BaseMessage } from '@langchain/core/messages';
3
4
  import { type StructuredToolInterface } from '@langchain/core/tools';
4
- import { type Configure } from '../common.ts';
5
+ import { type Configure, type Summarize } from '../common.ts';
6
+ import { type Items } from '../conversation.ts';
5
7
  import { type Answer } from '../output.ts';
6
8
  import type { z } from 'zod';
7
9
  import { type Definition } from '../object.ts';
8
10
  import { type Tool as AnyTool } from '../tools.ts';
9
11
  import { SqlCheckpointSaver } from './checkpointer.ts';
12
+ import { type AnyGraph } from './graph.ts';
10
13
  export { SqlCheckpointSaver };
14
+ export { type AnyGraph, INTERRUPT } from './graph.ts';
15
+ export * as nodes from './nodes.ts';
16
+ /**
17
+ * LangGraph's items: LangChain's messages, stored as their `toDict()`. A
18
+ * human message is said by the user; an AI message by the assistant, with
19
+ * its `tool_calls` as calls; a tool message is a result (an error if its
20
+ * status says so).
21
+ */
22
+ export declare const items: Items<BaseMessage>;
23
+ /**
24
+ * `given` as LangChain tools, for a graph of your own or LangChain's
25
+ * `createAgent`:
26
+ *
27
+ * const graph = createAgent({ model, tools: langgraph.tools([call(orders, 'status', { description: '…' })]) });
28
+ * const desk = langgraph.agent({ name: 'desk', graph });
29
+ *
30
+ * Restate's tools (`call`, `send`, `workflow`, `subagent`, `signal`) make
31
+ * their Restate calls once per tool call, even if a crash runs the tool call
32
+ * again: the model's reply, with the tool call's id, is checkpointed before
33
+ * the tools run. A `tool()` of your own runs your function, again after a
34
+ * crash, as do LangChain's tools, which are passed through. They take the
35
+ * handler's context from the graph's run (`langgraph.agent({ graph })` gives
36
+ * it; a handler of your own passes `context: ctx`).
37
+ */
38
+ export declare const tools: (given: (AnyTool | StructuredToolInterface)[]) => StructuredToolInterface[];
11
39
  /** An agent's options: `chat` and `prompt` take them. */
12
40
  export interface Options<O extends z.ZodObject | undefined = z.ZodObject | undefined> {
13
41
  /** The model: `openai/model-id` or `anthropic/model-id` (MODEL, or else openai/gpt-6-sol), or a chat model that calls tools. */
@@ -16,22 +44,40 @@ export interface Options<O extends z.ZodObject | undefined = z.ZodObject | undef
16
44
  system?: string;
17
45
  /** The agent's tools: `tool()`s, Restate's (`call`, `signal`...), or LangChain's. */
18
46
  tools?: (AnyTool | StructuredToolInterface)[];
47
+ /** How many steps of the graph a turn takes at most (default 10 000): past it, the turn fails for good. */
48
+ recursionLimit?: number;
19
49
  /**
20
50
  * The answer as data: a zod object, whose JSON the agent replies with
21
- * (checked), and `chat` and `prompt` answer with (see output.ts).
51
+ * (checked), and `chat` and `prompt` answer with (see output.ts). With
52
+ * `graph`, the graph's own prompts must ask for it.
22
53
  */
23
54
  output?: O;
55
+ /**
56
+ * A graph of your own to run, instead of the built-in tool-calling loop
57
+ * (graph.ts): a `StateGraph` whose state has `messages`, or a compiled one
58
+ * (such as LangChain's `createAgent` makes). It has its own model and
59
+ * tools, so it takes no `model`, `system`, `tools` or `recursionLimit`.
60
+ */
61
+ graph?: AnyGraph;
62
+ /**
63
+ * The run context of `graph` (LangGraph's `context`), for a graph with a
64
+ * context schema of its own. By default the handler's context. The
65
+ * prebuilt `nodes` and the tools of `tools()` get the handler's context
66
+ * either way.
67
+ */
68
+ context?: unknown;
24
69
  }
25
70
  /**
26
71
  * Answer `text`, once: a retried attempt resumes the same prompt. Each prompt
27
- * of an invocation is a prompt of its own. The thread is the object's key.
72
+ * of an invocation is a prompt of its own.
28
73
  * With `output`, it answers with the value the agent replies with (see
29
- * output.ts), not its text.
74
+ * output.ts), not its text: a reply that is not one is asked again within
75
+ * its turn, once.
30
76
  */
31
77
  export declare const prompt: <O extends z.ZodObject | undefined = undefined>(ctx: restate.SessionContext, text: string, options?: Options<O>) => Promise<Answer<O>>;
32
78
  /**
33
- * A chat handler: each message an invocation, the thread (the object's key)
34
- * in the object's database, with `options`, or the options a function of the
79
+ * A chat handler: each message an invocation, the conversation in the
80
+ * object's database, with `options`, or the options a function of the
35
81
  * invocation's context gives. It takes the message as plain text
36
82
  * (`curl -d 'Hi'`) or as a JSON string (`curl --json '"Hi"'`).
37
83
  */
@@ -42,13 +88,19 @@ export declare const chat: <O extends z.ZodObject | undefined = undefined>(optio
42
88
  handler: (ctx: restate.SessionContext, text: string) => Promise<Answer<O>>;
43
89
  };
44
90
  /**
45
- * A handler of the conversation as clients read it: a page at a time, or
46
- * what is new or changed since a cursor, from the log each change writes
47
- * (log.ts). It answers while a message is answered.
91
+ * A view of the conversation as clients read it: a page at a time, or what
92
+ * is new or changed since a cursor; `view: 'summary'` for each turn's
93
+ * message and answer. It answers while a message is answered.
48
94
  */
49
95
  export declare const messages: () => (ctx: restate.ViewContext, request?: import("../common.ts").MessagesRequest) => Promise<import("../common.ts").Messages>;
96
+ /**
97
+ * How an agent of `model` summarizes the earliest turns, past its budget:
98
+ * with its own model (`agent()` gives it; for an object of your own,
99
+ * `sessionObject`'s `summarize`).
100
+ */
101
+ export declare const summarizer: (model?: Options['model']) => Summarize;
50
102
  /** An agent: a virtual object `name`, one per key, whose `chat` handler is {@link chat}, and `messages` {@link messages}. */
51
- export declare const agent: <P extends string, O extends z.ZodObject | undefined = undefined>({ name, description, schema, background, ...options }: Options<O> & Definition<P>) => restate.VirtualObjectDefinition<P, {
103
+ export declare const agent: <P extends string, O extends z.ZodObject | undefined = undefined>({ name, description, schema, background, window, budget, summarize, ...options }: Options<O> & Definition<P>) => restate.VirtualObjectDefinition<P, {
52
104
  signal: (ctx: restate.ViewContext, signal: import("../signals.ts").Signal) => Promise<import("../signals.ts").Resolved>;
53
105
  pending: (ctx: restate.ViewContext) => Promise<import("../signals.ts").Waiting[]>;
54
106
  status: (ctx: restate.ViewContext) => Promise<import("../object.ts").Status>;
@@ -57,7 +109,8 @@ export declare const agent: <P extends string, O extends z.ZodObject | undefined
57
109
  watch: (ctx: restate.ViewContext, watch: import("../signals.ts").Watch) => Promise<import("../signals.ts").Notifications>;
58
110
  } & {
59
111
  clear: (ctx: restate.ViewContext) => Promise<import("../object.ts").Stopped>;
60
- sync: (ctx: restate.ViewContext, { cursor, revision, timeoutSeconds, limit }?: import("../object.ts").SyncRequest) => Promise<import("../object.ts").Synced>;
112
+ steer: (ctx: restate.ViewContext, text: string) => Promise<import("../signals.ts").Steered>;
113
+ sync: (ctx: restate.ViewContext, { cursor, revision, timeoutSeconds, limit, view }?: import("../object.ts").SyncRequest) => Promise<import("../object.ts").Synced>;
61
114
  } & {
62
115
  chat: (ctx: restate.SessionContext, text: string) => Promise<Answer<O>>;
63
116
  } & {
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/langgraph/index.ts"],"names":[],"mappings":"AA2BA,OAAO,KAAK,OAAO,MAAM,sBAAsB,CAAC;AAGhD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,6CAA6C,CAAC;AAEjF,OAAO,EAAE,KAAK,uBAAuB,EAAmC,MAAM,uBAAuB,CAAC;AAGtG,OAAO,EAIL,KAAK,SAAS,EAgBf,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;AAEzE,OAAO,EAAE,kBAAkB,EAAE,MAAM,mBAAmB,CAAC;AAEvD,OAAO,EAAE,kBAAkB,EAAE,CAAC;AAyH9B,yDAAyD;AACzD,MAAM,WAAW,OAAO,CAAC,CAAC,SAAS,CAAC,CAAC,SAAS,GAAG,SAAS,GAAG,CAAC,CAAC,SAAS,GAAG,SAAS;IAClF,gIAAgI;IAChI,KAAK,CAAC,EAAE,MAAM,GAAG,aAAa,CAAC;IAC/B,+DAA+D;IAC/D,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,qFAAqF;IACrF,KAAK,CAAC,EAAE,CAAC,OAAO,GAAG,uBAAuB,CAAC,EAAE,CAAC;IAC9C;;;OAGG;IACH,MAAM,CAAC,EAAE,CAAC,CAAC;CACZ;AA0FD;;;;;GAKG;AACH,eAAO,MAAM,MAAM,GAAI,CAAC,SAAS,CAAC,CAAC,SAAS,GAAG,SAAS,GAAG,SAAS,OAC7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