[PR #323] [MERGED] feat(sdk): add async subagent middleware for remote LangGraph servers #358

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

📋 Pull Request Information

Original PR: https://github.com/langchain-ai/deepagentsjs/pull/323
Author: @colifran
Created: 3/18/2026
Status: Merged
Merged: 3/20/2026
Merged by: @colifran

Base: mainHead: colifran/async-subagents


📝 Commits (10+)

  • 515f358 add langgraph sdk dep
  • 18d865d launch tool, check tool
  • 6c53c8b update tool and cancel tool
  • b55b5f8 update and cancel tool tests
  • fcc5569 list async subagent jobs tool
  • b3e4031 list subagent jobs tool and create middleware
  • 2dd7703 wire in async subagents
  • 173532f create and use state schema, update message to messages
  • 3669c60 tests
  • 5108002 AsyncSubagent -> AsyncSubAgent

📊 Changes

10 files changed (+2442 additions, -1 deletions)

View changed files

.changeset/true-buckets-hide.md (+5 -0)
📝 libs/deepagents/package.json (+1 -0)
📝 libs/deepagents/src/agent.ts (+5 -0)
📝 libs/deepagents/src/index.ts (+7 -0)
libs/deepagents/src/middleware/async_subagents.test.ts (+1459 -0)
libs/deepagents/src/middleware/async_subagents.ts (+864 -0)
📝 libs/deepagents/src/middleware/index.test.ts (+66 -0)
📝 libs/deepagents/src/middleware/index.ts (+10 -0)
📝 libs/deepagents/src/types.ts (+22 -1)
📝 pnpm-lock.yaml (+3 -0)

📄 Description

Summary

Adds AsyncSubAgentMiddleware for launching background jobs on remote LangGraph deployments via the LangGraph SDK. This is the JS port of the Python AsyncSubAgentMiddleware.

The middleware provides five tools:

  • start_async_task — creates a thread + run on a remote server, returns a job ID immediately
  • check_async_task — fetches run status and extracts the result on completion
  • update_async_task — sends follow-up instructions by creating a new run on the same thread (with multitaskStrategy: "interrupt")
  • cancel_async_task — cancels a running job
  • list_async_tasks — lists all tracked jobs with live statuses fetched in parallel

Job state is persisted in the asyncSubAgentJobs state channel via a ReducedValue reducer, so jobs survive context compaction and summarization.

Integrated into createDeepAgent via the asyncSubagents parameter.

Tests

77 unit tests covering:

  • State reducer merge logic and immutability
  • ClientCache — caching, key deduplication, default x-auth-scheme header injection
  • All 5 tools — happy paths, unknown job IDs, SDK errors, graceful degradation (e.g. threads.getState failure on success still returns a result)
  • buildCheckResult — message content extraction, non-object fallback, empty messages fallback, error status
  • buildListTool — status filtering, terminal status SDK call skipping, live status updates, parallel fetching
  • createAsyncSubAgentMiddleware — validation (empty list, duplicate names), tool wiring, system prompt injection, independent instances

🔄 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/323 **Author:** [@colifran](https://github.com/colifran) **Created:** 3/18/2026 **Status:** ✅ Merged **Merged:** 3/20/2026 **Merged by:** [@colifran](https://github.com/colifran) **Base:** `main` ← **Head:** `colifran/async-subagents` --- ### 📝 Commits (10+) - [`515f358`](https://github.com/langchain-ai/deepagentsjs/commit/515f3586b8c6d98e98b55c0e76345f8354743ad9) add langgraph sdk dep - [`18d865d`](https://github.com/langchain-ai/deepagentsjs/commit/18d865dfab63480872957a5aad0816e1671ae38a) launch tool, check tool - [`6c53c8b`](https://github.com/langchain-ai/deepagentsjs/commit/6c53c8b4692a6ab086fe15f90b7af73dea999792) update tool and cancel tool - [`b55b5f8`](https://github.com/langchain-ai/deepagentsjs/commit/b55b5f8e83c4d1a92c2074e5e7bca6157dbd0c95) update and cancel tool tests - [`fcc5569`](https://github.com/langchain-ai/deepagentsjs/commit/fcc5569cc7f57af22464c00908109bb61f27bb6d) list async subagent jobs tool - [`b3e4031`](https://github.com/langchain-ai/deepagentsjs/commit/b3e403189b47489d4fcf0f14063f31b3dc09e734) list subagent jobs tool and create middleware - [`2dd7703`](https://github.com/langchain-ai/deepagentsjs/commit/2dd7703f7e985fc4066faa6424f01cabe7b168cb) wire in async subagents - [`173532f`](https://github.com/langchain-ai/deepagentsjs/commit/173532f764363db78e2f0fde9586d5e24cd1573c) create and use state schema, update message to messages - [`3669c60`](https://github.com/langchain-ai/deepagentsjs/commit/3669c60ead25615251c840cae03e3d619c671e09) tests - [`5108002`](https://github.com/langchain-ai/deepagentsjs/commit/51080023c656983daf7fb87c5fdf8283ad1f5a2a) AsyncSubagent -> AsyncSubAgent ### 📊 Changes **10 files changed** (+2442 additions, -1 deletions) <details> <summary>View changed files</summary> ➕ `.changeset/true-buckets-hide.md` (+5 -0) 📝 `libs/deepagents/package.json` (+1 -0) 📝 `libs/deepagents/src/agent.ts` (+5 -0) 📝 `libs/deepagents/src/index.ts` (+7 -0) ➕ `libs/deepagents/src/middleware/async_subagents.test.ts` (+1459 -0) ➕ `libs/deepagents/src/middleware/async_subagents.ts` (+864 -0) 📝 `libs/deepagents/src/middleware/index.test.ts` (+66 -0) 📝 `libs/deepagents/src/middleware/index.ts` (+10 -0) 📝 `libs/deepagents/src/types.ts` (+22 -1) 📝 `pnpm-lock.yaml` (+3 -0) </details> ### 📄 Description ### Summary Adds `AsyncSubAgentMiddleware` for launching background jobs on remote LangGraph deployments via the LangGraph SDK. This is the JS port of the Python `AsyncSubAgentMiddleware`. The middleware provides five tools: - `start_async_task` — creates a thread + run on a remote server, returns a job ID immediately - `check_async_task` — fetches run status and extracts the result on completion - `update_async_task` — sends follow-up instructions by creating a new run on the same thread (with `multitaskStrategy: "interrupt"`) - `cancel_async_task` — cancels a running job - `list_async_tasks` — lists all tracked jobs with live statuses fetched in parallel Job state is persisted in the `asyncSubAgentJobs` state channel via a `ReducedValue` reducer, so jobs survive context compaction and summarization. Integrated into `createDeepAgent` via the `asyncSubagents` parameter. ### Tests 77 unit tests covering: - State reducer merge logic and immutability - `ClientCache` — caching, key deduplication, default `x-auth-scheme` header injection - All 5 tools — happy paths, unknown job IDs, SDK errors, graceful degradation (e.g. `threads.getState` failure on success still returns a result) - `buildCheckResult` — message content extraction, non-object fallback, empty messages fallback, error status - `buildListTool` — status filtering, terminal status SDK call skipping, live status updates, parallel fetching - `createAsyncSubAgentMiddleware` — validation (empty list, duplicate names), tool wiring, system prompt injection, independent instances --- <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:48 -04:00
yindo closed this issue 2026-06-05 17:22:48 -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#358