[PR #361] [MERGED] feat(deepagents): rename completion notifier to completion callback and align with Python #392

Closed
opened 2026-06-05 17:22:55 -04:00 by yindo · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/langchain-ai/deepagentsjs/pull/361
Author: @hntrl
Created: 3/24/2026
Status: Merged
Merged: 3/26/2026
Merged by: @hntrl

Base: alphaHead: hunter/notifier-middleware-improvements


📝 Commits (3)

  • 9c6af27 feat(deepagents): rename completion notifier to completion callback and align with Python PR
  • 7f6934a cr
  • 02a31e2 Rename completion notifier to completion callback

📊 Changes

9 files changed (+959 additions, -757 deletions)

View changed files

.changeset/nice-swans-ring.md (+5 -0)
📝 libs/deepagents/src/index.ts (+3 -3)
📝 libs/deepagents/src/middleware/async_subagents.test.ts (+95 -0)
📝 libs/deepagents/src/middleware/async_subagents.ts (+27 -1)
libs/deepagents/src/middleware/completion_callback.test.ts (+464 -0)
libs/deepagents/src/middleware/completion_callback.ts (+361 -0)
libs/deepagents/src/middleware/completion_notifier.test.ts (+0 -393)
libs/deepagents/src/middleware/completion_notifier.ts (+0 -356)
📝 libs/deepagents/src/middleware/index.ts (+4 -4)

📄 Description

Summary

Brings the JS completion notifier middleware to full parity with the Python CompletionCallbackMiddleware from PR #2119

Changes

deepagents — Completion callback middleware (completion_callback.ts)

Replaces completion_notifier.ts with completion_callback.ts, aligning naming, API surface, and behavior with Python:

  • Renamed exports: createCompletionNotifierMiddlewarecreateCompletionCallbackMiddleware, CompletionNotifierOptionsCompletionCallbackOptions
  • Renamed state key: parent_thread_idcallbackThreadId (matches Python's callback_thread_id)
  • Renamed option: parentGraphIdcallbackGraphId (matches Python's callback_graph_id)
  • url is now optional: Python allows omitting it for same-deployment ASGI transport; JS previously required it
  • Strict error handling: extractLastMessage now throws on empty messages and non-AIMessage types (matching Python's AssertionError/TypeError); afterAgent throws when callbackThreadId is missing from state (matching Python's KeyError)
  • Truncation with hint: Long messages get "... [full result truncated]" suffix plus a check_async_task(task_id='...') hint when task_id is available
  • Generic error notifications: wrapModelCall now sends "The agent encountered an error while calling the model." instead of leaking the actual error message
  • No dedup guard: Removed the notified boolean — Python notifies on every model error, and JS now matches

deepagents — Callback context injection (async_subagents.ts)

Adds extractCallbackContext() to the async subagents middleware, matching Python's _extract_callback_context. When start_async_task launches a subagent, the parent's thread_id is now automatically propagated as callbackThreadId in the subagent's input state — enabling the CompletionCallbackMiddleware on the subagent side to notify back on completion.

Tests

  • 31 tests for completion_callback.ts covering strict error behavior, truncation, generic error messages, and per-error notification
  • 7 new tests for extractCallbackContext and callback context injection in async_subagents.test.ts

🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/langchain-ai/deepagentsjs/pull/361 **Author:** [@hntrl](https://github.com/hntrl) **Created:** 3/24/2026 **Status:** ✅ Merged **Merged:** 3/26/2026 **Merged by:** [@hntrl](https://github.com/hntrl) **Base:** `alpha` ← **Head:** `hunter/notifier-middleware-improvements` --- ### 📝 Commits (3) - [`9c6af27`](https://github.com/langchain-ai/deepagentsjs/commit/9c6af274caa84de6cc3f2cb74bdad0fd87d198d3) feat(deepagents): rename completion notifier to completion callback and align with Python PR - [`7f6934a`](https://github.com/langchain-ai/deepagentsjs/commit/7f6934a070b7378d36e71fa3f1bf48b24112b789) cr - [`02a31e2`](https://github.com/langchain-ai/deepagentsjs/commit/02a31e20d40285bb85db8fbe54a5b30760d8220f) Rename completion notifier to completion callback ### 📊 Changes **9 files changed** (+959 additions, -757 deletions) <details> <summary>View changed files</summary> ➕ `.changeset/nice-swans-ring.md` (+5 -0) 📝 `libs/deepagents/src/index.ts` (+3 -3) 📝 `libs/deepagents/src/middleware/async_subagents.test.ts` (+95 -0) 📝 `libs/deepagents/src/middleware/async_subagents.ts` (+27 -1) ➕ `libs/deepagents/src/middleware/completion_callback.test.ts` (+464 -0) ➕ `libs/deepagents/src/middleware/completion_callback.ts` (+361 -0) ➖ `libs/deepagents/src/middleware/completion_notifier.test.ts` (+0 -393) ➖ `libs/deepagents/src/middleware/completion_notifier.ts` (+0 -356) 📝 `libs/deepagents/src/middleware/index.ts` (+4 -4) </details> ### 📄 Description ## Summary Brings the JS completion notifier middleware to full parity with the Python `CompletionCallbackMiddleware` from [PR #2119](https://github.com/langchain-ai/deepagents/pull/2119) ## Changes ### `deepagents` — Completion callback middleware (`completion_callback.ts`) Replaces `completion_notifier.ts` with `completion_callback.ts`, aligning naming, API surface, and behavior with Python: - **Renamed exports**: `createCompletionNotifierMiddleware` → `createCompletionCallbackMiddleware`, `CompletionNotifierOptions` → `CompletionCallbackOptions` - **Renamed state key**: `parent_thread_id` → `callbackThreadId` (matches Python's `callback_thread_id`) - **Renamed option**: `parentGraphId` → `callbackGraphId` (matches Python's `callback_graph_id`) - **`url` is now optional**: Python allows omitting it for same-deployment ASGI transport; JS previously required it - **Strict error handling**: `extractLastMessage` now throws on empty messages and non-`AIMessage` types (matching Python's `AssertionError`/`TypeError`); `afterAgent` throws when `callbackThreadId` is missing from state (matching Python's `KeyError`) - **Truncation with hint**: Long messages get `"... [full result truncated]"` suffix plus a `check_async_task(task_id='...')` hint when task_id is available - **Generic error notifications**: `wrapModelCall` now sends `"The agent encountered an error while calling the model."` instead of leaking the actual error message - **No dedup guard**: Removed the `notified` boolean — Python notifies on every model error, and JS now matches ### `deepagents` — Callback context injection (`async_subagents.ts`) Adds `extractCallbackContext()` to the async subagents middleware, matching Python's `_extract_callback_context`. When `start_async_task` launches a subagent, the parent's `thread_id` is now automatically propagated as `callbackThreadId` in the subagent's input state — enabling the `CompletionCallbackMiddleware` on the subagent side to notify back on completion. ### Tests - 31 tests for `completion_callback.ts` covering strict error behavior, truncation, generic error messages, and per-error notification - 7 new tests for `extractCallbackContext` and callback context injection in `async_subagents.test.ts` --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
yindo added the pull-request label 2026-06-05 17:22:55 -04:00
yindo closed this issue 2026-06-05 17:22:55 -04:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/deepagentsjs#392