@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
@@ -1,69 +1,66 @@
1
- // LangGraph agents in Restate virtual objects: a tool-calling graph whose
2
- // checkpoints are in the object's database (checkpointer.ts).
3
- //
4
- // const assistant = langgraph.agent({ name: 'assistant', tools: [search] });
5
- //
6
- // or a handler of an object of your own: `handlers: { chat: langgraph.chat() }`,
7
- // with options for each invocation: `langgraph.chat(async (ctx) => ({ system }))`,
8
- // or a prompt of your own handler: `langgraph.prompt(ctx, text, options)`
9
- //
10
- // The graph is the usual tool-calling loop: a model node, a tools node, and
11
- // back to the model until it answers. The model is `model` (a chat model,
12
- // `openai/model-id` or `anthropic/model-id`), or else MODEL, or else
13
- // openai/gpt-6-sol, with OPENAI_API_KEY.
14
- //
15
- // The handler is not replayed: a retried attempt (a crash, a lost connection)
16
- // runs again from the start, and LangGraph carries on from the last step it
17
- // stored:
18
- // - Each step is stored before the next starts (`durability: 'sync'`), in
19
- // order with everything else the handler does. So the tool calls a model
20
- // made are stored before any tool runs, and a crash during the tools
21
- // resumes them with the same tool call ids, which a tool passes on to stay
22
- // idempotent.
23
- // - A tool's error fails the attempt, which Restate retries (the ToolNode
24
- // would hand it to the model as the tool's result); a call of a tool the
25
- // agent lacks, or with arguments that do not fit, is the model's to fix.
26
- // - A message is answered once per invocation: the graph records each answer
27
- // in its state, and a retried attempt returns it.
28
- import * as restate from '@restatedev/sessions';
29
- import { AIMessage, HumanMessage, SystemMessage, ToolMessage } from '@langchain/core/messages';
1
+ import { AIMessage, HumanMessage, mapStoredMessagesToChatMessages, SystemMessage, ToolMessage, } from '@langchain/core/messages';
30
2
  import { tool, ToolInputParsingException } from '@langchain/core/tools';
31
- import { Annotation, END, isGraphInterrupt, MessagesAnnotation, START, StateGraph } from '@langchain/langgraph';
3
+ import { END, isGraphInterrupt, MessagesAnnotation, START, StateGraph } from '@langchain/langgraph';
32
4
  import { ToolNode, toolsCondition } from '@langchain/langgraph/prebuilt';
33
- import { AttemptEnded, CANCELLED, chatHandler, configured, fromTool, messagesHandler, ModelError, modelOf, nextPromptId, providerOf, refusalOf, stopSignalOf, storedAnswer, toolCallEnded, toolCallStarted, transcribing, Transcript, UNANSWERED, } from '../common.js';
34
- import { withOutput } from '../output.js';
5
+ import { chatHandler, configured, fromTool, ModelError, modelOf, providerOf, RETURNED_UNRECORDED, stopSignalOf, toolCallEnded, toolCallStarted, NO_ANSWER, } from '../common.js';
6
+ import { answerOnce } from '../conversation.js';
7
+ import { conversationView } from '../messages.js';
8
+ import { withChecked } from '../output.js';
35
9
  import { sessionObject } from '../object.js';
10
+ import { takeSteers } from '../steering.js';
36
11
  import { isTool, jsonSchemaOf } from '../tools.js';
37
12
  import { SqlCheckpointSaver } from './checkpointer.js';
13
+ import { handlerContext } from './context.js';
14
+ import { terminalOf } from './errors.js';
15
+ import { check as checkGraph, graphRun } from './graph.js';
38
16
  export { SqlCheckpointSaver };
39
- const State = Annotation.Root({
40
- ...MessagesAnnotation.spec,
41
- /** The id of the prompt being answered. */
42
- prompt: Annotation(),
43
- /** The answer to each prompt, by id. */
44
- answers: Annotation({ reducer: (a, b) => ({ ...a, ...b }), default: () => ({}) }),
45
- });
17
+ export { INTERRUPT } from './graph.js';
18
+ export * as nodes from './nodes.js';
46
19
  /**
47
- * The tools node: each tool call of the model's last message run by a
48
- * ToolNode, which answers the model with what is wrong when a call names a
49
- * tool the agent does not have, or arguments that do not fit (the model's to
50
- * fix: failing the attempt, every retry would meet the same call again). Any
51
- * other error of a tool fails the attempt, at once (the ToolNode would hand
52
- * it to the model too). The round is published as it starts and ends, for
53
- * the clients that follow the conversation.
20
+ * LangGraph's items: LangChain's messages, stored as their `toDict()`. A
21
+ * human message is said by the user; an AI message by the assistant, with
22
+ * its `tool_calls` as calls; a tool message is a result (an error if its
23
+ * status says so).
54
24
  */
55
- function toolsNode(ctx, tools) {
56
- return async (state, config) => {
57
- await toolCallStarted(ctx);
58
- // The first error fails the attempt at once, not once the other calls end.
59
- const { promise: failure, reject: failed } = Promise.withResolvers();
60
- failure.catch(() => { });
61
- const node = new ToolNode(tools.map((t) => failing(ctx, t, failed)), { handleToolErrors: true });
62
- const ran = await Promise.race([node.invoke(state, config), failure]);
63
- await toolCallEnded(ctx);
64
- return ran;
65
- };
66
- }
25
+ export const items = {
26
+ dump: (message) => JSON.stringify(message.toDict()),
27
+ load: (stored) => mapStoredMessagesToChatMessages([JSON.parse(stored)])[0],
28
+ prompt: (text) => new HumanMessage(text),
29
+ // A steered message, told apart from a prompt in the run's state by its id, which is stored with it.
30
+ steered: (text, steerId) => new HumanMessage({ content: text, id: `steer:${steerId}` }),
31
+ // A provider may refuse an empty message: an empty answer, as the model sees it later, says so.
32
+ reply: (text) => new AIMessage(text.trim() ? text : NO_ANSWER),
33
+ results: (results) => results.map(([call, output]) => new ToolMessage({
34
+ tool_call_id: call.id,
35
+ name: call.name,
36
+ content: output,
37
+ ...(output === RETURNED_UNRECORDED ? {} : { status: 'error' }),
38
+ })),
39
+ read: (message) => {
40
+ if (HumanMessage.isInstance(message))
41
+ return { said: ['user', message.text] };
42
+ if (AIMessage.isInstance(message)) {
43
+ const calls = (message.tool_calls ?? []).map((c) => ({ id: c.id ?? '', name: c.name, input: c.args }));
44
+ // Each reply is a message of its own, its tool calls' too.
45
+ return { said: ['assistant', message.text], calls };
46
+ }
47
+ if (ToolMessage.isInstance(message)) {
48
+ return { results: [{ id: message.tool_call_id, output: message.text, error: message.status === 'error' }] };
49
+ }
50
+ return {};
51
+ },
52
+ };
53
+ /** Whether `message` is a reply of the model with nothing in it: no text, no tool call, no other content. */
54
+ const blank = (message) => (message.tool_calls ?? []).length === 0 &&
55
+ (typeof message.content === 'string'
56
+ ? !message.content.trim()
57
+ : message.content.every((b) => b.type === 'text' && !(typeof b.text === 'string' && b.text.trim())));
58
+ /**
59
+ * `messages` as a provider takes them: a reply of the model with nothing in
60
+ * it (stored as it came) says so, as an empty answer does. Anthropic's API
61
+ * refuses an empty message but the last.
62
+ */
63
+ const sendable = (messages) => messages.map((m) => (AIMessage.isInstance(m) && blank(m) ? new AIMessage(NO_ANSWER) : m));
67
64
  /** `t`, its errors given to `failed`, but for its input's (arguments that do not fit) and LangGraph's interrupts. */
68
65
  const failing = (ctx, t, failed) => Object.create(t, {
69
66
  invoke: {
@@ -81,6 +78,42 @@ const failing = (ctx, t, failed) => Object.create(t, {
81
78
  },
82
79
  },
83
80
  });
81
+ /**
82
+ * The tools node: each tool call of the turn without a result run by a
83
+ * ToolNode, which answers the model with what is wrong when a call names a
84
+ * tool the agent does not have, or arguments that do not fit (the model's to
85
+ * fix: failing the attempt, every retry would meet the same call again). Each
86
+ * result is stored as it lands. Any other error of a tool fails the attempt,
87
+ * at once (the ToolNode would hand it to the model too). The round is
88
+ * published as it starts and ends, for the clients that follow the
89
+ * conversation.
90
+ */
91
+ function toolsNode(ctx, turn, tools) {
92
+ return async (_state, config) => {
93
+ await toolCallStarted(ctx);
94
+ // The first error fails the attempt at once, not once the other calls end.
95
+ const { promise: failure, reject } = Promise.withResolvers();
96
+ failure.catch(() => { });
97
+ let broken = false;
98
+ const failed = (error) => {
99
+ broken = true;
100
+ reject(error);
101
+ };
102
+ const node = new ToolNode(tools.map((t) => failing(ctx, t, failed)), { handleToolErrors: true });
103
+ const one = async (call) => {
104
+ const ran = (await node.invoke({ messages: [new AIMessage({ content: '', tool_calls: [call] })] }, config));
105
+ // A tool's error fails the attempt: the ToolNode's answer to the model of it is not the call's result.
106
+ if (broken)
107
+ return [];
108
+ await turn.append(...ran.messages);
109
+ return ran.messages;
110
+ };
111
+ const calls = turn.openCalls().map((c) => ({ id: c.id, name: c.name, args: c.input }));
112
+ const ran = await Promise.race([Promise.all(calls.map(one)), failure]);
113
+ await toolCallEnded(ctx);
114
+ return { messages: ran.flat() };
115
+ };
116
+ }
84
117
  /** `provider/model-id` as its provider and model id, for a provider the usual graph takes. */
85
118
  const providerOfModel = (named) => {
86
119
  const [provider, id] = providerOf(named);
@@ -99,7 +132,9 @@ const chatModel = async (named) => {
99
132
  const [provider, id] = providerOfModel(named);
100
133
  if (provider === 'openai') {
101
134
  const { ChatOpenAI } = await integration('@langchain/openai', () => import('@langchain/openai'));
102
- return new ChatOpenAI({ model: id });
135
+ // OpenAI's reasoning models take function tools only on the Responses API
136
+ // (on Chat Completions they refuse them, unless reasoning is off).
137
+ return new ChatOpenAI({ model: id, useResponsesApi: true });
103
138
  }
104
139
  const { ChatAnthropic } = await integration('@langchain/anthropic', () => import('@langchain/anthropic'));
105
140
  return new ChatAnthropic({ model: id });
@@ -115,148 +150,169 @@ async function integration(name, load) {
115
150
  throw new ModelError(`${name.replace('@langchain/', '')}/<model-id> models need ${name}: install it beside @restatedev/agents`);
116
151
  }
117
152
  }
118
- /** The agent's graph: `model`, calling `tools`. */
119
- function graph(ctx, model, tools, system) {
153
+ /**
154
+ * The agent's graph, for the latest turn of `conversation`: `model`, calling
155
+ * `tools`, from the tools if the turn has calls without results (a crash cut
156
+ * them off). The model node takes the messages steered to the turn first
157
+ * (`takeSteers`: it runs after the prompt or the tools' results), which go
158
+ * into its request and stay in the run's state, and stores each reply before
159
+ * it returns.
160
+ */
161
+ function toolLoop(ctx, conversation, model, tools, system) {
120
162
  if (!model.bindTools)
121
163
  throw new Error(`${model.getName()} does not call tools`);
122
164
  const withTools = model.bindTools(tools);
123
- return new StateGraph(State)
124
- .addNode('model', async ({ messages }) => ({
125
- messages: [await withTools.invoke(system ? [new SystemMessage(system), ...messages] : messages)],
126
- }))
127
- .addNode('tools', toolsNode(ctx, tools))
128
- .addNode('answer', ({ prompt, messages }) => ({ answers: { [prompt]: messages.at(-1).text } }))
129
- .addEdge(START, 'model')
130
- .addConditionalEdges('model', toolsCondition, { tools: 'tools', [END]: 'answer' })
131
- .addEdge('tools', 'model')
132
- .addEdge('answer', END);
165
+ const turn = conversation.turn;
166
+ return new StateGraph(MessagesAnnotation)
167
+ .addNode('model', async ({ messages }) => {
168
+ const steered = await takeSteers(ctx, conversation);
169
+ const asked = [...messages, ...steered];
170
+ const reply = await withTools.invoke(system ? [new SystemMessage(system), ...asked] : asked);
171
+ await turn.appendReply([reply]);
172
+ return { messages: [...steered, reply] };
173
+ })
174
+ .addNode('tools', toolsNode(ctx, turn, tools))
175
+ .addConditionalEdges(START, () => (turn.openCalls().length > 0 ? 'tools' : 'model'), {
176
+ tools: 'tools',
177
+ model: 'model',
178
+ })
179
+ .addConditionalEdges('model', toolsCondition, { tools: 'tools', [END]: END })
180
+ .addEdge('tools', 'model');
133
181
  }
134
- /** `t` as a LangChain tool: `t.run` checks the model's arguments itself. */
135
- const native = (t, ctx) => tool(async (args, { toolCall }) => {
182
+ /** How many steps a turn takes at most, by default: tool rounds enough for any turn, and the end of a run that loops. */
183
+ const RECURSION_LIMIT = 10_000;
184
+ /** The run of the agent: the graph from what the model sees, to the final reply's text. */
185
+ const runOf = (ctx, model, tools, system, recursionLimit = RECURSION_LIMIT) => async (conversation) => {
186
+ const turn = conversation.turn;
187
+ // A stored final reply is the answer: the model is not asked for it again.
188
+ const final = turn.finalReply();
189
+ if (final !== undefined)
190
+ return final;
191
+ const app = toolLoop(ctx, conversation, model, tools, system).compile();
192
+ try {
193
+ const { messages } = await app.invoke({ messages: sendable(conversation.history()) }, { signal: stopSignalOf(ctx), recursionLimit });
194
+ return messages.at(-1).text;
195
+ }
196
+ catch (error) {
197
+ // LangGraph's own errors (a run that loops, an invalid update) would be met again: they end the turn.
198
+ throw terminalOf(error) ?? error;
199
+ }
200
+ };
201
+ /**
202
+ * `t` as a LangChain tool: `t.run` checks the model's arguments itself. Its
203
+ * context is `ctx`, or else the graph's run's (context.ts).
204
+ */
205
+ const native = (t, ctx) => tool(async (args, config) => {
206
+ const { toolCall } = config;
136
207
  if (!toolCall?.id)
137
208
  throw new Error('a tool call without an id');
138
- return t.run(args, { ctx, callId: toolCall.id });
209
+ const at = ctx ?? handlerContext(config.context);
210
+ if (!at) {
211
+ throw new TypeError(`the tool ${t.name} runs in a graph that langgraph.agent({ graph }) runs, or that is invoked with the ` +
212
+ "handler's context: invoke(input, { context: ctx })");
213
+ }
214
+ return t.run(args, { ctx: at, callId: toolCall.id });
139
215
  },
140
216
  // What does not fit, for the model to fix: not only that something does not.
141
217
  { name: t.name, description: t.description, schema: jsonSchemaOf(t), verboseParsingErrors: true });
142
- /** {@link prompt}, answering with the agent's text. */
143
- const promptText = (ctx, text, options) => transcribing(ctx, () => transcribe(ctx.db, ctx.key), () => answerOnce(ctx, text, options));
144
- const answerOnce = async (ctx, text, { model, system, tools = [] }) => {
145
- const llm = typeof model === 'object' ? model : await chatModel(modelOf(model));
146
- // The latest checkpoint is all an agent resumes from: earlier ones would
147
- // store the conversation again at each step.
148
- const checkpointer = new SqlCheckpointSaver(ctx.db, { history: 'latest' });
149
- const app = graph(ctx, llm, tools.map((t) => (isTool(t) ? native(t, ctx) : t)), system).compile({ checkpointer });
150
- const config = { configurable: { thread_id: ctx.key }, durability: 'sync' };
151
- const id = nextPromptId(ctx);
152
- for (;;) {
153
- const state = await app.getState(config);
154
- const answer = state.values.answers?.[id];
155
- if (answer !== undefined)
156
- return storedAnswer(answer);
157
- // Finish an interrupted run first (this prompt's, after a crash), then
158
- // start this prompt's. A run is unfinished while its prompt has no
159
- // answer: `next` does not say, as it leaves out the steps whose writes
160
- // are stored.
161
- const { prompt: last, answers = {} } = state.values;
162
- const interrupted = last !== undefined && answers[last] === undefined;
163
- const turn = stopSignalOf(ctx);
164
- try {
165
- await app.invoke(interrupted ? null : { messages: [new HumanMessage(text)], prompt: id }, {
166
- ...config,
167
- signal: turn,
168
- });
169
- }
170
- catch (error) {
171
- // The attempt ended: it stops, and the next attempt goes on with the run.
172
- if (turn?.reason instanceof AttemptEnded)
173
- throw turn.reason;
174
- // Cancelled: the run ends, and the next prompt starts afresh.
175
- if (turn?.aborted || error instanceof restate.CancelledError) {
176
- await close(app, config, CANCELLED);
177
- throw turn?.aborted ? turn.reason : error;
178
- }
179
- // Refused for good (a wrong API key): the run ends unanswered, and
180
- // fails as terminal. An earlier prompt's, this one goes on.
181
- const refused = refusalOf(ctx, error);
182
- if (!refused)
183
- throw error;
184
- await close(app, config, UNANSWERED);
185
- if (!interrupted || last === id)
186
- throw refused;
187
- }
188
- }
189
- };
190
218
  /**
191
- * End the run of `app` that was cancelled or refused, as its `answer` node: a
192
- * result of `text` for each tool call of the last reply that has none, then
193
- * `text` as the reply and the prompt's answer. A run that stored no input
194
- * yet (cancelled at once) has nothing to end: the prompt the state has is
195
- * an earlier one, which has its answer.
219
+ * `given` as LangChain tools, for a graph of your own or LangChain's
220
+ * `createAgent`:
221
+ *
222
+ * const graph = createAgent({ model, tools: langgraph.tools([call(orders, 'status', { description: '…' })]) });
223
+ * const desk = langgraph.agent({ name: 'desk', graph });
224
+ *
225
+ * Restate's tools (`call`, `send`, `workflow`, `subagent`, `signal`) make
226
+ * their Restate calls once per tool call, even if a crash runs the tool call
227
+ * again: the model's reply, with the tool call's id, is checkpointed before
228
+ * the tools run. A `tool()` of your own runs your function, again after a
229
+ * crash, as do LangChain's tools, which are passed through. They take the
230
+ * handler's context from the graph's run (`langgraph.agent({ graph })` gives
231
+ * it; a handler of your own passes `context: ctx`).
196
232
  */
197
- async function close(app, config, text) {
198
- const { values } = await app.getState(config);
199
- if (values.prompt === undefined || values.answers?.[values.prompt] !== undefined)
233
+ export const tools = (given) => given.map((t) => (isTool(t) ? native(t) : t));
234
+ /** Throw a `TypeError` if `options` gives a graph of your own with what only the built-in loop takes, or the other way around. */
235
+ function checkOptions({ graph, model, system, tools: given, recursionLimit, context }) {
236
+ if (graph === undefined) {
237
+ if (context !== undefined)
238
+ throw new TypeError('context is the run context of a graph of your own: pass graph');
200
239
  return;
201
- const messages = (values.messages ?? []);
202
- const answered = new Set(messages.filter((m) => ToolMessage.isInstance(m)).map((m) => m.tool_call_id));
203
- const last = messages.findLast((m) => AIMessage.isInstance(m));
204
- const calls = (last && AIMessage.isInstance(last) ? (last.tool_calls ?? []) : []).filter((call) => call.id !== undefined && !answered.has(call.id));
205
- await app.updateState(config, {
206
- messages: [
207
- ...calls.map((call) => new ToolMessage({ tool_call_id: call.id, content: text, status: 'error' })),
208
- new AIMessage(text),
209
- ],
210
- answers: { [values.prompt]: text },
211
- }, 'answer');
240
+ }
241
+ const extra = Object.entries({ model, system, tools: given, recursionLimit }).flatMap(([name, value]) => value === undefined ? [] : [name]);
242
+ if (extra.length > 0) {
243
+ throw new TypeError(`a graph of your own has its own model and tools: it takes no ${extra.join(', ')}`);
244
+ }
245
+ checkGraph(graph);
212
246
  }
247
+ /** The chat model of `model`. */
248
+ const modelOfOptions = async (model) => typeof model === 'object' ? model : chatModel(modelOf(model));
213
249
  /**
214
250
  * Answer `text`, once: a retried attempt resumes the same prompt. Each prompt
215
- * of an invocation is a prompt of its own. The thread is the object's key.
251
+ * of an invocation is a prompt of its own.
216
252
  * With `output`, it answers with the value the agent replies with (see
217
- * output.ts), not its text.
253
+ * output.ts), not its text: a reply that is not one is asked again within
254
+ * its turn, once.
218
255
  */
219
- export const prompt = (ctx, text, options = {}) => withOutput(text, options, (t, o) => promptText(ctx, t, o));
256
+ export const prompt = (ctx, text, options = {}) => {
257
+ checkOptions(options);
258
+ const { graph, context } = options;
259
+ if (graph !== undefined) {
260
+ // The graph keeps its own history: the conversation loads the previous turn whole, for what closed it.
261
+ return withChecked(text, options, (t, _options, check) => answerOnce(ctx, t, items, graphRun(ctx, graph, context), { check, window: 1, budget: 0 }));
262
+ }
263
+ return withChecked(text, options, async (t, { model, system, tools: given = [], recursionLimit }, check, reminder) => answerOnce(ctx, t, items, runOf(ctx, await modelOfOptions(model), given.map((x) => (isTool(x) ? native(x, ctx) : x)), system, recursionLimit), { check, reminder }));
264
+ };
220
265
  /**
221
- * A chat handler: each message an invocation, the thread (the object's key)
222
- * in the object's database, with `options`, or the options a function of the
266
+ * A chat handler: each message an invocation, the conversation in the
267
+ * object's database, with `options`, or the options a function of the
223
268
  * invocation's context gives. It takes the message as plain text
224
269
  * (`curl -d 'Hi'`) or as a JSON string (`curl --json '"Hi"'`).
225
270
  */
226
271
  export const chat = (options = {}) => {
227
- if (typeof options === 'object' && typeof options.model !== 'object')
228
- providerOfModel(modelOf(options.model));
229
- return chatHandler(async (ctx, message) => prompt(ctx, message, await configured(options, ctx)));
272
+ if (typeof options === 'object') {
273
+ checkOptions(options);
274
+ if (options.graph === undefined && typeof options.model !== 'object')
275
+ providerOfModel(modelOf(options.model));
276
+ }
277
+ // The built-in loop takes steered messages at its steps; a graph of your own takes none (each is a turn of its
278
+ // own). Options a function gives are its message's: given once per attempt, to the turn's start and its prompt.
279
+ if (typeof options !== 'function') {
280
+ const steers = options.graph === undefined;
281
+ return chatHandler(async (ctx, message) => prompt(ctx, message, options), { steers });
282
+ }
283
+ const given = new WeakMap();
284
+ const optionsOf = (ctx) => {
285
+ let of = given.get(ctx);
286
+ if (!of)
287
+ given.set(ctx, (of = configured(options, ctx)));
288
+ return of;
289
+ };
290
+ return chatHandler(async (ctx, message) => prompt(ctx, message, await optionsOf(ctx)), {
291
+ steers: async (ctx) => (await optionsOf(ctx)).graph === undefined,
292
+ });
230
293
  };
231
294
  /**
232
- * A handler of the conversation as clients read it: a page at a time, or
233
- * what is new or changed since a cursor, from the log each change writes
234
- * (log.ts). It answers while a message is answered.
295
+ * A view of the conversation as clients read it: a page at a time, or what
296
+ * is new or changed since a cursor; `view: 'summary'` for each turn's
297
+ * message and answer. It answers while a message is answered.
235
298
  */
236
- export const messages = () => messagesHandler();
237
- /** The thread `key` in `db`, from its last checkpoint, as `messages` gives it. */
238
- const transcribe = async (db, key) => {
239
- const transcript = new Transcript();
240
- const saved = await new SqlCheckpointSaver(db).getTuple({ configurable: { thread_id: key } });
241
- for (const m of (saved?.checkpoint.channel_values.messages ?? [])) {
242
- if (HumanMessage.isInstance(m))
243
- transcript.say('user', m.text);
244
- if (AIMessage.isInstance(m)) {
245
- transcript.say('assistant', m.text);
246
- for (const call of m.tool_calls ?? [])
247
- transcript.call(call.id ?? '', call.name, call.args);
248
- }
249
- if (ToolMessage.isInstance(m))
250
- transcript.result(m.tool_call_id, m.text, m.status === 'error');
251
- }
252
- return transcript;
253
- };
299
+ export const messages = () => conversationView(items);
300
+ /**
301
+ * How an agent of `model` summarizes the earliest turns, past its budget:
302
+ * with its own model (`agent()` gives it; for an object of your own,
303
+ * `sessionObject`'s `summarize`).
304
+ */
305
+ export const summarizer = (model) => async (_ctx, request) => (await (await modelOfOptions(model)).invoke([new HumanMessage(request)])).text;
254
306
  /** An agent: a virtual object `name`, one per key, whose `chat` handler is {@link chat}, and `messages` {@link messages}. */
255
- export const agent = ({ name, description, schema, background, ...options }) => sessionObject({
307
+ export const agent = ({ name, description, schema, background, window, budget, summarize, ...options }) => sessionObject({
256
308
  name,
257
309
  description,
258
310
  schema,
259
311
  background,
312
+ window,
313
+ budget,
314
+ // A graph of your own keeps its own history, which the conversation's summaries do not reach.
315
+ summarize: summarize ?? (options.graph === undefined ? summarizer(options.model) : undefined),
260
316
  handlers: { chat: chat(options) },
261
317
  views: { messages: messages() },
262
318
  });
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/langgraph/index.ts"],"names":[],"mappings":"AAAA,0EAA0E;AAC1E,8DAA8D;AAC9D,EAAE;AACF,+EAA+E;AAC/E,EAAE;AACF,iFAAiF;AACjF,mFAAmF;AACnF,0EAA0E;AAC1E,EAAE;AACF,4EAA4E;AAC5E,0EAA0E;AAC1E,qEAAqE;AACrE,yCAAyC;AACzC,EAAE;AACF,8EAA8E;AAC9E,4EAA4E;AAC5E,UAAU;AACV,0EAA0E;AAC1E,2EAA2E;AAC3E,uEAAuE;AACvE,6EAA6E;AAC7E,gBAAgB;AAChB,0EAA0E;AAC1E,2EAA2E;AAC3E,2EAA2E;AAC3E,6EAA6E;AAC7E,oDAAoD;AACpD,OAAO,KAAK,OAAO,MAAM,sBAAsB,CAAC;AAIhD,OAAO,EAAE,SAAS,EAAoB,YAAY,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACjH,OAAO,EAAgC,IAAI,EAAE,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C,IAAI,CAAC;AAEnF,6HAA6H;AAC7H,MAAM,CAAC,MAAM,KAAK,GAAG,CAAkE,EACrF,IAAI,EACJ,WAAW,EACX,MAAM,EACN,UAAU,EACV,MAAM,EACN,MAAM,EACN,SAAS,EACT,GAAG,OAAO,EACiB,EAAE,EAAE,CAC/B,aAAa,CAAC;IACZ,IAAI;IACJ,WAAW;IACX,MAAM;IACN,UAAU;IACV,MAAM;IACN,MAAM;IACN,8FAA8F;IAC9F,SAAS,EAAE,SAAS,IAAI,CAAC,OAAO,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,UAAU,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;IAC7F,QAAQ,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,EAAE;IACjC,KAAK,EAAE,EAAE,QAAQ,EAAE,QAAQ,EAAE,EAAE;CAChC,CAAC,CAAC"}
@@ -0,0 +1,70 @@
1
+ import type * as restate from '@restatedev/sessions';
2
+ import type { LangGraphRunnableConfig } from '@langchain/langgraph';
3
+ /** A LangGraph node: it takes the state and the run's config, and returns the state's update. */
4
+ export type Node = (state: any, config: LangGraphRunnableConfig) => Promise<Record<string, unknown>>;
5
+ /** A service, virtual object or workflow, as its definition, of handlers `M`. */
6
+ type Target<M = unknown> = restate.ServiceDefinition<string, M> | restate.VirtualObjectDefinition<string, M> | restate.WorkflowDefinition<string, M>;
7
+ /**
8
+ * A node that waits for the signal `name` to the agent, and writes its value
9
+ * to `output`: a person's approval, say, or another system's result. The
10
+ * graph waits without holding a process, for as long as it takes. The
11
+ * agent's `pending` view lists the wait, with `input`'s value, and its
12
+ * `signal` view resolves it:
13
+ *
14
+ * graph.addNode('approve', nodes.waitForSignal('approval', { input: (s) => s.refund, output: 'approved' }))
15
+ */
16
+ export declare const waitForSignal: (name: string, { output, input }?: {
17
+ output?: string;
18
+ input?: (state: any) => unknown;
19
+ }) => Node;
20
+ /** What a node that calls a handler takes. */
21
+ interface CallOptions {
22
+ /** The state field that gets the result; none to write nothing. */
23
+ output?: string;
24
+ /** The handler's input, from the state; none for a handler that takes none. */
25
+ input?: (state: any) => unknown;
26
+ /** The key to call, from the state: for a virtual object's or a workflow's handler, and only for those. */
27
+ key?: (state: any) => string;
28
+ }
29
+ /**
30
+ * A node that calls `handler` of `target` (a service, virtual object or
31
+ * workflow), and writes its result to `output`:
32
+ *
33
+ * graph.addNode('status', nodes.call(orders, 'status', { input: (s) => s.order, key: (s) => s.customer, output: 'status' }))
34
+ */
35
+ export declare const call: <M>(target: Target<M>, handler: keyof M & string, options?: CallOptions) => Node;
36
+ /**
37
+ * A node that sends to `handler` of `target`, without waiting for it to run,
38
+ * after `delay` if given (such as `{ days: 1 }`). It writes nothing:
39
+ *
40
+ * graph.addNode('remind', nodes.send(checkins, 'remind', { input: (s) => s.checkin, delay: { days: 1 } }))
41
+ */
42
+ export declare const send: <M>(target: Target<M>, handler: keyof M & string, options?: Omit<CallOptions, 'output'> & {
43
+ delay?: restate.Duration;
44
+ }) => Node;
45
+ /**
46
+ * A node that runs the workflow `target` (its `run` handler) to the end, and
47
+ * writes its result to `output`. The workflow's id is `key`'s, or one of the
48
+ * node's own, made of the agent's key and the node's task:
49
+ *
50
+ * graph.addNode('ship', nodes.workflow(shipping, { input: (s) => s.order, output: 'receipt' }))
51
+ */
52
+ export declare const workflow: (target: restate.WorkflowDefinition<string, {
53
+ run: unknown;
54
+ }>, { output, input, key }?: CallOptions) => Node;
55
+ /**
56
+ * A node that sends a message to another agent (or any virtual object with
57
+ * a handler that takes text), and writes its answer to `output`. The message
58
+ * goes to the agent's key `<this key>.<node name>` unless `key` gives one, so
59
+ * each run of the graph continues the same conversation with it:
60
+ *
61
+ * graph.addNode('research', nodes.subagent(researcher, { message: (s) => s.question, output: 'findings' }))
62
+ */
63
+ export declare const subagent: <M>(agent: restate.VirtualObjectDefinition<string, M>, { message, output, key, handler, }: {
64
+ message: (state: any) => string;
65
+ output?: string;
66
+ key?: (state: any) => string;
67
+ handler?: string;
68
+ }) => Node;
69
+ export {};
70
+ //# sourceMappingURL=nodes.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"nodes.d.ts","sourceRoot":"","sources":["../../src/langgraph/nodes.ts"],"names":[],"mappings":"AAyBA,OAAO,KAAK,KAAK,OAAO,MAAM,sBAAsB,CAAC;AACrD,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAIpE,iGAAiG;AAEjG,MAAM,MAAM,IAAI,GAAG,CAAC,KAAK,EAAE,GAAG,EAAE,MAAM,EAAE,uBAAuB,KAAK,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC,CAAC;AAErG,iFAAiF;AACjF,KAAK,MAAM,CAAC,CAAC,GAAG,OAAO,IACnB,OAAO,CAAC,iBAAiB,CAAC,MAAM,EAAE,CAAC,CAAC,GACpC,OAAO,CAAC,uBAAuB,CAAC,MAAM,EAAE,CAAC,CAAC,GAC1C,OAAO,CAAC,kBAAkB,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC;AAuD1C;;;;;;;;GAQG;AACH,eAAO,MAAM,aAAa,SAEjB,MAAM,sBAAqB;IAAE,MAAM,CAAC,EAAE,MAAM,CAAC;IAAC,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,OAAO,CAAA;CAAE,KAAQ,IAY3F,CAAC;AAEN,8CAA8C;AAC9C,UAAU,WAAW;IACnB,mEAAmE;IACnE,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,+EAA+E;IAE/E,KAAK,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,OAAO,CAAC;IAChC,2GAA2G;IAE3G,GAAG,CAAC,EAAE,CAAC,KAAK,EAAE,GAAG,KAAK,MAAM,CAAC;CAC9B;AAWD;;;;;GAKG;AACH,eAAO,MAAM,IAAI,GAAI,CAAC,UAAU,MAAM,CAAC,CAAC,CAAC,WAAW,MAAM,C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