managed-deepagents 0.10.7 → 0.10.8-dev.10

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 (224) hide show
  1. package/README.md +463 -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/assistant-text.d.ts +2 -0
  11. package/dist/channels/assistant-text.d.ts.map +1 -1
  12. package/dist/channels/assistant-text.js +47 -6
  13. package/dist/channels/assistant-text.js.map +1 -1
  14. package/dist/channels/binding.d.ts +7 -0
  15. package/dist/channels/binding.d.ts.map +1 -1
  16. package/dist/channels/binding.js +28 -4
  17. package/dist/channels/binding.js.map +1 -1
  18. package/dist/channels/delivery.d.ts.map +1 -1
  19. package/dist/channels/delivery.js +15 -18
  20. package/dist/channels/delivery.js.map +1 -1
  21. package/dist/channels/github/app-setup.d.ts.map +1 -1
  22. package/dist/channels/github/app-setup.js +86 -3
  23. package/dist/channels/github/app-setup.js.map +1 -1
  24. package/dist/channels/github/index.d.ts +1 -6
  25. package/dist/channels/github/index.d.ts.map +1 -1
  26. package/dist/channels/github/index.js +191 -38
  27. package/dist/channels/github/index.js.map +1 -1
  28. package/dist/channels/github/schema.d.ts +9280 -1622
  29. package/dist/channels/github/schema.d.ts.map +1 -1
  30. package/dist/channels/github/schema.js +164 -0
  31. package/dist/channels/github/schema.js.map +1 -1
  32. package/dist/channels/github/types.d.ts +98 -36
  33. package/dist/channels/github/types.d.ts.map +1 -1
  34. package/dist/channels/http/endpoint.d.ts +33 -9
  35. package/dist/channels/http/endpoint.d.ts.map +1 -1
  36. package/dist/channels/http/endpoint.js +72 -18
  37. package/dist/channels/http/endpoint.js.map +1 -1
  38. package/dist/channels/http/http.d.ts +7 -0
  39. package/dist/channels/http/http.d.ts.map +1 -1
  40. package/dist/channels/http/http.js +273 -27
  41. package/dist/channels/http/http.js.map +1 -1
  42. package/dist/channels/http/index.d.ts.map +1 -1
  43. package/dist/channels/http/index.js +4 -5
  44. package/dist/channels/http/index.js.map +1 -1
  45. package/dist/channels/http/ingress.d.ts +44 -1
  46. package/dist/channels/http/ingress.d.ts.map +1 -1
  47. package/dist/channels/http/ingress.js +63 -0
  48. package/dist/channels/http/ingress.js.map +1 -1
  49. package/dist/channels/http/input-state.d.ts +7 -0
  50. package/dist/channels/http/input-state.d.ts.map +1 -0
  51. package/dist/channels/http/input-state.js +16 -0
  52. package/dist/channels/http/input-state.js.map +1 -0
  53. package/dist/channels/http/provider.d.ts +36 -7
  54. package/dist/channels/http/provider.d.ts.map +1 -1
  55. package/dist/channels/http/provider.js +46 -7
  56. package/dist/channels/http/provider.js.map +1 -1
  57. package/dist/channels/http/types.d.ts +13 -5
  58. package/dist/channels/http/types.d.ts.map +1 -1
  59. package/dist/channels/linear/index.d.ts +0 -5
  60. package/dist/channels/linear/index.d.ts.map +1 -1
  61. package/dist/channels/linear/index.js +94 -21
  62. package/dist/channels/linear/index.js.map +1 -1
  63. package/dist/channels/linear/schema.d.ts +20 -20
  64. package/dist/channels/linear/schema.d.ts.map +1 -1
  65. package/dist/channels/linear/schema.js +20 -1
  66. package/dist/channels/linear/schema.js.map +1 -1
  67. package/dist/channels/linear/types.d.ts +58 -49
  68. package/dist/channels/linear/types.d.ts.map +1 -1
  69. package/dist/channels/reply.d.ts +28 -0
  70. package/dist/channels/reply.d.ts.map +1 -0
  71. package/dist/channels/reply.js +37 -0
  72. package/dist/channels/reply.js.map +1 -0
  73. package/dist/channels/resolve-user.d.ts +3 -2
  74. package/dist/channels/resolve-user.d.ts.map +1 -1
  75. package/dist/channels/resolve-user.js +5 -4
  76. package/dist/channels/resolve-user.js.map +1 -1
  77. package/dist/channels/run-input.d.ts +120 -10
  78. package/dist/channels/run-input.d.ts.map +1 -1
  79. package/dist/channels/run-input.js +233 -16
  80. package/dist/channels/run-input.js.map +1 -1
  81. package/dist/channels/runtime.d.ts +10 -3
  82. package/dist/channels/runtime.d.ts.map +1 -1
  83. package/dist/channels/runtime.js +15 -1
  84. package/dist/channels/runtime.js.map +1 -1
  85. package/dist/channels/schedule-delivery.d.ts +2 -2
  86. package/dist/channels/schedule-delivery.d.ts.map +1 -1
  87. package/dist/channels/slack/events.d.ts +176 -63
  88. package/dist/channels/slack/events.d.ts.map +1 -1
  89. package/dist/channels/slack/events.js +153 -4
  90. package/dist/channels/slack/events.js.map +1 -1
  91. package/dist/channels/slack/files.d.ts +6 -3
  92. package/dist/channels/slack/files.d.ts.map +1 -1
  93. package/dist/channels/slack/files.js +4 -1
  94. package/dist/channels/slack/files.js.map +1 -1
  95. package/dist/channels/slack/index.d.ts +60 -29
  96. package/dist/channels/slack/index.d.ts.map +1 -1
  97. package/dist/channels/slack/index.js +134 -56
  98. package/dist/channels/slack/index.js.map +1 -1
  99. package/dist/channels/trigger/conversation.d.ts +8 -3
  100. package/dist/channels/trigger/conversation.d.ts.map +1 -1
  101. package/dist/channels/trigger/conversation.js +101 -12
  102. package/dist/channels/trigger/conversation.js.map +1 -1
  103. package/dist/channels/trigger/http.d.ts +57 -8
  104. package/dist/channels/trigger/http.d.ts.map +1 -1
  105. package/dist/channels/trigger/http.js +405 -49
  106. package/dist/channels/trigger/http.js.map +1 -1
  107. package/dist/channels/trigger/ingress.d.ts +80 -2
  108. package/dist/channels/trigger/ingress.d.ts.map +1 -1
  109. package/dist/channels/trigger/ingress.js +143 -1
  110. package/dist/channels/trigger/ingress.js.map +1 -1
  111. package/dist/channels/trigger/transport.d.ts +2 -0
  112. package/dist/channels/trigger/transport.d.ts.map +1 -1
  113. package/dist/channels/trigger/transport.js +5 -1
  114. package/dist/channels/trigger/transport.js.map +1 -1
  115. package/dist/channels/trigger/types.d.ts +52 -3
  116. package/dist/channels/trigger/types.d.ts.map +1 -1
  117. package/dist/channels/trigger/types.js +21 -0
  118. package/dist/channels/trigger/types.js.map +1 -1
  119. package/dist/channels/types.d.ts +205 -1
  120. package/dist/channels/types.d.ts.map +1 -1
  121. package/dist/channels/types.js +27 -0
  122. package/dist/channels/types.js.map +1 -1
  123. package/dist/channels/warnings.d.ts +8 -0
  124. package/dist/channels/warnings.d.ts.map +1 -0
  125. package/dist/channels/warnings.js +17 -0
  126. package/dist/channels/warnings.js.map +1 -0
  127. package/dist/connectors/mcp/index.d.ts.map +1 -1
  128. package/dist/connectors/mcp/index.js +12 -4
  129. package/dist/connectors/mcp/index.js.map +1 -1
  130. package/dist/connectors/mcp/instructions.d.ts +30 -0
  131. package/dist/connectors/mcp/instructions.d.ts.map +1 -0
  132. package/dist/connectors/mcp/instructions.js +150 -0
  133. package/dist/connectors/mcp/instructions.js.map +1 -0
  134. package/dist/connectors/mcp/schema.d.ts.map +1 -1
  135. package/dist/connectors/mcp/schema.js +2 -1
  136. package/dist/connectors/mcp/schema.js.map +1 -1
  137. package/dist/connectors/mcp/types.d.ts +10 -0
  138. package/dist/connectors/mcp/types.d.ts.map +1 -1
  139. package/dist/index.d.ts +9 -6
  140. package/dist/index.d.ts.map +1 -1
  141. package/dist/index.js +2 -0
  142. package/dist/index.js.map +1 -1
  143. package/dist/ingress/runs.d.ts +3 -0
  144. package/dist/ingress/runs.d.ts.map +1 -1
  145. package/dist/ingress/runs.js +34 -16
  146. package/dist/ingress/runs.js.map +1 -1
  147. package/dist/memory/define-memory.d.ts +4 -2
  148. package/dist/memory/define-memory.d.ts.map +1 -1
  149. package/dist/memory/define-memory.js +4 -2
  150. package/dist/memory/define-memory.js.map +1 -1
  151. package/dist/namespaces.d.ts +2 -3
  152. package/dist/namespaces.d.ts.map +1 -1
  153. package/dist/namespaces.js +1 -1
  154. package/dist/namespaces.js.map +1 -1
  155. package/dist/run-context.d.ts +8 -0
  156. package/dist/run-context.d.ts.map +1 -1
  157. package/dist/run-context.js +5 -0
  158. package/dist/run-context.js.map +1 -1
  159. package/dist/run-ending-error.d.ts +16 -0
  160. package/dist/run-ending-error.d.ts.map +1 -0
  161. package/dist/run-ending-error.js +16 -0
  162. package/dist/run-ending-error.js.map +1 -0
  163. package/dist/runtime/auth.d.ts +5 -0
  164. package/dist/runtime/auth.d.ts.map +1 -1
  165. package/dist/runtime/auth.js +39 -6
  166. package/dist/runtime/auth.js.map +1 -1
  167. package/dist/runtime/backend.d.ts.map +1 -1
  168. package/dist/runtime/backend.js +7 -1
  169. package/dist/runtime/backend.js.map +1 -1
  170. package/dist/runtime/index.d.ts.map +1 -1
  171. package/dist/runtime/index.js +4 -1
  172. package/dist/runtime/index.js.map +1 -1
  173. package/dist/runtime/managed-thread.d.ts +6 -0
  174. package/dist/runtime/managed-thread.d.ts.map +1 -1
  175. package/dist/runtime/managed-thread.js +38 -2
  176. package/dist/runtime/managed-thread.js.map +1 -1
  177. package/dist/runtime/memory/policy.d.ts.map +1 -1
  178. package/dist/runtime/memory/policy.js +24 -5
  179. package/dist/runtime/memory/policy.js.map +1 -1
  180. package/dist/runtime/parent-run.d.ts +2 -1
  181. package/dist/runtime/parent-run.d.ts.map +1 -1
  182. package/dist/runtime/parent-run.js +9 -6
  183. package/dist/runtime/parent-run.js.map +1 -1
  184. package/dist/runtime/run-input.d.ts +1 -0
  185. package/dist/runtime/run-input.d.ts.map +1 -1
  186. package/dist/runtime/sandbox-manager.d.ts +27 -3
  187. package/dist/runtime/sandbox-manager.d.ts.map +1 -1
  188. package/dist/runtime/sandbox-manager.js +188 -22
  189. package/dist/runtime/sandbox-manager.js.map +1 -1
  190. package/dist/runtime/schedule-auth.d.ts +21 -5
  191. package/dist/runtime/schedule-auth.d.ts.map +1 -1
  192. package/dist/runtime/schedule-auth.js +58 -15
  193. package/dist/runtime/schedule-auth.js.map +1 -1
  194. package/dist/runtime/steering.d.ts +2 -2
  195. package/dist/runtime/steering.d.ts.map +1 -1
  196. package/dist/runtime/steering.js +83 -15
  197. package/dist/runtime/steering.js.map +1 -1
  198. package/dist/runtime/thread-handoff.d.ts +16 -0
  199. package/dist/runtime/thread-handoff.d.ts.map +1 -0
  200. package/dist/runtime/thread-handoff.js +24 -0
  201. package/dist/runtime/thread-handoff.js.map +1 -0
  202. package/dist/runtime/thread-record.d.ts +6 -0
  203. package/dist/runtime/thread-record.d.ts.map +1 -1
  204. package/dist/runtime/thread-record.js +6 -0
  205. package/dist/runtime/thread-record.js.map +1 -1
  206. package/dist/runtime-schedules.d.ts +2 -2
  207. package/dist/runtime-schedules.d.ts.map +1 -1
  208. package/dist/runtime-schedules.js +9 -3
  209. package/dist/runtime-schedules.js.map +1 -1
  210. package/dist/sandbox.d.ts +12 -0
  211. package/dist/sandbox.d.ts.map +1 -1
  212. package/dist/sandbox.js +5 -0
  213. package/dist/sandbox.js.map +1 -1
  214. package/dist/schedules.d.ts +33 -14
  215. package/dist/schedules.d.ts.map +1 -1
  216. package/dist/schedules.js +32 -1
  217. package/dist/schedules.js.map +1 -1
  218. package/dist/telemetry/run.d.ts +2 -1
  219. package/dist/telemetry/run.d.ts.map +1 -1
  220. package/dist/telemetry/run.js.map +1 -1
  221. package/dist/tool-errors.d.ts.map +1 -1
  222. package/dist/tool-errors.js +10 -5
  223. package/dist/tool-errors.js.map +1 -1
  224. package/package.json +7 -7
package/README.md CHANGED
@@ -127,6 +127,12 @@ export const agent = defineDeepAgent({
127
127
 
128
128
  `defineDeepAgent` requires `name` and supports the [`createDeepAgent`](https://reference.langchain.com/javascript/deepagents/agent/createDeepAgent) options except the platform-owned `backend`, `store`, `checkpointer`, `systemPrompt`, and `memory` fields. Static agents use `instructions.md` and all discovered skills.
129
129
 
130
+ > [!WARNING]
131
+ > Treat `name` as permanent once deployed. It serves as the agent's persistent
132
+ > identifier, so renaming it breaks existing threads and detaches deployed
133
+ > state (such as memory and connections). Update display names in your UI or
134
+ > channels instead.
135
+
130
136
  Export a sync or async factory as `agent` to select configuration per run:
131
137
 
132
138
  ```ts
@@ -183,6 +189,14 @@ every caller that shares it shares its threads and cannot use user-owned
183
189
  connections or user memory. To act for many end users from one server, use a
184
190
  trusted backend or validated-token identity instead.
185
191
 
192
+ A trusted backend can send a tenant in the `x-mda-tenant-id` header. MDA stores
193
+ it on new threads as `ls_mda_tenant_id` and filters that backend's thread
194
+ requests by it. Access inside a tenant is the backend's decision.
195
+ `x-mda-user-id` sets the run's identity. MDA does not validate the tenant value.
196
+
197
+ A schedule that a run creates gets the tenant of that run, and so do the threads
198
+ it creates. Schedules in `schedules/` have no tenant.
199
+
186
200
  On deploy, Context Hub stores harness files (`instructions.md`, `skills/**`). A
187
201
  root `memory.ts` enables agent and user memory independently:
188
202
 
@@ -197,10 +211,14 @@ export const memory = defineMemory({
197
211
 
198
212
  Omit a layer to disable it. A layer with no `allow` callback uses its default
199
213
  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.
214
+ User memory requires a trusted person. By default it is mounted in two private
215
+ settings: managed Slack one-to-one DMs
216
+ (`context.channel.rawEvent.channel_type == "im"`), and direct API runs by a
217
+ caller who signed in with their own credential (such as a validated token) on a
218
+ thread no channel recorded. Shared conversations, missing event data, scheduled
219
+ runs, and trusted-backend runs get no user mount unless an authored policy
220
+ allows it: a trusted backend vouches for a user ID, but MDA cannot see who the
221
+ backend shows the reply to.
204
222
 
205
223
  For compatibility, an autodiscovered root declaration can still use a sync or
206
224
  async `allow(context)` callback to replace its default policy. `allow` is
@@ -281,6 +299,7 @@ runtime
281
299
  .provider // Provider label, such as slack
282
300
  .event // Typed MDA delivery, or null
283
301
  .rawEvent // Optional original provider payload
302
+ .address // The provider conversation, typed per provider
284
303
  .post(...) // Present when sending is supported
285
304
  .sender // The participant who sent the latest event, or null
286
305
  .participants // The people on the thread: { id, role }
@@ -320,8 +339,21 @@ no message started still have it: a run LangSmith Studio resumes, and a
320
339
  scheduled run on the thread. In those runs `origin.channel.event` is `null` (a
321
340
  scheduled run gets a `schedule` event) and there is no `rawEvent`. The channel's
322
341
  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.
342
+ reply target, which callers can't replace. `address` is where the channel
343
+ posts: the conversation that `post` and the run's answers go to. It is on
344
+ `origin.channel` because a channel thread answers where it came from, so
345
+ `address` names the origin conversation, in every run of the thread, typed by
346
+ `provider`:
347
+
348
+ - Slack: `conversationId` (Slack's `channel`) and `threadTs` (Slack's
349
+ `thread_ts`).
350
+ - GitHub: `repository` (`owner/name`) and the issue or pull request `number`.
351
+ - Linear: `organizationId`, `issueId`, and `identifier`, `commentId` or
352
+ `sessionId` when the conversation has one.
353
+
354
+ In a scheduled run that starts a new thread, `post` posts at top level, so
355
+ `address` has no `threadTs`, `commentId` or `sessionId`. `address` is absent for a
356
+ channel without a typed address, such as `channels.http()`.
325
357
 
326
358
  ```ts
327
359
  const channel = runtime.thread?.origin?.channel;
@@ -354,7 +386,7 @@ It rejects native payloads and content it cannot send. For channels that support
354
386
  native messages, set `type` to `"native"` and supply the JSON in `native`.
355
387
  For content messages, set `type` to `"content"` and supply `content`.
356
388
  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.
389
+ wrapper. A message to `post` has no `address`, `update`, or destination override.
358
390
  A post sends an additional message; the normal final agent reply remains automatic.
359
391
 
360
392
  On Slack, `post(message, { newThread: true })` posts at top level in the same
@@ -366,10 +398,36 @@ person. The result also has `threadId` and, on Slack, the message `url`:
366
398
  ```ts
367
399
  const posted = await runtime.thread?.origin?.channel.post?.(
368
400
  { type: "content", content: "Haiku about mango" },
369
- { newThread: true, run: { messages: [...history, new HumanMessage("Go on.")] } }
401
+ {
402
+ newThread: true,
403
+ run: { messages: [...history, new HumanMessage("Go on.")] },
404
+ }
370
405
  );
371
406
  ```
372
407
 
408
+ To move the conversation instead, add `handOff: true`. The new Slack thread
409
+ takes the current run's thread, with its history: replies, Stop and decision
410
+ buttons there reach it, and `threadId` is the current thread's. The rest of
411
+ the run answers, and waits on decisions, in the new Slack thread too, and
412
+ `origin` is the new Slack thread's conversation from then on. MDA posts "This
413
+ conversation moved to a new thread", with a link to it, in the old Slack thread.
414
+ A later message there starts no run: MDA answers that the conversation moved,
415
+ unless the channel's handler replies first. Only a channel conversation's run
416
+ can hand off its thread, and not together with `run`:
417
+
418
+ ```ts
419
+ await runtime.thread?.origin?.channel.post?.(
420
+ { type: "content", content: "Moved here from the old thread." },
421
+ { newThread: true, handOff: true }
422
+ );
423
+ ```
424
+
425
+ Add `to` to start the new thread in another conversation of the same channel,
426
+ such as another Slack channel the app is in: a `ChannelAddress` of the origin's
427
+ provider with no thread, for example
428
+ `{ provider: "slack", conversationId: "C0123456789" }`. It works with `run`
429
+ and with `handOff`.
430
+
373
431
  Managed Slack channels save incoming files under `/workspace/attachments/` and
374
432
  add `upload_files(paths)` so the agent can attach completed workspace files
375
433
  to its reply. This requires a managed sandbox.
@@ -439,6 +497,43 @@ alias for the tool type. MDA adds `serverInfo`, `channel`, `backend`, and
439
497
  but the type marks it optional so annotated hooks still match LangChain's native
440
498
  runtime types.
441
499
 
500
+ ## Tool errors
501
+
502
+ MDA returns an error thrown by a tool to the model as that tool's result, so the
503
+ model can act on it, and the run continues. Throw a `RunEndingError` subclass to
504
+ end the run instead, from a tool or from your own middleware's `wrapToolCall`.
505
+ Use it for errors no later call can get past, such as a sandbox that stopped
506
+ answering. To end the run on an error you don't own, throw yours with it as the
507
+ `cause`:
508
+
509
+ ```ts
510
+ import { RunEndingError } from "managed-deepagents";
511
+ import { createMiddleware } from "langchain";
512
+ import { LangSmithSandboxConnectionError } from "langsmith/sandbox";
513
+
514
+ class SandboxGoneError extends RunEndingError {}
515
+
516
+ const sandboxErrors = createMiddleware({
517
+ name: "SandboxErrors",
518
+ wrapToolCall: async (request, handler) => {
519
+ try {
520
+ return await handler(request);
521
+ } catch (error) {
522
+ if (error instanceof LangSmithSandboxConnectionError) {
523
+ throw new SandboxGoneError(error.message, { cause: error });
524
+ }
525
+ throw error;
526
+ }
527
+ },
528
+ });
529
+ ```
530
+
531
+ MDA's own errors that end the run are subclasses too: a person who has not
532
+ connected an account the tool needs (`CredentialAuthorizationRequiredError`)
533
+ ends the run, so they can connect it. So `error instanceof RunEndingError` tells
534
+ your middleware whether MDA ends the run on an error. Errors in a sync subagent's tools work the same way: one it
535
+ can act on goes to the subagent's model, and a `RunEndingError` ends the whole run.
536
+
442
537
  ## Slack channels
443
538
 
444
539
  `channels.slack(...)` receives Slack messages through Trigger Server. Each
@@ -468,12 +563,12 @@ By default every message that reaches the app starts a run with the message.
468
563
  import { channels } from "managed-deepagents";
469
564
 
470
565
  export const channel = channels.slack({
471
- name: "Support Bot",
566
+ app: { name: "Support Bot" },
472
567
  triggerMode: "thread",
473
568
  onEvent: {
474
569
  mention: (event, thread) => [
475
- event.text,
476
570
  {
571
+ input: event.text,
477
572
  context: { ticket: thread.id },
478
573
  metadata: { slack_channel: event.channelId },
479
574
  },
@@ -486,6 +581,15 @@ export const channel = channels.slack({
486
581
  });
487
582
  ```
488
583
 
584
+ `app` is the Slack app deploy sets up, as `channels.github` and
585
+ `channels.linear` take theirs: its `name`, `description`, `icon` (a path
586
+ relative to `channels/`) and `backgroundColor`. Setting them at the top level
587
+ of `channels.slack(...)` still works but is deprecated and will be removed in
588
+ 0.12, and can't be combined with `app`. `ignoreBots` (default `true`, as on
589
+ `channels.linear`) ignores other bots' messages; with `false`, a bot's message
590
+ reaches the agent as a person's would in its `triggerMode`. `allowBotTriggers`
591
+ is its deprecated opposite, also removed in 0.12.
592
+
489
593
  The keys are `mention`, a channel message that @-mentions the app;
490
594
  `directMessage`; and `message`, any other channel message, which only
491
595
  `triggerMode` `"thread"` or `"all"` delivers. Under those modes Slack sends a
@@ -501,13 +605,21 @@ thread's mention, the thread's later replies start nothing until someone
501
605
  mentions the agent there again.
502
606
 
503
607
  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
608
+ `threadTs`, `files`, Slack's own event as `payload`, `actor`, and `teamId`, the
609
+ workspace your app is installed in) and its thread (`id`, `sourceThreadKey`,
610
+ `channel.name`). `await thread.getState()` reads the thread's state as Agent
611
+ Server's `threads.getState` does (its `values`, such as `messages`, as its last
612
+ run left them, `next` and `tasks`), or `undefined` before any run. It returns the run's input,
613
+ as `agent.invoke` takes it, or, to also set run options such as `context`,
614
+ `metadata` or `webhook`, a list of runs `{ input, ...options }`, as the GitHub
615
+ and Linear handlers do. `null` or
616
+ `undefined` starts no run, and the app neither reacts nor replies. Trigger
617
+ Server gets its answer before MDA asks the handler, so a slow handler never
618
+ times out the delivery. A handler that throws, or returns input the channel
619
+ can't start, starts no run either; the error is logged without its message.
620
+ To try a failing call again, retry it inside the handler with the backoff you
621
+ choose; a delivery whose handler is still running or waiting when the
622
+ deployment restarts is lost. The message's blocks and attachments
511
623
  are added to the handler's messages, and its files still reach
512
624
  `/workspace/attachments/`. Interrupt resumes don't go through `onEvent`; a
513
625
  click on a button the agent posted does, as `interaction`: see
@@ -532,6 +644,78 @@ already runs: `enqueue` (the default) waits for the run and starts after it,
532
644
  `interrupt` cancels the run, keeping its progress, and starts at once,
533
645
  `rollback` cancels it and discards its progress, and `reject` starts nothing.
534
646
 
647
+ A handler may also choose each run's thread, strategy and `autoPost`, as on
648
+ GitHub, Linear and HTTP channels: its list may hold several runs, at most one
649
+ on the Slack thread's own conversation:
650
+
651
+ ```ts
652
+ onEvent: {
653
+ message: (event) => {
654
+ if (event.text.startsWith("<@")) return event.text; // a mention interrupts
655
+ if (channelSessionId)
656
+ // One session for the whole channel: every Slack thread's message waits its turn.
657
+ return [
658
+ {
659
+ input: event.text,
660
+ thread: { mode: "persistent", id: channelSessionId },
661
+ multitaskStrategy: "enqueue",
662
+ autoPost: true,
663
+ },
664
+ ];
665
+ return [{ input: event.text, multitaskStrategy: "enqueue" }]; // waits behind the running run
666
+ },
667
+ },
668
+ ```
669
+
670
+ A run on a thread of the handler's choosing shows its status, reaction and
671
+ decisions in the Slack thread its message came from, and posts its answer
672
+ there only with `autoPost: true`, or an address naming that Slack thread, such
673
+ as a run's `runtime.thread.origin.channel.address` passed back. A run on
674
+ the Slack thread's own conversation (without `thread`, or on
675
+ `{ mode: "persistent", id: thread.id }`) posts as the channel's `autoPost`
676
+ says, unless its own `autoPost` says otherwise. Stop in that Slack thread
677
+ cancels the runs its messages started, on the conversation and on the
678
+ handler's threads; another Slack thread's run on a shared thread goes on. A
679
+ decision a run there waits on is answered from the Slack thread that started
680
+ the run. Every thread a channel's handlers choose is owned by the channel, not
681
+ by one Slack thread. An ephemeral thread is deleted once its run ends, unless
682
+ it waits on a decision.
683
+
684
+ An `edit`, `delete` or `reaction` handler takes what happened to a message: a
685
+ `SlackActivityEvent` with `messageTs`, `threadTs`, the message's `text` (as
686
+ edited, as it was before it was deleted, or as reacted to), `userId` (the author
687
+ for an edit or deletion, the person who reacted for a reaction), `reaction` and
688
+ `removed`, and Slack's event as `payload`. It starts only the run it returns:
689
+
690
+ ```ts
691
+ onEvent: {
692
+ mention: onMention,
693
+ reaction: (event) =>
694
+ event.reaction === "thumbsup" && !event.removed
695
+ ? [{ input: `<@${event.userId}> liked: ${event.text}`, multitaskStrategy: "enqueue" }]
696
+ : null,
697
+ },
698
+ ```
699
+
700
+ The channel asks Trigger Server for these events only when it has a handler for
701
+ their key, which needs an `mda` CLI that sends `forwardedEvents`. Trigger Server
702
+ forwards one only for a thread the channel already took a message from, unless
703
+ the channel takes every message (`triggerMode: "all"`) or it is in a direct
704
+ message, and never your agent's own edits or reactions. Reactions need the Slack
705
+ app's `reactions:read` scope: a LangSmith-managed app gets it at the next
706
+ deploy, after a reinstall the workspace may have to approve; a customer-owned
707
+ app's manifest has to add it.
708
+
709
+ A `shortcut` handler takes one of your Slack app's message shortcuts, used on a
710
+ message: `actionId` is the shortcut's `callback_id`, `userId` the person who used it,
711
+ and `payload` Slack's interaction payload, with its `response_url` to answer
712
+ them. Trigger Server forwards it wherever a person used it, as a mention. Your
713
+ app defines its shortcuts in its own settings; it needs the `commands` scope.
714
+
715
+ A `channel` handler takes a change to a channel itself: created, renamed,
716
+ archived, unarchived or deleted (`type` is Slack's event, `group_*` for a private
717
+ channel), with `channelId` and `teamId`. It names no message or thread.
718
+
535
719
  `event.actor` is the Slack user who sent the message, as Trigger Server read
536
720
  it from Slack's signed request: `{ provider: "slack", id, teamId }`. `teamId`
537
721
  is their own workspace: in a Slack Connect channel, someone from another
@@ -631,17 +815,19 @@ the background. The reply, errors and approvals still show.
631
815
  ### Replying from the agent
632
816
 
633
817
  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:
818
+ `autoPost: false` leaves replying to the agent instead, for an agent that
819
+ posts its own messages, with `runtime.channel.post` or its own Slack client,
820
+ or that answers somewhere else:
637
821
 
638
822
  ```ts
639
- channels.slack({ reply: "none" });
823
+ channels.slack({ autoPost: false });
640
824
  ```
641
825
 
642
826
  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.
827
+ and `channels.http` take the same option. The older `reply: "auto" | "none"`
828
+ still works, as `autoPost` `true` or `false`; set one of them. Deploying
829
+ `autoPost: false` needs an `mda` CLI from this release; an older one refuses
830
+ it.
645
831
 
646
832
  ### Buttons your agent posts
647
833
 
@@ -649,9 +835,7 @@ and `channels.http` take the same option. Deploying `reply: "none"` needs an
649
835
  Slack-specific, such as buttons, feedback buttons or a message the agent
650
836
  updates later, the agent posts with its own Slack client. The app's bot token
651
837
  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.
838
+ throws), and the channel's `address` names the conversation and its thread.
655
839
 
656
840
  ```ts
657
841
  import { WebClient } from "@slack/web-api";
@@ -661,15 +845,12 @@ import { connections, type ManagedToolRuntime } from "managed-deepagents";
661
845
 
662
846
  export const offerChoices = tool(
663
847
  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;
848
+ const address = runtime.thread?.origin?.channel.address;
849
+ if (address?.provider !== "slack") return "Not in Slack.";
669
850
  const token = await connections.get("mda/slack-bot-token", { type: "agent" });
670
851
  await new WebClient(token).chat.postMessage({
671
- channel,
672
- thread_ts: threadTs,
852
+ channel: address.conversationId,
853
+ thread_ts: address.threadTs,
673
854
  text: question,
674
855
  blocks: [
675
856
  { type: "section", text: { type: "mrkdwn", text: question } },
@@ -842,23 +1023,39 @@ from Agent Auth are cached for up to 5 minutes. A matched event fails closed if
842
1023
  the bot ID is missing or invalid. Calling `channels.github()` without handlers preserves
843
1024
  receipt-only behavior and needs only the webhook secret.
844
1025
 
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.
1026
+ Supported keys are `<event>.<action>`, for every action GitHub sends of these
1027
+ events:
1028
+
1029
+ - `issues`: `opened`, `edited`, `reopened`, `closed`, `deleted`, `transferred`,
1030
+ `labeled`, `unlabeled`, `assigned`, `unassigned`, `locked`, `unlocked`,
1031
+ `milestoned`, `demilestoned`, `pinned`, `unpinned`, `typed`, `untyped`.
1032
+ - `issue_comment`: `created`, `edited`, `deleted`.
1033
+ - `pull_request`: `opened`, `edited`, `reopened`, `closed`, `ready_for_review`,
1034
+ `converted_to_draft`, `synchronize`, `labeled`, `unlabeled`, `assigned`,
1035
+ `unassigned`, `review_requested`, `review_request_removed`, `locked`,
1036
+ `unlocked`, `milestoned`, `demilestoned`, `enqueued`, `dequeued`,
1037
+ `auto_merge_enabled`, `auto_merge_disabled`.
1038
+ - `pull_request_review`: `submitted`, `edited`, `dismissed`.
1039
+ - `pull_request_review_comment`: `created`, `edited`, `deleted`.
1040
+ - `pull_request_review_thread`: `resolved`, `unresolved`. The payload's `thread`
1041
+ has the thread's `node_id` and its review `comments`. These need only
1042
+ `pull_requests: read`.
1043
+ - Code and CI: `push` and `status`, which have no action, so their key is the
1044
+ event name; `check_run`: `created`, `completed`, `rerequested`,
1045
+ `requested_action`; `check_suite`: `requested`, `rerequested`, `completed`;
1046
+ `workflow_run`: `requested`, `in_progress`, `completed`. A CI event continues
1047
+ a pull request's conversation when it ran for exactly one pull request.
860
1048
  - Merge queue: `merge_group.checks_requested`, `merge_group.destroyed`. A
861
1049
  merge group belongs to no conversation, so each delivery gets its own thread.
1050
+ - Installation: `installation.created`, `installation.deleted`, `installation.suspend`,
1051
+ `installation.unsuspend`, `installation.new_permissions_accepted`,
1052
+ `installation_repositories.added`, `installation_repositories.removed`.
1053
+ GitHub sends these to every App, so handling one needs no subscription or
1054
+ permission. They are about the installation, not a repository: the handler
1055
+ gets a `GitHubInstallationEvent`, with the `account` the App is installed on
1056
+ instead of a `repository`. A channel limited to `app.repositories` gets them
1057
+ too, each delivery gets its own thread, and `onReceived` and `onFinish`
1058
+ aren't called for them.
862
1059
 
863
1060
  GitHub sends no event for a mention, so each event lists the handles the
864
1061
  text it wrote mentions in `event.mentions`: the body of a new or edited
@@ -903,13 +1100,19 @@ nothing. The App's own activity is what the agent does with the App's token,
903
1100
  such as its comments, its pushes or a pull request it opened; set
904
1101
  `includeOwnEvents: true` to hand those to handlers too, with `event.fromApp`
905
1102
  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
1103
+ the agent answers itself. Issues, comments, pull requests and reviews from other bots, such as
1104
+ Dependabot, are ignored too, as on Linear and Slack; set `ignoreBots: false` to
1105
+ let them start runs. CI, `push` and `merge_group` events still reach their
1106
+ handlers. GitHub gets its answer first; then MDA asks the configured handler,
1107
+ a callback or an endpoint (see "Asking your service what to start"), and starts
1108
+ the run, so a slow handler never times out the delivery. Synchronous and async
1109
+ callbacks are supported. A handler returns
1110
+ what `agent.invoke` takes, for one run on the event's conversation: a nonblank
1111
+ string (one user message), a message such as `new HumanMessage(...)` with text
1112
+ or content blocks, or state such as `{ messages: [...], todos: [] }`. To set
1113
+ run options, it returns a list of runs `{ input, ...options }` instead, where
1114
+ `input` is any of those. The options set the run's context
1115
+ (`context.channel` is reserved) or metadata, such as
913
1116
  `{ issue: "ENG-123" }` to find the run by in LangSmith. Metadata keys are
914
1117
  letters, digits, `_`, `.` or `-`. Keys the Agent Server and LangSmith set
915
1118
  are reserved: `mda_`, `langgraph_` and `ls_` keys, and ids such as
@@ -919,17 +1122,74 @@ metadata, values and any error) to `url`, as `runs.create({ webhook })` does;
919
1122
  http(s), without credentials in the URL.
920
1123
  The handler's second argument is the conversation's `thread`: `thread.id` is
921
1124
  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.
1125
+ backend signs for the thread. `await thread.getState()` reads the thread's
1126
+ state as Agent Server's `threads.getState` does, or `undefined` before any run,
1127
+ as on Slack and Linear; only a handler deciding an event can read it.
1128
+ `null` or `undefined` skips without a thread or run. GitHub posts no answer,
1129
+ so a GitHub handler has no `reply(message)`.
1130
+ Other results are safely logged and start nothing. So does a handler that
1131
+ throws: GitHub already has its answer, so the delivery isn't failed; MDA logs
1132
+ the error's type only. Nor is a delivery whose run can't start, for example
1133
+ while the Agent Server is briefly unavailable: `onFinish` gets `failed` with
1134
+ reason `start`.
1135
+ To try a failing call again, retry it inside the handler with the backoff
1136
+ you choose: the handler may take as long as it needs. A delivery whose
1137
+ handler is still running or waiting when the deployment restarts is lost.
925
1138
 
926
1139
  Each issue or pull request has one thread, so the agent keeps the conversation:
927
1140
  an issue, its comments, and a pull request with its reviews and review comments
928
1141
  continue the same thread, as does a workflow run for exactly one pull request.
929
1142
  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
1143
+ because each thread runs a delivery once. The exception is an event whose only
1144
+ runs were on ephemeral threads, on a conversation that has no thread yet: those
1145
+ threads are deleted when their runs end, so a later redelivery starts them again. A comment that arrives while the agent
931
1146
  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.
1147
+ run stops for. GitHub never redelivers on its own.
1148
+
1149
+ A list may hold several runs for one event, on threads the handler chooses
1150
+ (GitHub, Linear, HTTP and Slack channels):
1151
+
1152
+ ```ts
1153
+ "issue_comment.created": (event, thread) => [
1154
+ // The issue's conversation.
1155
+ { input: prompt },
1156
+ // A fresh thread, deleted once the run ends.
1157
+ { input: triage, thread: { mode: "ephemeral" } },
1158
+ // A thread your service keeps across events, by its UUID.
1159
+ {
1160
+ input: plan,
1161
+ thread: { mode: "persistent", id: planThreadId },
1162
+ multitaskStrategy: "interrupt",
1163
+ },
1164
+ ],
1165
+ ```
1166
+
1167
+ A run without `thread` starts on the thread the handler was given, the
1168
+ event's conversation, as does one on `{ mode: "persistent", id: thread.id }`;
1169
+ at most one run may. Otherwise `thread` is a `ThreadConfig`, as a schedule's:
1170
+ `{ mode: "ephemeral" }` or `{ mode: "persistent", id }`. `autoPost` says
1171
+ where a run posts its final answer: `true` where the event came from, `false`
1172
+ nowhere, or an address, such as the thread's
1173
+ `runtime.thread.origin.channel.address`, passed as it is. For now an address
1174
+ must be where the event came from; on Linear a run's answer posts nowhere
1175
+ else yet. GitHub posts no run's answer, so a GitHub run (`GitHubRun`) has no
1176
+ `autoPost`: the agent's tools post on GitHub. Without `autoPost`, the channel's `autoPost`
1177
+ decides for the conversation's run, and a run on another thread posts nothing.
1178
+ `multitaskStrategy` overrides the channel's for one run.
1179
+ On Slack, a run on a thread the handler chose may name the Slack thread it
1180
+ belongs to with `conversation`, a Slack address with its `threadTs`, such as a
1181
+ thread the handler just opened in the same app and workspace: its status, Stop
1182
+ button and decisions show there instead of where the event came from, Stop
1183
+ there stops it, and `autoPost: true` answers there (experimental).
1184
+ A persistent id must be a UUID; which ids an event may reach is yours to
1185
+ check. A delivery starts at most one run on each thread, so a resent one
1186
+ starts nothing there again, even if the handler now starts a different set of
1187
+ runs. The handler is asked once per delivery, before any thread is read, and
1188
+ not at all once the conversation has seen the delivery. While the conversation
1189
+ waits on a decision, the handler is still asked (on GitHub with
1190
+ `thread.interrupted` set): its runs on other threads start, and a run on the
1191
+ conversation is skipped, with the usual waiting notice. An empty list starts
1192
+ nothing.
933
1193
 
934
1194
  Handlers can call GitHub with a client such as Octokit and the App's
935
1195
  installation token from `connections.get("mda/github-token", { type: "agent" })`,
@@ -998,6 +1258,49 @@ supported. To act on
998
1258
  GitHub from a run (comment, label, open pull requests), give the agent a GitHub
999
1259
  MCP server in `tools/mcp.ts`.
1000
1260
 
1261
+ ### Forwarding deliveries to your backend
1262
+
1263
+ A backend that needs GitHub's events, including ones that never start a run,
1264
+ gets them through `forwardTo`: services, each a URL or a `Request` that also
1265
+ carries headers, such as an API key. No handler has to call it, and it gets
1266
+ events MDA has no type for too.
1267
+
1268
+ ```ts
1269
+ const backend = new Request(`${BACKEND_URL}/github/webhooks`, {
1270
+ headers: { "x-api-key": process.env.BACKEND_KEY! },
1271
+ });
1272
+
1273
+ export const channel = channels.github({
1274
+ onEvent: {
1275
+ "issues.opened": (e) => `Help with #${e.payload.issue.number}`,
1276
+ },
1277
+ forwardTo: [backend],
1278
+ });
1279
+ ```
1280
+
1281
+ - Once GitHub's signature checks out, MDA POSTs every delivery but `ping` to
1282
+ each service, before anything else reads it: whatever its event or action,
1283
+ whether or not a handler takes it, from any repository and any sender.
1284
+ - The body is GitHub's raw body, byte for byte. The headers are GitHub's own,
1285
+ unchanged: `Content-Type` and every `X-GitHub-*` and `X-Hub-*` header
1286
+ (`X-GitHub-Event`, `X-GitHub-Delivery`, `X-Hub-Signature-256` and any GitHub
1287
+ adds), but no other header the delivery arrived with. Then come the `Request`'s
1288
+ headers and the Standard Webhooks signature described in
1289
+ [Asking your service what to start](#asking-your-service-what-to-start), with
1290
+ the webhook ID `msg_<deliveryId>_forward`.
1291
+ - GitHub is answered only once every service answered 2xx, all asked at once,
1292
+ within 8 seconds. Then the delivery goes on as without `forwardTo`.
1293
+ - Any other answer, a redirect, a timeout or a network error answers GitHub
1294
+ HTTP 502 and starts no handler and no run, so GitHub marks the delivery
1295
+ failed. GitHub doesn't send it again on its own: redelivering it from the
1296
+ App's settings, or with GitHub's API, forwards and handles it again.
1297
+ - A channel can have `forwardTo` and no `onEvent`.
1298
+ - `forwardTo` adds no App permission and no webhook event: a service gets the
1299
+ events the App is subscribed to, which the channel's handlers decide.
1300
+
1301
+ The URL must be https, or plain http to a loopback host, and carry no
1302
+ credentials; a bad one throws when the channel is declared.
1303
+
1001
1304
  ### Setting up the GitHub App
1002
1305
 
1003
1306
  The first `mda deploy` of a GitHub channel asks which GitHub App it uses, as
@@ -1030,7 +1333,9 @@ To skip the questions, with or without a terminal, set these in the shell or
1030
1333
  `@me`, the personal account of whoever creates it.
1031
1334
  - `MDA_GITHUB_APP_ID`, `MDA_GITHUB_APP_PRIVATE_KEY_FILE` (the path to its
1032
1335
  `.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.
1336
+ Add `MDA_GITHUB_APP_INSTALLATION_ID` when it's installed in several accounts:
1337
+ the agent's token is minted on that installation, and each deploy renews it
1338
+ there when the channel's permissions change.
1034
1339
  - `MDA_GITHUB_WEBHOOK_SECRET` alone: the webhook secret of an existing App
1035
1340
  whose secret Agent Auth doesn't have yet.
1036
1341
  - `MDA_GITHUB_WEBHOOK_ELSEWHERE`: the URL an existing App's webhook keeps.
@@ -1085,6 +1390,9 @@ names them; an unknown key in `onEvent` throws. The channel verifies each delive
1085
1390
  and rejects deliveries older than a minute. It ignores events about teams
1086
1391
  outside `app.teams`, changes by other apps and integrations (set
1087
1392
  `ignoreBots: false` to keep them), and the app's own comments and changes.
1393
+ `onReceived(event, thread)` hears each handled delivery as it reaches its
1394
+ thread, after the channel acknowledges an agent session, as GitHub's does; a
1395
+ handler's `thread.getState()` reads the thread's state, as on GitHub and Slack.
1088
1396
 
1089
1397
  > **Experimental.** Agent sessions use Linear's Agents API, which is a
1090
1398
  > Developer Preview, so they may change as Linear changes it. Issue and
@@ -1103,6 +1411,17 @@ same link. Comments that a
1103
1411
  session already delivers, such as the mention itself and replies in the
1104
1412
  session, don't also reach a `Comment.create` handler.
1105
1413
 
1414
+ Linear gets its answer before MDA asks the handler, so a slow handler never
1415
+ times out the delivery. A handler that throws starts nothing, and Linear doesn't
1416
+ send the delivery again; the error is logged by type only. The same holds for a
1417
+ run that can't start, for example while the Agent Server is briefly
1418
+ unavailable: `onFinish` gets `failed` with reason `start`. In an agent session,
1419
+ the session hears at once that something went wrong, since its author waits;
1420
+ an issue gets no comment, since its handler may have skipped the event.
1421
+ To try a failing call again, retry it inside the handler with the backoff
1422
+ you choose: the handler may take as long as it needs. A delivery whose
1423
+ handler is still running or waiting when the deployment restarts is lost.
1424
+
1106
1425
  `app` also names the app deploy asks the admin to create: `name` (2-80
1107
1426
  characters, without "Linear"; defaults to the agent's name), `description`,
1108
1427
  and `icon`, a PNG or JPEG given as a path relative to `channels/` like the
@@ -1118,12 +1437,12 @@ it installs the app.
1118
1437
 
1119
1438
  The channel reads the webhook signing secret from Agent Auth, or from
1120
1439
  `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
1440
+ Agent Auth app, whose OAuth connection is `mda/linear-app/<deployment-id>`
1441
+ and whose token acts as the app; read its token with
1123
1442
  `await connections.get("mda/linear-token", { type: "agent" })` to call Linear's API from tools.
1124
1443
 
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
1444
+ `autoPost: false` leaves the run's answer to the agent: the channel doesn't
1445
+ post it as a comment or in the session. Session acknowledgements, Stop and error
1127
1446
  notices still post.
1128
1447
 
1129
1448
  [`examples/linear`](../../examples/linear) triages issues in agent sessions,
@@ -1138,19 +1457,21 @@ the Slack and GitHub channels do. Setting it up takes a Linear workspace admin:
1138
1457
  - **Create a new Linear app**: Linear has no public API to create apps, so
1139
1458
  deploy asks for the workspace's URL key (as in `https://linear.app/<key>/`)
1140
1459
  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
1460
+ name, client credentials turned on, webhook URL
1461
+ (`<deployment-url>/channels/linear/events`) and events. The admin creates the app and pastes its client ID, client
1143
1462
  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
1463
+ - **Use an existing Linear app**: deploy lists what to set on the app's
1464
+ settings page (client credentials on, the webhook URL and events), then asks for the same three
1146
1465
  values. Linear sends an app's webhooks to one URL, so whatever received them
1147
1466
  before stops receiving them.
1148
1467
 
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
1468
+ Agent Auth then gets the app's token with Linear's client-credentials grant,
1469
+ so no one approves an install, and it gets a new token before the old one
1470
+ expires. Agent Auth keeps the credentials and the agent's token, so nothing
1471
+ goes into `.env`, and later deploys keep the app without asking. An app that
1472
+ an earlier mda set up keeps the install an admin approved: if Linear stops
1473
+ renewing its access, the next deploy keeps the app and only asks an admin to
1474
+ approve it again. Linear has no API to change an app, so when the
1154
1475
  channel's `app` settings change or the deployment moves to another URL, update
1155
1476
  the app on its settings page.
1156
1477
 
@@ -1166,12 +1487,11 @@ remove them once the channel is set up. Without a terminal and without them,
1166
1487
  deploy stops before uploading with the link to create the app.
1167
1488
 
1168
1489
  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
1490
+ Linear has no API that says what it has set. So before the install, deploy
1491
+ lists the client credentials, webhook URL and events the app needs, the same
1171
1492
  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".
1493
+ without one it prints them and goes on. Without client credentials, Agent
1494
+ Auth can't get the app's token, and the install fails.
1175
1495
 
1176
1496
  If a setup step fails, deploy offers to try again or to continue without the
1177
1497
  Linear channel. Without a terminal the failure ends the deploy, once the other
@@ -1217,8 +1537,8 @@ Linear event that names no one. It returns:
1217
1537
  backend then share connections and memory.
1218
1538
  - `{ type: "identity", provider, issuer, subject }`: run as an exact Agent
1219
1539
  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
1540
+ - `{ type: "reply", message }`, or `reply(message)`: start nothing, and post
1541
+ `message` where the event came from, as `runtime.channel.post` does, but only when the event
1222
1542
  would start or resume a run. `message` is a `ChannelMessage`. Slack and Linear send text only. A GitHub channel can't
1223
1543
  post, so it only starts nothing.
1224
1544
  - `{ type: "ignore" }`: start nothing. This also stops a stranger from
@@ -1323,7 +1643,7 @@ fields must not replace them.
1323
1643
  Automatic agent replies use the `content` form. An explicit
1324
1644
  `runtime.thread.origin.channel.post({ type: "native", native: ... })` reaches your adapter
1325
1645
  without conversion. Automatic replies run after the request is accepted. A failed
1326
- `post` is recorded as a delivery error. `reply: "none"` turns automatic
1646
+ `post` is recorded as a delivery error. `autoPost: false` turns automatic
1327
1647
  replies off, so the agent replies itself; `post` still serves
1328
1648
  `runtime.channel.post` and error notices.
1329
1649
  If `post` is omitted, the channel can receive events and exposes facts, but
@@ -1379,7 +1699,7 @@ onFinish: async (target, finished) => {
1379
1699
  The hooks run in the background, in the process that took the delivery;
1380
1700
  failures are logged. A restart while a run is in flight loses its
1381
1701
  `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
1702
+ reconciliation, or the run's `webhook` (see a handler's run options), for anything
1383
1703
  that must not miss one. The run posts its own
1384
1704
  answer.
1385
1705
 
@@ -1398,9 +1718,15 @@ checks. When the event's thread takes a turn, MDA POSTs
1398
1718
  `{ event: { key, deliveryId, payload }, thread: { id, channel, interrupted? } }`
1399
1719
  as JSON to it, with the `Request`'s headers (never logged), and starts the run
1400
1720
  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
1721
+ a handler's list of one run. `null` or HTTP 204 starts nothing.
1722
+ `{ type: "reply", message }` starts nothing too, and posts `message`, a
1723
+ `ChannelMessage`, where the event came from, as `resolveUser`'s reply does: a
1724
+ Linear agent session hears it as its response, instead of "I'm not set up to
1725
+ work on this request." A function handler returns `reply(message)` for the
1726
+ same, with text or a `ChannelMessage`. For a sender `resolveUser` holds back,
1727
+ its own answer stands instead. A GitHub event also
1728
+ carries what a handler gets beside the payload: its `action`, `repository`
1729
+ (`account` for an installation event), `sender` and `mentions`, so a service checks them as a handler does. These are
1404
1730
  optional in `GitHubEndpointRequest`, so a receiver takes requests from older
1405
1731
  deployments. A Slack message carries its `text`, `userId`, `channelId`,
1406
1732
  `messageTs`, `threadTs` and `files` the same way, with Slack's own event as
@@ -1437,7 +1763,8 @@ request as [Standard Webhooks](https://www.standardwebhooks.com/) does:
1437
1763
  `webhook-id`, `webhook-timestamp` and `webhook-signature`, an HMAC-SHA256 of the
1438
1764
  id, the timestamp and the exact body. The id is `msg_<deliveryId>` for the call
1439
1765
  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
1766
+ asks whether to tell the conversation its thread waits on a decision,
1767
+ `msg_<deliveryId>_forward` for a GitHub delivery `forwardTo` forwards, and
1441
1768
  `msg_<deliveryId>_resolve_user` for a `resolveUser` call
1442
1769
  (see [Mapping channel senders to your users](#mapping-channel-senders-to-your-users)). The secret is `whsec_` and padded base64
1443
1770
  of 24 to 64 random bytes (`echo "whsec_$(openssl rand -base64 32)"`; an
@@ -1533,6 +1860,26 @@ live. Declarations must be statically serializable literals or top-level
1533
1860
  constants; prompt schedules become user-message input, and stateless runs clean
1534
1861
  up their temporary thread after completion.
1535
1862
 
1863
+ `autoPost` posts the run's final answer to a channel address, for now a Slack
1864
+ conversation or thread; `false`, the default, posts nothing. A schedule has no
1865
+ conversation of its own, so `true` is refused:
1866
+
1867
+ ```ts
1868
+ export const schedule = defineSchedule({
1869
+ cron: "0 9 * * 1",
1870
+ prompt: "Write a short Monday greeting.",
1871
+ // `threadTs` posts in a thread; `channel` names the Slack channel when the
1872
+ // deployment declares more than one.
1873
+ autoPost: { provider: "slack", conversationId: "C0123456789" },
1874
+ });
1875
+ ```
1876
+
1877
+ `deliverTo` is deprecated: `deliverTo: { channel, to: { type:
1878
+ "provider_conversation", conversationId } }` is `autoPost: { provider: "slack",
1879
+ conversationId, channel }`, `provider_thread` adds `threadTs: threadId`, and a
1880
+ `deliverTo` with `autoPost: false` is `autoPost: false`. Set one of them, not
1881
+ both.
1882
+
1536
1883
  ### Runtime schedules
1537
1884
 
1538
1885
  Use `runtime.schedules` in a tool or middleware to create schedules while the
@@ -1701,10 +2048,30 @@ export const sandbox = defineSandbox({
1701
2048
  key: creation options (a bake base, `vCpus`, `memBytes`, `fsCapacityBytes`,
1702
2049
  TTLs) and `proxyConfig`. It cannot set `defaultTimeout` or `apiKey`, and its
1703
2050
  proxy can reference only agent-owned connections, because every run on the
1704
- thread shares the sandbox. Name and thread scope stay MDA's.
2051
+ thread shares the sandbox. Thread scope stays MDA's, and so does the
2052
+ name, unless the definition names an existing sandbox.
1705
2053
  - Creation options apply when the thread's sandbox is created; a live sandbox
1706
2054
  is kept. The proxy is written before each command, so it applies to the run
1707
- that returned it.
2055
+ that returned it (except on an existing sandbox, below).
2056
+ - To open a sandbox that already exists, such as one an eval harness created,
2057
+ return a definition with `existingSandbox` set to its name. The thread is bound
2058
+ to it and MDA never creates it: if LangSmith no longer has it, the run fails
2059
+ with `SandboxMissingError`. Name it on every run of the thread; a run that
2060
+ names none opens MDA's own sandbox for the thread. Its creation options are
2061
+ ignored. MDA leaves its proxy config alone unless the run declares a
2062
+ `proxyConfig`, which it writes as on any other sandbox; a config a run wrote
2063
+ stays on the sandbox through later runs that declare none, so a resolver
2064
+ that declares one should declare one on every run. The name can reach
2065
+ any sandbox the deployment's key can, another thread's included, so take it
2066
+ from something the agent trusts, such as its own records, never from a
2067
+ caller's input.
2068
+ - An async subagent shares its lead's sandbox. Once the lead is bound to an
2069
+ existing sandbox, a subagent without mounts of its own opens that sandbox
2070
+ even if its own `resolve` names none, and leaves its proxy config alone
2071
+ unless it declares a `proxyConfig`. A subagent naming a different existing
2072
+ sandbox, or whose lead is bound to several sandboxes, none of them its own,
2073
+ fails. If the lead has not opened its sandbox yet, the subagent's own
2074
+ `resolve` decides, so it should name the same `existingSandbox` as the lead's.
1708
2075
  - `null` gives the run no sandbox: its files stay in agent state and
1709
2076
  `execute` is not offered.
1710
2077
  - If `resolve` throws, the model call or sandbox operation that asked for it
@@ -1859,6 +2226,13 @@ Tool names are raw MCP tool names before the managed `{server}_` prefix is
1859
2226
  applied, so `includeTools: ["search"]` on server `langchainDocs` exposes
1860
2227
  `langchainDocs_search` when prefixing is enabled.
1861
2228
 
2229
+ MDA adds the
2230
+ [instructions](https://modelcontextprotocol.io/specification/2025-06-18/basic/lifecycle#initialization)
2231
+ a server returns when it connects to the agent's system prompt. They are
2232
+ labeled as external guidance and added only to model calls that offer one of
2233
+ the server's tools. Set `includeInstructions: false` on a server to leave them out.
2234
+ Instructions over 4,096 characters are cut off with a marker.
2235
+
1862
2236
  ### Migration from 0.8
1863
2237
 
1864
2238
  - `mcpServers` → `servers`, and `type` → `transport`.