[PR #32] [CLOSED] feat: migrate to createAgent API and middleware architecture #73

Closed
opened 2026-02-16 06:17:05 -05:00 by yindo · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/langchain-ai/deepagentsjs/pull/32
Author: @christian-bromann
Created: 9/23/2025
Status: Closed

Base: mainHead: cb/createAgent-migration


📝 Commits (10+)

📊 Changes

19 files changed (+701 additions, -707 deletions)

View changed files

📝 .github/workflows/ci.yml (+4 -4)
📝 .github/workflows/unit-tests.yml (+3 -3)
.nvmrc (+1 -0)
.vscode/settings.json (+10 -0)
📝 README.md (+43 -2)
📝 examples/research/research-agent.ts (+30 -12)
📝 package.json (+8 -10)
📝 src/agent.ts (+47 -83)
📝 src/index.ts (+1 -7)
src/interrupt.ts (+0 -137)
📝 src/middleware/fs.ts (+45 -56)
src/middleware/index.ts (+2 -0)
src/middleware/todo.ts (+75 -0)
src/model.ts (+0 -25)
src/state.ts (+0 -63)
📝 src/subAgent.ts (+29 -50)
📝 src/types.ts (+20 -61)
📝 tsconfig.json (+1 -1)
📝 yarn.lock (+382 -193)

📄 Description

Overview

This PR migrates the Deep Agents library from a custom LangGraph-based setup to the new langchain createAgent API with a middleware-driven architecture. It simplifies state management, standardizes agent creation, and aligns the project with current LangChain best practices.

Why

  • Reduce bespoke state/schema plumbing in favor of built-in agent capabilities.
  • Adopt a cleaner, composable middleware model for filesystem and todo operations.
  • Align with the latest langchain alpha APIs to enable future enhancements.

What Changed

  • Architecture

    • Replaced createReactAgent with createAgent.
    • Introduced middleware-based design (fsMiddleware, todoMiddleware).
    • Removed custom state scaffolding in favor of runtime middleware state.
  • Code

    • Deleted: src/state.ts, src/model.ts, src/interrupt.ts.
    • Moved tools to middleware: src/tools.tssrc/middleware/fs.ts; added src/middleware/todo.ts; new src/middleware/index.ts.
    • Refactored src/subAgent.ts:
      • Uses createAgent and middleware.
      • model can be a string or LanguageModelLike, defaulting to "openai:gpt-4o-mini".
      • Removed internal hardcoded/built-in tools map; resolution now relies solely on provided tools.
      • When subagent.tools is unspecified, all provided tools are used.
    • Updated src/types.ts:
      • Added SubAgentSchema (Zod) and SubAgent type based on it.
      • Simplified CreateDeepAgentParams; interruptConfig now uses HumanInTheLoopMiddlewareConfig["toolConfigs"].
      • Simplified CreateTaskToolParams generic to z.ZodObject.
    • Config and examples:
      • tsconfig.json: fix extends path to @tsconfig/recommended/tsconfig.json.
      • examples/research/research-agent.ts: updated to new API.
  • Dependencies

    • Bumped ESLint/TypeScript-related deps.
    • Upgraded to langchain alpha and latest related packages (@langchain/langgraph@next, @langchain/anthropic@alpha).
    • Updated lockfile accordingly.

Breaking Changes

  • Removal of DeepAgentState and custom reducers (src/state.ts).
  • Removal of built-in tools registry inside subAgent.ts:
    • Callers must pass tools explicitly (by name via subagent.tools mapping into the provided tools object).
  • createTaskTool signature changes:
    • stateSchema no longer required.
    • model accepts either a model string or a LanguageModelLike.
  • Interrupts/state handling now flows through middleware; any prior usage of interrupt.ts patterns must be updated.

Migration Guide

  • Replace any createReactAgent usage with createAgent.
  • Pass tools explicitly via tools: Record<string, StructuredTool>; if a subagent specifies no tools, all provided tools will be used.
  • Remove dependencies on DeepAgentState; move stateful behaviors into middleware or rely on the runtime state the agent manages.
  • Update types/imports to use SubAgentSchema / SubAgent and the simplified CreateDeepAgentParams.
  • Ensure your model is provided as a string (e.g., "openai:gpt-4o-mini") or as a LanguageModelLike.

🔄 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/32 **Author:** [@christian-bromann](https://github.com/christian-bromann) **Created:** 9/23/2025 **Status:** ❌ Closed **Base:** `main` ← **Head:** `cb/createAgent-migration` --- ### 📝 Commits (10+) - [`061ee01`](https://github.com/langchain-ai/deepagentsjs/commit/061ee01d5a261c357472cf9975d9d6df8b14dae0) feat: migrate to createAgent API and middleware architecture - [`f961383`](https://github.com/langchain-ai/deepagentsjs/commit/f961383627a4e858992957ef07b255c8075d1297) consolidate imports - [`ecca02c`](https://github.com/langchain-ai/deepagentsjs/commit/ecca02c437d89949d527305cb53f9414e7bef18c) progress - [`b6cbe1b`](https://github.com/langchain-ai/deepagentsjs/commit/b6cbe1baa5e2518c386307124d08fd349d04647e) push remaining update - [`680b78f`](https://github.com/langchain-ai/deepagentsjs/commit/680b78fbe56271e886b84683e3e4c3f11a90ba88) fix ci - [`536819a`](https://github.com/langchain-ai/deepagentsjs/commit/536819a17df77bc57055c0dd228418ce6224669b) cr - [`d1c852b`](https://github.com/langchain-ai/deepagentsjs/commit/d1c852bed2bcaeb4a44bdcf83f1e23915f1daeeb) fix - [`8997fd7`](https://github.com/langchain-ai/deepagentsjs/commit/8997fd7dc8fa4bd09b6d4c222c764839214d882e) add anthropicPromptCachingMiddleware - [`95ac817`](https://github.com/langchain-ai/deepagentsjs/commit/95ac81709b684f8d6579613d2edfa43ef1d6cb3d) prettier - [`cc4d68f`](https://github.com/langchain-ai/deepagentsjs/commit/cc4d68f7d1a1a2b446b7f9934c1c0dc6be7b7ce2) prettier ### 📊 Changes **19 files changed** (+701 additions, -707 deletions) <details> <summary>View changed files</summary> 📝 `.github/workflows/ci.yml` (+4 -4) 📝 `.github/workflows/unit-tests.yml` (+3 -3) ➕ `.nvmrc` (+1 -0) ➕ `.vscode/settings.json` (+10 -0) 📝 `README.md` (+43 -2) 📝 `examples/research/research-agent.ts` (+30 -12) 📝 `package.json` (+8 -10) 📝 `src/agent.ts` (+47 -83) 📝 `src/index.ts` (+1 -7) ➖ `src/interrupt.ts` (+0 -137) 📝 `src/middleware/fs.ts` (+45 -56) ➕ `src/middleware/index.ts` (+2 -0) ➕ `src/middleware/todo.ts` (+75 -0) ➖ `src/model.ts` (+0 -25) ➖ `src/state.ts` (+0 -63) 📝 `src/subAgent.ts` (+29 -50) 📝 `src/types.ts` (+20 -61) 📝 `tsconfig.json` (+1 -1) 📝 `yarn.lock` (+382 -193) </details> ### 📄 Description ## Overview This PR migrates the Deep Agents library from a custom LangGraph-based setup to the new `langchain` createAgent API with a middleware-driven architecture. It simplifies state management, standardizes agent creation, and aligns the project with current LangChain best practices. ## Why - Reduce bespoke state/schema plumbing in favor of built-in agent capabilities. - Adopt a cleaner, composable middleware model for filesystem and todo operations. - Align with the latest `langchain` alpha APIs to enable future enhancements. ## What Changed - Architecture - Replaced `createReactAgent` with `createAgent`. - Introduced middleware-based design (`fsMiddleware`, `todoMiddleware`). - Removed custom state scaffolding in favor of runtime middleware state. - Code - Deleted: `src/state.ts`, `src/model.ts`, `src/interrupt.ts`. - Moved tools to middleware: `src/tools.ts` → `src/middleware/fs.ts`; added `src/middleware/todo.ts`; new `src/middleware/index.ts`. - Refactored `src/subAgent.ts`: - Uses `createAgent` and middleware. - `model` can be a string or `LanguageModelLike`, defaulting to `"openai:gpt-4o-mini"`. - Removed internal hardcoded/built-in tools map; resolution now relies solely on provided `tools`. - When `subagent.tools` is unspecified, all provided tools are used. - Updated `src/types.ts`: - Added `SubAgentSchema` (Zod) and `SubAgent` type based on it. - Simplified `CreateDeepAgentParams`; `interruptConfig` now uses `HumanInTheLoopMiddlewareConfig["toolConfigs"]`. - Simplified `CreateTaskToolParams` generic to `z.ZodObject`. - Config and examples: - `tsconfig.json`: fix extends path to `@tsconfig/recommended/tsconfig.json`. - `examples/research/research-agent.ts`: updated to new API. - Dependencies - Bumped ESLint/TypeScript-related deps. - Upgraded to `langchain` alpha and latest related packages (`@langchain/langgraph@next`, `@langchain/anthropic@alpha`). - Updated lockfile accordingly. ## Breaking Changes - Removal of `DeepAgentState` and custom reducers (`src/state.ts`). - Removal of built-in tools registry inside `subAgent.ts`: - Callers must pass tools explicitly (by name via `subagent.tools` mapping into the provided `tools` object). - `createTaskTool` signature changes: - `stateSchema` no longer required. - `model` accepts either a model string or a `LanguageModelLike`. - Interrupts/state handling now flows through middleware; any prior usage of `interrupt.ts` patterns must be updated. ## Migration Guide - Replace any `createReactAgent` usage with `createAgent`. - Pass tools explicitly via `tools: Record<string, StructuredTool>`; if a `subagent` specifies no tools, all provided tools will be used. - Remove dependencies on `DeepAgentState`; move stateful behaviors into middleware or rely on the runtime state the agent manages. - Update types/imports to use `SubAgentSchema` / `SubAgent` and the simplified `CreateDeepAgentParams`. - Ensure your `model` is provided as a string (e.g., `"openai:gpt-4o-mini"`) or as a `LanguageModelLike`. --- <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-02-16 06:17:05 -05:00
yindo closed this issue 2026-02-16 06:17:05 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/deepagentsjs#73