managed-deepagents 0.10.7 → 0.10.8-dev.2

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 (212) hide show
  1. package/README.md +449 -89
  2. package/dist/agent-auth.d.ts +4 -2
  3. package/dist/agent-auth.d.ts.map +1 -1
  4. package/dist/agent-auth.js +3 -1
  5. package/dist/agent-auth.js.map +1 -1
  6. package/dist/channels/address.d.ts +13 -0
  7. package/dist/channels/address.d.ts.map +1 -0
  8. package/dist/channels/address.js +67 -0
  9. package/dist/channels/address.js.map +1 -0
  10. package/dist/channels/binding.d.ts +7 -0
  11. package/dist/channels/binding.d.ts.map +1 -1
  12. package/dist/channels/binding.js +28 -4
  13. package/dist/channels/binding.js.map +1 -1
  14. package/dist/channels/delivery.d.ts.map +1 -1
  15. package/dist/channels/delivery.js +13 -16
  16. package/dist/channels/delivery.js.map +1 -1
  17. package/dist/channels/github/app-setup.d.ts.map +1 -1
  18. package/dist/channels/github/app-setup.js +86 -3
  19. package/dist/channels/github/app-setup.js.map +1 -1
  20. package/dist/channels/github/index.d.ts +1 -6
  21. package/dist/channels/github/index.d.ts.map +1 -1
  22. package/dist/channels/github/index.js +191 -38
  23. package/dist/channels/github/index.js.map +1 -1
  24. package/dist/channels/github/schema.d.ts +9280 -1622
  25. package/dist/channels/github/schema.d.ts.map +1 -1
  26. package/dist/channels/github/schema.js +164 -0
  27. package/dist/channels/github/schema.js.map +1 -1
  28. package/dist/channels/github/types.d.ts +98 -36
  29. package/dist/channels/github/types.d.ts.map +1 -1
  30. package/dist/channels/http/endpoint.d.ts +33 -9
  31. package/dist/channels/http/endpoint.d.ts.map +1 -1
  32. package/dist/channels/http/endpoint.js +72 -18
  33. package/dist/channels/http/endpoint.js.map +1 -1
  34. package/dist/channels/http/http.d.ts +7 -0
  35. package/dist/channels/http/http.d.ts.map +1 -1
  36. package/dist/channels/http/http.js +273 -27
  37. package/dist/channels/http/http.js.map +1 -1
  38. package/dist/channels/http/index.d.ts.map +1 -1
  39. package/dist/channels/http/index.js +4 -5
  40. package/dist/channels/http/index.js.map +1 -1
  41. package/dist/channels/http/ingress.d.ts +44 -1
  42. package/dist/channels/http/ingress.d.ts.map +1 -1
  43. package/dist/channels/http/ingress.js +63 -0
  44. package/dist/channels/http/ingress.js.map +1 -1
  45. package/dist/channels/http/input-state.d.ts +7 -0
  46. package/dist/channels/http/input-state.d.ts.map +1 -0
  47. package/dist/channels/http/input-state.js +16 -0
  48. package/dist/channels/http/input-state.js.map +1 -0
  49. package/dist/channels/http/provider.d.ts +36 -7
  50. package/dist/channels/http/provider.d.ts.map +1 -1
  51. package/dist/channels/http/provider.js +46 -7
  52. package/dist/channels/http/provider.js.map +1 -1
  53. package/dist/channels/http/types.d.ts +13 -5
  54. package/dist/channels/http/types.d.ts.map +1 -1
  55. package/dist/channels/linear/index.d.ts +0 -5
  56. package/dist/channels/linear/index.d.ts.map +1 -1
  57. package/dist/channels/linear/index.js +94 -21
  58. package/dist/channels/linear/index.js.map +1 -1
  59. package/dist/channels/linear/schema.d.ts +20 -20
  60. package/dist/channels/linear/schema.d.ts.map +1 -1
  61. package/dist/channels/linear/schema.js +20 -1
  62. package/dist/channels/linear/schema.js.map +1 -1
  63. package/dist/channels/linear/types.d.ts +58 -49
  64. package/dist/channels/linear/types.d.ts.map +1 -1
  65. package/dist/channels/reply.d.ts +28 -0
  66. package/dist/channels/reply.d.ts.map +1 -0
  67. package/dist/channels/reply.js +37 -0
  68. package/dist/channels/reply.js.map +1 -0
  69. package/dist/channels/resolve-user.d.ts +3 -2
  70. package/dist/channels/resolve-user.d.ts.map +1 -1
  71. package/dist/channels/resolve-user.js +5 -4
  72. package/dist/channels/resolve-user.js.map +1 -1
  73. package/dist/channels/run-input.d.ts +120 -10
  74. package/dist/channels/run-input.d.ts.map +1 -1
  75. package/dist/channels/run-input.js +233 -16
  76. package/dist/channels/run-input.js.map +1 -1
  77. package/dist/channels/runtime.d.ts +10 -3
  78. package/dist/channels/runtime.d.ts.map +1 -1
  79. package/dist/channels/runtime.js +15 -1
  80. package/dist/channels/runtime.js.map +1 -1
  81. package/dist/channels/schedule-delivery.d.ts +2 -2
  82. package/dist/channels/schedule-delivery.d.ts.map +1 -1
  83. package/dist/channels/slack/events.d.ts +176 -63
  84. package/dist/channels/slack/events.d.ts.map +1 -1
  85. package/dist/channels/slack/events.js +153 -4
  86. package/dist/channels/slack/events.js.map +1 -1
  87. package/dist/channels/slack/files.d.ts +6 -3
  88. package/dist/channels/slack/files.d.ts.map +1 -1
  89. package/dist/channels/slack/files.js +4 -1
  90. package/dist/channels/slack/files.js.map +1 -1
  91. package/dist/channels/slack/index.d.ts +60 -29
  92. package/dist/channels/slack/index.d.ts.map +1 -1
  93. package/dist/channels/slack/index.js +134 -56
  94. package/dist/channels/slack/index.js.map +1 -1
  95. package/dist/channels/trigger/conversation.d.ts +8 -3
  96. package/dist/channels/trigger/conversation.d.ts.map +1 -1
  97. package/dist/channels/trigger/conversation.js +101 -12
  98. package/dist/channels/trigger/conversation.js.map +1 -1
  99. package/dist/channels/trigger/http.d.ts +48 -8
  100. package/dist/channels/trigger/http.d.ts.map +1 -1
  101. package/dist/channels/trigger/http.js +324 -47
  102. package/dist/channels/trigger/http.js.map +1 -1
  103. package/dist/channels/trigger/ingress.d.ts +68 -2
  104. package/dist/channels/trigger/ingress.d.ts.map +1 -1
  105. package/dist/channels/trigger/ingress.js +124 -1
  106. package/dist/channels/trigger/ingress.js.map +1 -1
  107. package/dist/channels/trigger/transport.d.ts +2 -0
  108. package/dist/channels/trigger/transport.d.ts.map +1 -1
  109. package/dist/channels/trigger/transport.js +5 -1
  110. package/dist/channels/trigger/transport.js.map +1 -1
  111. package/dist/channels/trigger/types.d.ts +49 -0
  112. package/dist/channels/trigger/types.d.ts.map +1 -1
  113. package/dist/channels/trigger/types.js +21 -0
  114. package/dist/channels/trigger/types.js.map +1 -1
  115. package/dist/channels/types.d.ts +205 -1
  116. package/dist/channels/types.d.ts.map +1 -1
  117. package/dist/channels/types.js +27 -0
  118. package/dist/channels/types.js.map +1 -1
  119. package/dist/channels/warnings.d.ts +8 -0
  120. package/dist/channels/warnings.d.ts.map +1 -0
  121. package/dist/channels/warnings.js +17 -0
  122. package/dist/channels/warnings.js.map +1 -0
  123. package/dist/connectors/mcp/index.d.ts.map +1 -1
  124. package/dist/connectors/mcp/index.js +12 -4
  125. package/dist/connectors/mcp/index.js.map +1 -1
  126. package/dist/connectors/mcp/instructions.d.ts +30 -0
  127. package/dist/connectors/mcp/instructions.d.ts.map +1 -0
  128. package/dist/connectors/mcp/instructions.js +150 -0
  129. package/dist/connectors/mcp/instructions.js.map +1 -0
  130. package/dist/connectors/mcp/schema.d.ts.map +1 -1
  131. package/dist/connectors/mcp/schema.js +2 -1
  132. package/dist/connectors/mcp/schema.js.map +1 -1
  133. package/dist/connectors/mcp/types.d.ts +10 -0
  134. package/dist/connectors/mcp/types.d.ts.map +1 -1
  135. package/dist/index.d.ts +9 -6
  136. package/dist/index.d.ts.map +1 -1
  137. package/dist/index.js +2 -0
  138. package/dist/index.js.map +1 -1
  139. package/dist/ingress/runs.d.ts +3 -0
  140. package/dist/ingress/runs.d.ts.map +1 -1
  141. package/dist/ingress/runs.js +34 -16
  142. package/dist/ingress/runs.js.map +1 -1
  143. package/dist/memory/define-memory.d.ts +4 -2
  144. package/dist/memory/define-memory.d.ts.map +1 -1
  145. package/dist/memory/define-memory.js +4 -2
  146. package/dist/memory/define-memory.js.map +1 -1
  147. package/dist/namespaces.d.ts +2 -3
  148. package/dist/namespaces.d.ts.map +1 -1
  149. package/dist/namespaces.js +1 -1
  150. package/dist/namespaces.js.map +1 -1
  151. package/dist/run-context.d.ts +8 -0
  152. package/dist/run-context.d.ts.map +1 -1
  153. package/dist/run-context.js +5 -0
  154. package/dist/run-context.js.map +1 -1
  155. package/dist/run-ending-error.d.ts +16 -0
  156. package/dist/run-ending-error.d.ts.map +1 -0
  157. package/dist/run-ending-error.js +16 -0
  158. package/dist/run-ending-error.js.map +1 -0
  159. package/dist/runtime/auth.d.ts +1 -0
  160. package/dist/runtime/auth.d.ts.map +1 -1
  161. package/dist/runtime/auth.js +1 -1
  162. package/dist/runtime/auth.js.map +1 -1
  163. package/dist/runtime/backend.d.ts.map +1 -1
  164. package/dist/runtime/backend.js +7 -1
  165. package/dist/runtime/backend.js.map +1 -1
  166. package/dist/runtime/index.d.ts.map +1 -1
  167. package/dist/runtime/index.js +4 -1
  168. package/dist/runtime/index.js.map +1 -1
  169. package/dist/runtime/managed-thread.d.ts +6 -0
  170. package/dist/runtime/managed-thread.d.ts.map +1 -1
  171. package/dist/runtime/managed-thread.js +38 -2
  172. package/dist/runtime/managed-thread.js.map +1 -1
  173. package/dist/runtime/memory/policy.d.ts.map +1 -1
  174. package/dist/runtime/memory/policy.js +24 -5
  175. package/dist/runtime/memory/policy.js.map +1 -1
  176. package/dist/runtime/run-input.d.ts +1 -0
  177. package/dist/runtime/run-input.d.ts.map +1 -1
  178. package/dist/runtime/sandbox-manager.d.ts +27 -3
  179. package/dist/runtime/sandbox-manager.d.ts.map +1 -1
  180. package/dist/runtime/sandbox-manager.js +188 -22
  181. package/dist/runtime/sandbox-manager.js.map +1 -1
  182. package/dist/runtime/schedule-auth.d.ts +11 -5
  183. package/dist/runtime/schedule-auth.d.ts.map +1 -1
  184. package/dist/runtime/schedule-auth.js +37 -12
  185. package/dist/runtime/schedule-auth.js.map +1 -1
  186. package/dist/runtime/thread-handoff.d.ts +16 -0
  187. package/dist/runtime/thread-handoff.d.ts.map +1 -0
  188. package/dist/runtime/thread-handoff.js +24 -0
  189. package/dist/runtime/thread-handoff.js.map +1 -0
  190. package/dist/runtime/thread-record.d.ts +4 -0
  191. package/dist/runtime/thread-record.d.ts.map +1 -1
  192. package/dist/runtime/thread-record.js +4 -0
  193. package/dist/runtime/thread-record.js.map +1 -1
  194. package/dist/runtime-schedules.d.ts +2 -2
  195. package/dist/runtime-schedules.d.ts.map +1 -1
  196. package/dist/runtime-schedules.js +3 -1
  197. package/dist/runtime-schedules.js.map +1 -1
  198. package/dist/sandbox.d.ts +12 -0
  199. package/dist/sandbox.d.ts.map +1 -1
  200. package/dist/sandbox.js +5 -0
  201. package/dist/sandbox.js.map +1 -1
  202. package/dist/schedules.d.ts +33 -14
  203. package/dist/schedules.d.ts.map +1 -1
  204. package/dist/schedules.js +32 -1
  205. package/dist/schedules.js.map +1 -1
  206. package/dist/telemetry/run.d.ts +2 -1
  207. package/dist/telemetry/run.d.ts.map +1 -1
  208. package/dist/telemetry/run.js.map +1 -1
  209. package/dist/tool-errors.d.ts.map +1 -1
  210. package/dist/tool-errors.js +10 -5
  211. package/dist/tool-errors.js.map +1 -1
  212. package/package.json +7 -7
package/README.md CHANGED
@@ -197,10 +197,14 @@ export const memory = defineMemory({
197
197
 
198
198
  Omit a layer to disable it. A layer with no `allow` callback uses its default
199
199
  policy. Agent memory is shared across callers and is available by default.
200
- User memory requires a trusted person and defaults to managed Slack one-to-one
201
- DMs (`context.channel.rawEvent.channel_type == "im"`). Shared conversations,
202
- missing event data, and direct API runs get no user mount unless an authored
203
- policy allows it.
200
+ User memory requires a trusted person. By default it is mounted in two private
201
+ settings: managed Slack one-to-one DMs
202
+ (`context.channel.rawEvent.channel_type == "im"`), and direct API runs by a
203
+ caller who signed in with their own credential (such as a validated token) on a
204
+ thread no channel recorded. Shared conversations, missing event data, scheduled
205
+ runs, and trusted-backend runs get no user mount unless an authored policy
206
+ allows it: a trusted backend vouches for a user ID, but MDA cannot see who the
207
+ backend shows the reply to.
204
208
 
205
209
  For compatibility, an autodiscovered root declaration can still use a sync or
206
210
  async `allow(context)` callback to replace its default policy. `allow` is
@@ -281,6 +285,7 @@ runtime
281
285
  .provider // Provider label, such as slack
282
286
  .event // Typed MDA delivery, or null
283
287
  .rawEvent // Optional original provider payload
288
+ .address // The provider conversation, typed per provider
284
289
  .post(...) // Present when sending is supported
285
290
  .sender // The participant who sent the latest event, or null
286
291
  .participants // The people on the thread: { id, role }
@@ -320,8 +325,21 @@ no message started still have it: a run LangSmith Studio resumes, and a
320
325
  scheduled run on the thread. In those runs `origin.channel.event` is `null` (a
321
326
  scheduled run gets a `schedule` event) and there is no `rawEvent`. The channel's
322
327
  facts are available even when it cannot send. `post` uses a private, verified
323
- reply target. The channel helper does not expose the target or let callers
324
- replace it.
328
+ reply target, which callers can't replace. `address` is where the channel
329
+ posts: the conversation that `post` and the run's answers go to. It is on
330
+ `origin.channel` because a channel thread answers where it came from, so
331
+ `address` names the origin conversation, in every run of the thread, typed by
332
+ `provider`:
333
+
334
+ - Slack: `conversationId` (Slack's `channel`) and `threadTs` (Slack's
335
+ `thread_ts`).
336
+ - GitHub: `repository` (`owner/name`) and the issue or pull request `number`.
337
+ - Linear: `organizationId`, `issueId`, and `identifier`, `commentId` or
338
+ `sessionId` when the conversation has one.
339
+
340
+ In a scheduled run that starts a new thread, `post` posts at top level, so
341
+ `address` has no `threadTs`, `commentId` or `sessionId`. `address` is absent for a
342
+ channel without a typed address, such as `channels.http()`.
325
343
 
326
344
  ```ts
327
345
  const channel = runtime.thread?.origin?.channel;
@@ -354,7 +372,7 @@ It rejects native payloads and content it cannot send. For channels that support
354
372
  native messages, set `type` to `"native"` and supply the JSON in `native`.
355
373
  For content messages, set `type` to `"content"` and supply `content`.
356
374
  Supply only the matching payload. Native JSON has no extra provider or payload
357
- wrapper. The channel helper has no `address`, `update`, or destination override.
375
+ wrapper. A message to `post` has no `address`, `update`, or destination override.
358
376
  A post sends an additional message; the normal final agent reply remains automatic.
359
377
 
360
378
  On Slack, `post(message, { newThread: true })` posts at top level in the same
@@ -366,10 +384,36 @@ person. The result also has `threadId` and, on Slack, the message `url`:
366
384
  ```ts
367
385
  const posted = await runtime.thread?.origin?.channel.post?.(
368
386
  { type: "content", content: "Haiku about mango" },
369
- { newThread: true, run: { messages: [...history, new HumanMessage("Go on.")] } }
387
+ {
388
+ newThread: true,
389
+ run: { messages: [...history, new HumanMessage("Go on.")] },
390
+ }
391
+ );
392
+ ```
393
+
394
+ To move the conversation instead, add `handOff: true`. The new Slack thread
395
+ takes the current run's thread, with its history: replies, Stop and decision
396
+ buttons there reach it, and `threadId` is the current thread's. The rest of
397
+ the run answers, and waits on decisions, in the new Slack thread too, and
398
+ `origin` is the new Slack thread's conversation from then on. MDA posts "This
399
+ conversation moved to a new thread", with a link to it, in the old Slack thread.
400
+ A later message there starts no run: MDA answers that the conversation moved,
401
+ unless the channel's handler replies first. Only a channel conversation's run
402
+ can hand off its thread, and not together with `run`:
403
+
404
+ ```ts
405
+ await runtime.thread?.origin?.channel.post?.(
406
+ { type: "content", content: "Moved here from the old thread." },
407
+ { newThread: true, handOff: true }
370
408
  );
371
409
  ```
372
410
 
411
+ Add `to` to start the new thread in another conversation of the same channel,
412
+ such as another Slack channel the app is in: a `ChannelAddress` of the origin's
413
+ provider with no thread, for example
414
+ `{ provider: "slack", conversationId: "C0123456789" }`. It works with `run`
415
+ and with `handOff`.
416
+
373
417
  Managed Slack channels save incoming files under `/workspace/attachments/` and
374
418
  add `upload_files(paths)` so the agent can attach completed workspace files
375
419
  to its reply. This requires a managed sandbox.
@@ -439,6 +483,43 @@ alias for the tool type. MDA adds `serverInfo`, `channel`, `backend`, and
439
483
  but the type marks it optional so annotated hooks still match LangChain's native
440
484
  runtime types.
441
485
 
486
+ ## Tool errors
487
+
488
+ MDA returns an error thrown by a tool to the model as that tool's result, so the
489
+ model can act on it, and the run continues. Throw a `RunEndingError` subclass to
490
+ end the run instead, from a tool or from your own middleware's `wrapToolCall`.
491
+ Use it for errors no later call can get past, such as a sandbox that stopped
492
+ answering. To end the run on an error you don't own, throw yours with it as the
493
+ `cause`:
494
+
495
+ ```ts
496
+ import { RunEndingError } from "managed-deepagents";
497
+ import { createMiddleware } from "langchain";
498
+ import { LangSmithSandboxConnectionError } from "langsmith/sandbox";
499
+
500
+ class SandboxGoneError extends RunEndingError {}
501
+
502
+ const sandboxErrors = createMiddleware({
503
+ name: "SandboxErrors",
504
+ wrapToolCall: async (request, handler) => {
505
+ try {
506
+ return await handler(request);
507
+ } catch (error) {
508
+ if (error instanceof LangSmithSandboxConnectionError) {
509
+ throw new SandboxGoneError(error.message, { cause: error });
510
+ }
511
+ throw error;
512
+ }
513
+ },
514
+ });
515
+ ```
516
+
517
+ MDA's own errors that end the run are subclasses too: a person who has not
518
+ connected an account the tool needs (`CredentialAuthorizationRequiredError`)
519
+ ends the run, so they can connect it. So `error instanceof RunEndingError` tells
520
+ your middleware whether MDA ends the run on an error. Errors in a sync subagent's tools work the same way: one it
521
+ can act on goes to the subagent's model, and a `RunEndingError` ends the whole run.
522
+
442
523
  ## Slack channels
443
524
 
444
525
  `channels.slack(...)` receives Slack messages through Trigger Server. Each
@@ -468,12 +549,12 @@ By default every message that reaches the app starts a run with the message.
468
549
  import { channels } from "managed-deepagents";
469
550
 
470
551
  export const channel = channels.slack({
471
- name: "Support Bot",
552
+ app: { name: "Support Bot" },
472
553
  triggerMode: "thread",
473
554
  onEvent: {
474
555
  mention: (event, thread) => [
475
- event.text,
476
556
  {
557
+ input: event.text,
477
558
  context: { ticket: thread.id },
478
559
  metadata: { slack_channel: event.channelId },
479
560
  },
@@ -486,6 +567,15 @@ export const channel = channels.slack({
486
567
  });
487
568
  ```
488
569
 
570
+ `app` is the Slack app deploy sets up, as `channels.github` and
571
+ `channels.linear` take theirs: its `name`, `description`, `icon` (a path
572
+ relative to `channels/`) and `backgroundColor`. Setting them at the top level
573
+ of `channels.slack(...)` still works but is deprecated and will be removed in
574
+ 0.12, and can't be combined with `app`. `ignoreBots` (default `true`, as on
575
+ `channels.linear`) ignores other bots' messages; with `false`, a bot's message
576
+ reaches the agent as a person's would in its `triggerMode`. `allowBotTriggers`
577
+ is its deprecated opposite, also removed in 0.12.
578
+
489
579
  The keys are `mention`, a channel message that @-mentions the app;
490
580
  `directMessage`; and `message`, any other channel message, which only
491
581
  `triggerMode` `"thread"` or `"all"` delivers. Under those modes Slack sends a
@@ -501,13 +591,21 @@ thread's mention, the thread's later replies start nothing until someone
501
591
  mentions the agent there again.
502
592
 
503
593
  A handler gets the message (`text`, `userId`, `channelId`, `messageTs`,
504
- `threadTs`, `files`, Slack's own event as `payload`, and `actor`) and its
505
- thread (`id`, `sourceThreadKey`, `channel.name`). It returns the run's input, as
506
- `agent.invoke` takes it, optionally with `context`, `metadata` and `webhook`
507
- as `[input, options]`, as the GitHub and Linear handlers do. `null` or
508
- `undefined` starts no run, and the app neither reacts nor replies. A handler
509
- that throws, or returns input the channel can't start, starts no run either;
510
- the error is logged without its message. The message's blocks and attachments
594
+ `threadTs`, `files`, Slack's own event as `payload`, `actor`, and `teamId`, the
595
+ workspace your app is installed in) and its thread (`id`, `sourceThreadKey`,
596
+ `channel.name`). `await thread.getState()` reads the thread's state as Agent
597
+ Server's `threads.getState` does (its `values`, such as `messages`, as its last
598
+ run left them, `next` and `tasks`), or `undefined` before any run. It returns the run's input,
599
+ as `agent.invoke` takes it, or, to also set run options such as `context`,
600
+ `metadata` or `webhook`, a list of runs `{ input, ...options }`, as the GitHub
601
+ and Linear handlers do. `null` or
602
+ `undefined` starts no run, and the app neither reacts nor replies. Trigger
603
+ Server gets its answer before MDA asks the handler, so a slow handler never
604
+ times out the delivery. A handler that throws, or returns input the channel
605
+ can't start, starts no run either; the error is logged without its message.
606
+ To try a failing call again, retry it inside the handler with the backoff you
607
+ choose; a delivery whose handler is still running or waiting when the
608
+ deployment restarts is lost. The message's blocks and attachments
511
609
  are added to the handler's messages, and its files still reach
512
610
  `/workspace/attachments/`. Interrupt resumes don't go through `onEvent`; a
513
611
  click on a button the agent posted does, as `interaction`: see
@@ -532,6 +630,78 @@ already runs: `enqueue` (the default) waits for the run and starts after it,
532
630
  `interrupt` cancels the run, keeping its progress, and starts at once,
533
631
  `rollback` cancels it and discards its progress, and `reject` starts nothing.
534
632
 
633
+ A handler may also choose each run's thread, strategy and `autoPost`, as on
634
+ GitHub, Linear and HTTP channels: its list may hold several runs, at most one
635
+ on the Slack thread's own conversation:
636
+
637
+ ```ts
638
+ onEvent: {
639
+ message: (event) => {
640
+ if (event.text.startsWith("<@")) return event.text; // a mention interrupts
641
+ if (channelSessionId)
642
+ // One session for the whole channel: every Slack thread's message waits its turn.
643
+ return [
644
+ {
645
+ input: event.text,
646
+ thread: { mode: "persistent", id: channelSessionId },
647
+ multitaskStrategy: "enqueue",
648
+ autoPost: true,
649
+ },
650
+ ];
651
+ return [{ input: event.text, multitaskStrategy: "enqueue" }]; // waits behind the running run
652
+ },
653
+ },
654
+ ```
655
+
656
+ A run on a thread of the handler's choosing shows its status, reaction and
657
+ decisions in the Slack thread its message came from, and posts its answer
658
+ there only with `autoPost: true`, or an address naming that Slack thread, such
659
+ as a run's `runtime.thread.origin.channel.address` passed back. A run on
660
+ the Slack thread's own conversation (without `thread`, or on
661
+ `{ mode: "persistent", id: thread.id }`) posts as the channel's `autoPost`
662
+ says, unless its own `autoPost` says otherwise. Stop in that Slack thread
663
+ cancels the runs its messages started, on the conversation and on the
664
+ handler's threads; another Slack thread's run on a shared thread goes on. A
665
+ decision a run there waits on is answered from the Slack thread that started
666
+ the run. Every thread a channel's handlers choose is owned by the channel, not
667
+ by one Slack thread. An ephemeral thread is deleted once its run ends, unless
668
+ it waits on a decision.
669
+
670
+ An `edit`, `delete` or `reaction` handler takes what happened to a message: a
671
+ `SlackActivityEvent` with `messageTs`, `threadTs`, the message's `text` (as
672
+ edited, as it was before it was deleted, or as reacted to), `userId` (the author
673
+ for an edit or deletion, the person who reacted for a reaction), `reaction` and
674
+ `removed`, and Slack's event as `payload`. It starts only the run it returns:
675
+
676
+ ```ts
677
+ onEvent: {
678
+ mention: onMention,
679
+ reaction: (event) =>
680
+ event.reaction === "thumbsup" && !event.removed
681
+ ? [{ input: `<@${event.userId}> liked: ${event.text}`, multitaskStrategy: "enqueue" }]
682
+ : null,
683
+ },
684
+ ```
685
+
686
+ The channel asks Trigger Server for these events only when it has a handler for
687
+ their key, which needs an `mda` CLI that sends `forwardedEvents`. Trigger Server
688
+ forwards one only for a thread the channel already took a message from, unless
689
+ the channel takes every message (`triggerMode: "all"`) or it is in a direct
690
+ message, and never your agent's own edits or reactions. Reactions need the Slack
691
+ app's `reactions:read` scope: a LangSmith-managed app gets it at the next
692
+ deploy, after a reinstall the workspace may have to approve; a customer-owned
693
+ app's manifest has to add it.
694
+
695
+ A `shortcut` handler takes one of your Slack app's message shortcuts, used on a
696
+ message: `actionId` is the shortcut's `callback_id`, `userId` the person who used it,
697
+ and `payload` Slack's interaction payload, with its `response_url` to answer
698
+ them. Trigger Server forwards it wherever a person used it, as a mention. Your
699
+ app defines its shortcuts in its own settings; it needs the `commands` scope.
700
+
701
+ A `channel` handler takes a change to a channel itself: created, renamed,
702
+ archived, unarchived or deleted (`type` is Slack's event, `group_*` for a private
703
+ channel), with `channelId` and `teamId`. It names no message or thread.
704
+
535
705
  `event.actor` is the Slack user who sent the message, as Trigger Server read
536
706
  it from Slack's signed request: `{ provider: "slack", id, teamId }`. `teamId`
537
707
  is their own workspace: in a Slack Connect channel, someone from another
@@ -631,17 +801,19 @@ the background. The reply, errors and approvals still show.
631
801
  ### Replying from the agent
632
802
 
633
803
  The channel posts the agent's last reply in the thread once a run succeeds.
634
- `reply: "none"` leaves replying to the agent instead, for an agent that posts
635
- its own messages, with `runtime.channel.post` or its own Slack client, or
636
- that answers somewhere else:
804
+ `autoPost: false` leaves replying to the agent instead, for an agent that
805
+ posts its own messages, with `runtime.channel.post` or its own Slack client,
806
+ or that answers somewhere else:
637
807
 
638
808
  ```ts
639
- channels.slack({ reply: "none" });
809
+ channels.slack({ autoPost: false });
640
810
  ```
641
811
 
642
812
  Reactions, the status, Stop and `onFinish` work as before. `channels.linear`
643
- and `channels.http` take the same option. Deploying `reply: "none"` needs an
644
- `mda` CLI from this release; an older one refuses it.
813
+ and `channels.http` take the same option. The older `reply: "auto" | "none"`
814
+ still works, as `autoPost` `true` or `false`; set one of them. Deploying
815
+ `autoPost: false` needs an `mda` CLI from this release; an older one refuses
816
+ it.
645
817
 
646
818
  ### Buttons your agent posts
647
819
 
@@ -649,9 +821,7 @@ and `channels.http` take the same option. Deploying `reply: "none"` needs an
649
821
  Slack-specific, such as buttons, feedback buttons or a message the agent
650
822
  updates later, the agent posts with its own Slack client. The app's bot token
651
823
  is the agent connection `mda/slack-bot-token` (reading it as a user connection
652
- throws), and `runtime.channel.rawEvent`, the Slack event the run came from,
653
- names the thread: a message's own event, or a click's interaction payload,
654
- whose `container` says where the button was.
824
+ throws), and the channel's `address` names the conversation and its thread.
655
825
 
656
826
  ```ts
657
827
  import { WebClient } from "@slack/web-api";
@@ -661,15 +831,12 @@ import { connections, type ManagedToolRuntime } from "managed-deepagents";
661
831
 
662
832
  export const offerChoices = tool(
663
833
  async ({ question, choices }, runtime: ManagedToolRuntime) => {
664
- if (runtime.channel?.provider !== "slack") return "Not in Slack.";
665
- const raw = runtime.channel.rawEvent as Record<string, any> | undefined;
666
- const where = raw?.container ?? raw;
667
- const channel = where?.channel_id ?? where?.channel;
668
- const threadTs = where?.thread_ts ?? where?.message_ts ?? where?.ts;
834
+ const address = runtime.thread?.origin?.channel.address;
835
+ if (address?.provider !== "slack") return "Not in Slack.";
669
836
  const token = await connections.get("mda/slack-bot-token", { type: "agent" });
670
837
  await new WebClient(token).chat.postMessage({
671
- channel,
672
- thread_ts: threadTs,
838
+ channel: address.conversationId,
839
+ thread_ts: address.threadTs,
673
840
  text: question,
674
841
  blocks: [
675
842
  { type: "section", text: { type: "mrkdwn", text: question } },
@@ -842,23 +1009,39 @@ from Agent Auth are cached for up to 5 minutes. A matched event fails closed if
842
1009
  the bot ID is missing or invalid. Calling `channels.github()` without handlers preserves
843
1010
  receipt-only behavior and needs only the webhook secret.
844
1011
 
845
- Supported keys:
846
-
847
- - Issues: `issues.opened`, `issues.edited`, `issues.reopened`, `issues.labeled`,
848
- `issue_comment.created`, `issue_comment.edited`.
849
- - Pull requests: `pull_request.opened`, `pull_request.edited`,
850
- `pull_request.reopened`, `pull_request.ready_for_review`,
851
- `pull_request.converted_to_draft`, `pull_request.synchronize`,
852
- `pull_request.labeled`, `pull_request.closed`.
853
- - Reviews: `pull_request_review.submitted`, `pull_request_review.edited`,
854
- `pull_request_review.dismissed`, `pull_request_review_comment.created`,
855
- `pull_request_review_comment.edited`.
856
- - Code and CI: `push`, `status`, `check_run.completed`, `check_suite.completed`,
857
- `workflow_run.completed`. `push` and `status` have no action, so their key is
858
- the event name. A CI event continues a pull request's conversation when it
859
- ran for exactly one pull request.
1012
+ Supported keys are `<event>.<action>`, for every action GitHub sends of these
1013
+ events:
1014
+
1015
+ - `issues`: `opened`, `edited`, `reopened`, `closed`, `deleted`, `transferred`,
1016
+ `labeled`, `unlabeled`, `assigned`, `unassigned`, `locked`, `unlocked`,
1017
+ `milestoned`, `demilestoned`, `pinned`, `unpinned`, `typed`, `untyped`.
1018
+ - `issue_comment`: `created`, `edited`, `deleted`.
1019
+ - `pull_request`: `opened`, `edited`, `reopened`, `closed`, `ready_for_review`,
1020
+ `converted_to_draft`, `synchronize`, `labeled`, `unlabeled`, `assigned`,
1021
+ `unassigned`, `review_requested`, `review_request_removed`, `locked`,
1022
+ `unlocked`, `milestoned`, `demilestoned`, `enqueued`, `dequeued`,
1023
+ `auto_merge_enabled`, `auto_merge_disabled`.
1024
+ - `pull_request_review`: `submitted`, `edited`, `dismissed`.
1025
+ - `pull_request_review_comment`: `created`, `edited`, `deleted`.
1026
+ - `pull_request_review_thread`: `resolved`, `unresolved`. The payload's `thread`
1027
+ has the thread's `node_id` and its review `comments`. These need only
1028
+ `pull_requests: read`.
1029
+ - Code and CI: `push` and `status`, which have no action, so their key is the
1030
+ event name; `check_run`: `created`, `completed`, `rerequested`,
1031
+ `requested_action`; `check_suite`: `requested`, `rerequested`, `completed`;
1032
+ `workflow_run`: `requested`, `in_progress`, `completed`. A CI event continues
1033
+ a pull request's conversation when it ran for exactly one pull request.
860
1034
  - Merge queue: `merge_group.checks_requested`, `merge_group.destroyed`. A
861
1035
  merge group belongs to no conversation, so each delivery gets its own thread.
1036
+ - Installation: `installation.created`, `installation.deleted`, `installation.suspend`,
1037
+ `installation.unsuspend`, `installation.new_permissions_accepted`,
1038
+ `installation_repositories.added`, `installation_repositories.removed`.
1039
+ GitHub sends these to every App, so handling one needs no subscription or
1040
+ permission. They are about the installation, not a repository: the handler
1041
+ gets a `GitHubInstallationEvent`, with the `account` the App is installed on
1042
+ instead of a `repository`. A channel limited to `app.repositories` gets them
1043
+ too, each delivery gets its own thread, and `onReceived` and `onFinish`
1044
+ aren't called for them.
862
1045
 
863
1046
  GitHub sends no event for a mention, so each event lists the handles the
864
1047
  text it wrote mentions in `event.mentions`: the body of a new or edited
@@ -903,13 +1086,19 @@ nothing. The App's own activity is what the agent does with the App's token,
903
1086
  such as its comments, its pushes or a pull request it opened; set
904
1087
  `includeOwnEvents: true` to hand those to handlers too, with `event.fromApp`
905
1088
  set. A handler that answers comments or reviews then skips `event.fromApp`, or
906
- the agent answers itself. The request awaits the configured callback and run creation before
907
- acknowledgment (an endpoint's is asked after; see "Asking your service what to
908
- start"); synchronous and async callbacks are supported. A handler returns
909
- what `agent.invoke` takes: a nonblank string (one user message), a message such
910
- as `new HumanMessage(...)` with text or content blocks, state such as
911
- `{ messages: [...], todos: [] }`, or `[input, { context, metadata }]` to also
912
- set the run's context (`context.channel` is reserved) or metadata, such as
1089
+ the agent answers itself. Issues, comments, pull requests and reviews from other bots, such as
1090
+ Dependabot, are ignored too, as on Linear and Slack; set `ignoreBots: false` to
1091
+ let them start runs. CI, `push` and `merge_group` events still reach their
1092
+ handlers. GitHub gets its answer first; then MDA asks the configured handler,
1093
+ a callback or an endpoint (see "Asking your service what to start"), and starts
1094
+ the run, so a slow handler never times out the delivery. Synchronous and async
1095
+ callbacks are supported. A handler returns
1096
+ what `agent.invoke` takes, for one run on the event's conversation: a nonblank
1097
+ string (one user message), a message such as `new HumanMessage(...)` with text
1098
+ or content blocks, or state such as `{ messages: [...], todos: [] }`. To set
1099
+ run options, it returns a list of runs `{ input, ...options }` instead, where
1100
+ `input` is any of those. The options set the run's context
1101
+ (`context.channel` is reserved) or metadata, such as
913
1102
  `{ issue: "ENG-123" }` to find the run by in LangSmith. Metadata keys are
914
1103
  letters, digits, `_`, `.` or `-`. Keys the Agent Server and LangSmith set
915
1104
  are reserved: `mda_`, `langgraph_` and `ls_` keys, and ids such as
@@ -919,17 +1108,74 @@ metadata, values and any error) to `url`, as `runs.create({ webhook })` does;
919
1108
  http(s), without credentials in the URL.
920
1109
  The handler's second argument is the conversation's `thread`: `thread.id` is
921
1110
  the thread the run starts on, for context that names it, such as a token your
922
- backend signs for the thread.
923
- `null` or `undefined` skips without a thread or run.
924
- Other results and callback failures are safely logged and start nothing.
1111
+ backend signs for the thread. `await thread.getState()` reads the thread's
1112
+ state as Agent Server's `threads.getState` does, or `undefined` before any run,
1113
+ as on Slack and Linear; only a handler deciding an event can read it.
1114
+ `null` or `undefined` skips without a thread or run. GitHub posts no answer,
1115
+ so a GitHub handler has no `reply(message)`.
1116
+ Other results are safely logged and start nothing. So does a handler that
1117
+ throws: GitHub already has its answer, so the delivery isn't failed; MDA logs
1118
+ the error's type only. Nor is a delivery whose run can't start, for example
1119
+ while the Agent Server is briefly unavailable: `onFinish` gets `failed` with
1120
+ reason `start`.
1121
+ To try a failing call again, retry it inside the handler with the backoff
1122
+ you choose: the handler may take as long as it needs. A delivery whose
1123
+ handler is still running or waiting when the deployment restarts is lost.
925
1124
 
926
1125
  Each issue or pull request has one thread, so the agent keeps the conversation:
927
1126
  an issue, its comments, and a pull request with its reviews and review comments
928
1127
  continue the same thread, as does a workflow run for exactly one pull request.
929
1128
  Other events get a thread of their own. A redelivered webhook starts nothing,
930
- because each thread runs a delivery once. A comment that arrives while the agent
1129
+ because each thread runs a delivery once. The exception is an event whose only
1130
+ runs were on ephemeral threads, on a conversation that has no thread yet: those
1131
+ threads are deleted when their runs end, so a later redelivery starts them again. A comment that arrives while the agent
931
1132
  is still working waits for that run to finish, so it never skips a decision the
932
- run stops for. There is no automatic retry.
1133
+ run stops for. GitHub never redelivers on its own.
1134
+
1135
+ A list may hold several runs for one event, on threads the handler chooses
1136
+ (GitHub, Linear, HTTP and Slack channels):
1137
+
1138
+ ```ts
1139
+ "issue_comment.created": (event, thread) => [
1140
+ // The issue's conversation.
1141
+ { input: prompt },
1142
+ // A fresh thread, deleted once the run ends.
1143
+ { input: triage, thread: { mode: "ephemeral" } },
1144
+ // A thread your service keeps across events, by its UUID.
1145
+ {
1146
+ input: plan,
1147
+ thread: { mode: "persistent", id: planThreadId },
1148
+ multitaskStrategy: "interrupt",
1149
+ },
1150
+ ],
1151
+ ```
1152
+
1153
+ A run without `thread` starts on the thread the handler was given, the
1154
+ event's conversation, as does one on `{ mode: "persistent", id: thread.id }`;
1155
+ at most one run may. Otherwise `thread` is a `ThreadConfig`, as a schedule's:
1156
+ `{ mode: "ephemeral" }` or `{ mode: "persistent", id }`. `autoPost` says
1157
+ where a run posts its final answer: `true` where the event came from, `false`
1158
+ nowhere, or an address, such as the thread's
1159
+ `runtime.thread.origin.channel.address`, passed as it is. For now an address
1160
+ must be where the event came from; on Linear a run's answer posts nowhere
1161
+ else yet. GitHub posts no run's answer, so a GitHub run (`GitHubRun`) has no
1162
+ `autoPost`: the agent's tools post on GitHub. Without `autoPost`, the channel's `autoPost`
1163
+ decides for the conversation's run, and a run on another thread posts nothing.
1164
+ `multitaskStrategy` overrides the channel's for one run.
1165
+ On Slack, a run on a thread the handler chose may name the Slack thread it
1166
+ belongs to with `conversation`, a Slack address with its `threadTs`, such as a
1167
+ thread the handler just opened in the same app and workspace: its status, Stop
1168
+ button and decisions show there instead of where the event came from, Stop
1169
+ there stops it, and `autoPost: true` answers there (experimental).
1170
+ A persistent id must be a UUID; which ids an event may reach is yours to
1171
+ check. A delivery starts at most one run on each thread, so a resent one
1172
+ starts nothing there again, even if the handler now starts a different set of
1173
+ runs. The handler is asked once per delivery, before any thread is read, and
1174
+ not at all once the conversation has seen the delivery. While the conversation
1175
+ waits on a decision, the handler is still asked (on GitHub with
1176
+ `thread.interrupted` set): its runs on other threads start, and a run on the
1177
+ conversation is skipped, with the usual waiting notice. An empty list starts
1178
+ nothing.
933
1179
 
934
1180
  Handlers can call GitHub with a client such as Octokit and the App's
935
1181
  installation token from `connections.get("mda/github-token", { type: "agent" })`,
@@ -998,6 +1244,49 @@ supported. To act on
998
1244
  GitHub from a run (comment, label, open pull requests), give the agent a GitHub
999
1245
  MCP server in `tools/mcp.ts`.
1000
1246
 
1247
+ ### Forwarding deliveries to your backend
1248
+
1249
+ A backend that needs GitHub's events, including ones that never start a run,
1250
+ gets them through `forwardTo`: services, each a URL or a `Request` that also
1251
+ carries headers, such as an API key. No handler has to call it, and it gets
1252
+ events MDA has no type for too.
1253
+
1254
+ ```ts
1255
+ const backend = new Request(`${BACKEND_URL}/github/webhooks`, {
1256
+ headers: { "x-api-key": process.env.BACKEND_KEY! },
1257
+ });
1258
+
1259
+ export const channel = channels.github({
1260
+ onEvent: {
1261
+ "issues.opened": (e) => `Help with #${e.payload.issue.number}`,
1262
+ },
1263
+ forwardTo: [backend],
1264
+ });
1265
+ ```
1266
+
1267
+ - Once GitHub's signature checks out, MDA POSTs every delivery but `ping` to
1268
+ each service, before anything else reads it: whatever its event or action,
1269
+ whether or not a handler takes it, from any repository and any sender.
1270
+ - The body is GitHub's raw body, byte for byte. The headers are GitHub's own,
1271
+ unchanged: `Content-Type` and every `X-GitHub-*` and `X-Hub-*` header
1272
+ (`X-GitHub-Event`, `X-GitHub-Delivery`, `X-Hub-Signature-256` and any GitHub
1273
+ adds), but no other header the delivery arrived with. Then come the `Request`'s
1274
+ headers and the Standard Webhooks signature described in
1275
+ [Asking your service what to start](#asking-your-service-what-to-start), with
1276
+ the webhook ID `msg_<deliveryId>_forward`.
1277
+ - GitHub is answered only once every service answered 2xx, all asked at once,
1278
+ within 8 seconds. Then the delivery goes on as without `forwardTo`.
1279
+ - Any other answer, a redirect, a timeout or a network error answers GitHub
1280
+ HTTP 502 and starts no handler and no run, so GitHub marks the delivery
1281
+ failed. GitHub doesn't send it again on its own: redelivering it from the
1282
+ App's settings, or with GitHub's API, forwards and handles it again.
1283
+ - A channel can have `forwardTo` and no `onEvent`.
1284
+ - `forwardTo` adds no App permission and no webhook event: a service gets the
1285
+ events the App is subscribed to, which the channel's handlers decide.
1286
+
1287
+ The URL must be https, or plain http to a loopback host, and carry no
1288
+ credentials; a bad one throws when the channel is declared.
1289
+
1001
1290
  ### Setting up the GitHub App
1002
1291
 
1003
1292
  The first `mda deploy` of a GitHub channel asks which GitHub App it uses, as
@@ -1030,7 +1319,9 @@ To skip the questions, with or without a terminal, set these in the shell or
1030
1319
  `@me`, the personal account of whoever creates it.
1031
1320
  - `MDA_GITHUB_APP_ID`, `MDA_GITHUB_APP_PRIVATE_KEY_FILE` (the path to its
1032
1321
  `.pem` file) and `MDA_GITHUB_WEBHOOK_SECRET`: use this existing App instead.
1033
- Add `MDA_GITHUB_APP_INSTALLATION_ID` when it's installed in several accounts.
1322
+ Add `MDA_GITHUB_APP_INSTALLATION_ID` when it's installed in several accounts:
1323
+ the agent's token is minted on that installation, and each deploy renews it
1324
+ there when the channel's permissions change.
1034
1325
  - `MDA_GITHUB_WEBHOOK_SECRET` alone: the webhook secret of an existing App
1035
1326
  whose secret Agent Auth doesn't have yet.
1036
1327
  - `MDA_GITHUB_WEBHOOK_ELSEWHERE`: the URL an existing App's webhook keeps.
@@ -1085,6 +1376,9 @@ names them; an unknown key in `onEvent` throws. The channel verifies each delive
1085
1376
  and rejects deliveries older than a minute. It ignores events about teams
1086
1377
  outside `app.teams`, changes by other apps and integrations (set
1087
1378
  `ignoreBots: false` to keep them), and the app's own comments and changes.
1379
+ `onReceived(event, thread)` hears each handled delivery as it reaches its
1380
+ thread, after the channel acknowledges an agent session, as GitHub's does; a
1381
+ handler's `thread.getState()` reads the thread's state, as on GitHub and Slack.
1088
1382
 
1089
1383
  > **Experimental.** Agent sessions use Linear's Agents API, which is a
1090
1384
  > Developer Preview, so they may change as Linear changes it. Issue and
@@ -1103,6 +1397,17 @@ same link. Comments that a
1103
1397
  session already delivers, such as the mention itself and replies in the
1104
1398
  session, don't also reach a `Comment.create` handler.
1105
1399
 
1400
+ Linear gets its answer before MDA asks the handler, so a slow handler never
1401
+ times out the delivery. A handler that throws starts nothing, and Linear doesn't
1402
+ send the delivery again; the error is logged by type only. The same holds for a
1403
+ run that can't start, for example while the Agent Server is briefly
1404
+ unavailable: `onFinish` gets `failed` with reason `start`. In an agent session,
1405
+ the session hears at once that something went wrong, since its author waits;
1406
+ an issue gets no comment, since its handler may have skipped the event.
1407
+ To try a failing call again, retry it inside the handler with the backoff
1408
+ you choose: the handler may take as long as it needs. A delivery whose
1409
+ handler is still running or waiting when the deployment restarts is lost.
1410
+
1106
1411
  `app` also names the app deploy asks the admin to create: `name` (2-80
1107
1412
  characters, without "Linear"; defaults to the agent's name), `description`,
1108
1413
  and `icon`, a PNG or JPEG given as a path relative to `channels/` like the
@@ -1118,12 +1423,12 @@ it installs the app.
1118
1423
 
1119
1424
  The channel reads the webhook signing secret from Agent Auth, or from
1120
1425
  `LINEAR_WEBHOOK_SECRET` when set. It acts as the app through the deployment's
1121
- Agent Auth app, whose OAuth connection is `mda/linear-app/<deployment-id>`,
1122
- installed with `actor=app`; read its token with
1426
+ Agent Auth app, whose OAuth connection is `mda/linear-app/<deployment-id>`
1427
+ and whose token acts as the app; read its token with
1123
1428
  `await connections.get("mda/linear-token", { type: "agent" })` to call Linear's API from tools.
1124
1429
 
1125
- `reply: "none"` leaves the run's answer to the agent: the channel doesn't post
1126
- it as a comment or in the session. Session acknowledgements, Stop and error
1430
+ `autoPost: false` leaves the run's answer to the agent: the channel doesn't
1431
+ post it as a comment or in the session. Session acknowledgements, Stop and error
1127
1432
  notices still post.
1128
1433
 
1129
1434
  [`examples/linear`](../../examples/linear) triages issues in agent sessions,
@@ -1138,19 +1443,21 @@ the Slack and GitHub channels do. Setting it up takes a Linear workspace admin:
1138
1443
  - **Create a new Linear app**: Linear has no public API to create apps, so
1139
1444
  deploy asks for the workspace's URL key (as in `https://linear.app/<key>/`)
1140
1445
  and opens Linear's new-app page in that workspace, filled in with the app's
1141
- name, redirect URI, webhook URL (`<deployment-url>/channels/linear/events`)
1142
- and events. The admin creates the app and pastes its client ID, client
1446
+ name, client credentials turned on, webhook URL
1447
+ (`<deployment-url>/channels/linear/events`) and events. The admin creates the app and pastes its client ID, client
1143
1448
  secret and webhook signing secret into deploy's prompts.
1144
- - **Use an existing Linear app**: deploy lists the redirect URI, webhook URL
1145
- and events to set on the app's settings page, then asks for the same three
1449
+ - **Use an existing Linear app**: deploy lists what to set on the app's
1450
+ settings page (client credentials on, the webhook URL and events), then asks for the same three
1146
1451
  values. Linear sends an app's webhooks to one URL, so whatever received them
1147
1452
  before stops receiving them.
1148
1453
 
1149
- Deploy then opens the install page, where the admin approves the app for the
1150
- workspace. Agent Auth keeps the credentials and the agent's token, so nothing
1151
- goes into `.env`, and later deploys keep the app without asking. If Linear
1152
- stops renewing the app's access, the next deploy keeps the app and only asks
1153
- an admin to approve it again. Linear has no API to change an app, so when the
1454
+ Agent Auth then gets the app's token with Linear's client-credentials grant,
1455
+ so no one approves an install, and it gets a new token before the old one
1456
+ expires. Agent Auth keeps the credentials and the agent's token, so nothing
1457
+ goes into `.env`, and later deploys keep the app without asking. An app that
1458
+ an earlier mda set up keeps the install an admin approved: if Linear stops
1459
+ renewing its access, the next deploy keeps the app and only asks an admin to
1460
+ approve it again. Linear has no API to change an app, so when the
1154
1461
  channel's `app` settings change or the deployment moves to another URL, update
1155
1462
  the app on its settings page.
1156
1463
 
@@ -1166,12 +1473,11 @@ remove them once the channel is set up. Without a terminal and without them,
1166
1473
  deploy stops before uploading with the link to create the app.
1167
1474
 
1168
1475
  An app from these variables wasn't made from deploy's filled-in page, and
1169
- Linear has no API that says what it has set. So before the install link,
1170
- deploy lists the redirect URI, webhook URL and events the app needs, the same
1476
+ Linear has no API that says what it has set. So before the install, deploy
1477
+ lists the client credentials, webhook URL and events the app needs, the same
1171
1478
  as for an existing app. In a terminal it waits until you say they're set;
1172
- without one it prints them before the install link for an admin to open.
1173
- Without the redirect URI, Linear answers the install with "Invalid
1174
- redirect_uri".
1479
+ without one it prints them and goes on. Without client credentials, Agent
1480
+ Auth can't get the app's token, and the install fails.
1175
1481
 
1176
1482
  If a setup step fails, deploy offers to try again or to continue without the
1177
1483
  Linear channel. Without a terminal the failure ends the deploy, once the other
@@ -1217,8 +1523,8 @@ Linear event that names no one. It returns:
1217
1523
  backend then share connections and memory.
1218
1524
  - `{ type: "identity", provider, issuer, subject }`: run as an exact Agent
1219
1525
  Auth identity, such as the IdP `sub` your web users sign in with.
1220
- - `{ type: "reply", message }`: start nothing, and post `message` where the
1221
- event came from, as `runtime.channel.post` does, but only when the event
1526
+ - `{ type: "reply", message }`, or `reply(message)`: start nothing, and post
1527
+ `message` where the event came from, as `runtime.channel.post` does, but only when the event
1222
1528
  would start or resume a run. `message` is a `ChannelMessage`. Slack and Linear send text only. A GitHub channel can't
1223
1529
  post, so it only starts nothing.
1224
1530
  - `{ type: "ignore" }`: start nothing. This also stops a stranger from
@@ -1323,7 +1629,7 @@ fields must not replace them.
1323
1629
  Automatic agent replies use the `content` form. An explicit
1324
1630
  `runtime.thread.origin.channel.post({ type: "native", native: ... })` reaches your adapter
1325
1631
  without conversion. Automatic replies run after the request is accepted. A failed
1326
- `post` is recorded as a delivery error. `reply: "none"` turns automatic
1632
+ `post` is recorded as a delivery error. `autoPost: false` turns automatic
1327
1633
  replies off, so the agent replies itself; `post` still serves
1328
1634
  `runtime.channel.post` and error notices.
1329
1635
  If `post` is omitted, the channel can receive events and exposes facts, but
@@ -1379,7 +1685,7 @@ onFinish: async (target, finished) => {
1379
1685
  The hooks run in the background, in the process that took the delivery;
1380
1686
  failures are logged. A restart while a run is in flight loses its
1381
1687
  `onFinish`, and a run Studio resumes has no delivery, so it gets none: keep a
1382
- reconciliation, or the run's `webhook` (see handlers' run options), for anything
1688
+ reconciliation, or the run's `webhook` (see a handler's run options), for anything
1383
1689
  that must not miss one. The run posts its own
1384
1690
  answer.
1385
1691
 
@@ -1398,9 +1704,15 @@ checks. When the event's thread takes a turn, MDA POSTs
1398
1704
  `{ event: { key, deliveryId, payload }, thread: { id, channel, interrupted? } }`
1399
1705
  as JSON to it, with the `Request`'s headers (never logged), and starts the run
1400
1706
  the service answers with: `{ input, context?, metadata?, webhook? }`, checked as
1401
- a handler's result. `null` or HTTP 204 starts nothing. A GitHub event also
1402
- carries what a handler gets beside the payload: its `action`, `repository`,
1403
- `sender` and `mentions`, so a service checks them as a handler does. These are
1707
+ a handler's list of one run. `null` or HTTP 204 starts nothing.
1708
+ `{ type: "reply", message }` starts nothing too, and posts `message`, a
1709
+ `ChannelMessage`, where the event came from, as `resolveUser`'s reply does: a
1710
+ Linear agent session hears it as its response, instead of "I'm not set up to
1711
+ work on this request." A function handler returns `reply(message)` for the
1712
+ same, with text or a `ChannelMessage`. For a sender `resolveUser` holds back,
1713
+ its own answer stands instead. A GitHub event also
1714
+ carries what a handler gets beside the payload: its `action`, `repository`
1715
+ (`account` for an installation event), `sender` and `mentions`, so a service checks them as a handler does. These are
1404
1716
  optional in `GitHubEndpointRequest`, so a receiver takes requests from older
1405
1717
  deployments. A Slack message carries its `text`, `userId`, `channelId`,
1406
1718
  `messageTs`, `threadTs` and `files` the same way, with Slack's own event as
@@ -1437,7 +1749,8 @@ request as [Standard Webhooks](https://www.standardwebhooks.com/) does:
1437
1749
  `webhook-id`, `webhook-timestamp` and `webhook-signature`, an HMAC-SHA256 of the
1438
1750
  id, the timestamp and the exact body. The id is `msg_<deliveryId>` for the call
1439
1751
  that starts the run, `msg_<deliveryId>_interrupted` for a GitHub call that
1440
- asks whether to tell the conversation its thread waits on a decision, and
1752
+ asks whether to tell the conversation its thread waits on a decision,
1753
+ `msg_<deliveryId>_forward` for a GitHub delivery `forwardTo` forwards, and
1441
1754
  `msg_<deliveryId>_resolve_user` for a `resolveUser` call
1442
1755
  (see [Mapping channel senders to your users](#mapping-channel-senders-to-your-users)). The secret is `whsec_` and padded base64
1443
1756
  of 24 to 64 random bytes (`echo "whsec_$(openssl rand -base64 32)"`; an
@@ -1533,6 +1846,26 @@ live. Declarations must be statically serializable literals or top-level
1533
1846
  constants; prompt schedules become user-message input, and stateless runs clean
1534
1847
  up their temporary thread after completion.
1535
1848
 
1849
+ `autoPost` posts the run's final answer to a channel address, for now a Slack
1850
+ conversation or thread; `false`, the default, posts nothing. A schedule has no
1851
+ conversation of its own, so `true` is refused:
1852
+
1853
+ ```ts
1854
+ export const schedule = defineSchedule({
1855
+ cron: "0 9 * * 1",
1856
+ prompt: "Write a short Monday greeting.",
1857
+ // `threadTs` posts in a thread; `channel` names the Slack channel when the
1858
+ // deployment declares more than one.
1859
+ autoPost: { provider: "slack", conversationId: "C0123456789" },
1860
+ });
1861
+ ```
1862
+
1863
+ `deliverTo` is deprecated: `deliverTo: { channel, to: { type:
1864
+ "provider_conversation", conversationId } }` is `autoPost: { provider: "slack",
1865
+ conversationId, channel }`, `provider_thread` adds `threadTs: threadId`, and a
1866
+ `deliverTo` with `autoPost: false` is `autoPost: false`. Set one of them, not
1867
+ both.
1868
+
1536
1869
  ### Runtime schedules
1537
1870
 
1538
1871
  Use `runtime.schedules` in a tool or middleware to create schedules while the
@@ -1701,10 +2034,30 @@ export const sandbox = defineSandbox({
1701
2034
  key: creation options (a bake base, `vCpus`, `memBytes`, `fsCapacityBytes`,
1702
2035
  TTLs) and `proxyConfig`. It cannot set `defaultTimeout` or `apiKey`, and its
1703
2036
  proxy can reference only agent-owned connections, because every run on the
1704
- thread shares the sandbox. Name and thread scope stay MDA's.
2037
+ thread shares the sandbox. Thread scope stays MDA's, and so does the
2038
+ name, unless the definition names an existing sandbox.
1705
2039
  - Creation options apply when the thread's sandbox is created; a live sandbox
1706
2040
  is kept. The proxy is written before each command, so it applies to the run
1707
- that returned it.
2041
+ that returned it (except on an existing sandbox, below).
2042
+ - To open a sandbox that already exists, such as one an eval harness created,
2043
+ return a definition with `existingSandbox` set to its name. The thread is bound
2044
+ to it and MDA never creates it: if LangSmith no longer has it, the run fails
2045
+ with `SandboxMissingError`. Name it on every run of the thread; a run that
2046
+ names none opens MDA's own sandbox for the thread. Its creation options are
2047
+ ignored. MDA leaves its proxy config alone unless the run declares a
2048
+ `proxyConfig`, which it writes as on any other sandbox; a config a run wrote
2049
+ stays on the sandbox through later runs that declare none, so a resolver
2050
+ that declares one should declare one on every run. The name can reach
2051
+ any sandbox the deployment's key can, another thread's included, so take it
2052
+ from something the agent trusts, such as its own records, never from a
2053
+ caller's input.
2054
+ - An async subagent shares its lead's sandbox. Once the lead is bound to an
2055
+ existing sandbox, a subagent without mounts of its own opens that sandbox
2056
+ even if its own `resolve` names none, and leaves its proxy config alone
2057
+ unless it declares a `proxyConfig`. A subagent naming a different existing
2058
+ sandbox, or whose lead is bound to several sandboxes, none of them its own,
2059
+ fails. If the lead has not opened its sandbox yet, the subagent's own
2060
+ `resolve` decides, so it should name the same `existingSandbox` as the lead's.
1708
2061
  - `null` gives the run no sandbox: its files stay in agent state and
1709
2062
  `execute` is not offered.
1710
2063
  - If `resolve` throws, the model call or sandbox operation that asked for it
@@ -1859,6 +2212,13 @@ Tool names are raw MCP tool names before the managed `{server}_` prefix is
1859
2212
  applied, so `includeTools: ["search"]` on server `langchainDocs` exposes
1860
2213
  `langchainDocs_search` when prefixing is enabled.
1861
2214
 
2215
+ MDA adds the
2216
+ [instructions](https://modelcontextprotocol.io/specification/2025-06-18/basic/lifecycle#initialization)
2217
+ a server returns when it connects to the agent's system prompt. They are
2218
+ labeled as external guidance and added only to model calls that offer one of
2219
+ the server's tools. Set `includeInstructions: false` on a server to leave them out.
2220
+ Instructions over 4,096 characters are cut off with a marker.
2221
+
1862
2222
  ### Migration from 0.8
1863
2223
 
1864
2224
  - `mcpServers` → `servers`, and `type` → `transport`.