[GH-ISSUE #141] tool_use.id: Field required error when using deepagents with Next.js + Turbopack (blocking enterprise deployment) #35

Closed
opened 2026-02-16 06:16:56 -05:00 by yindo · 3 comments
Owner

Originally created by @masonsuper on GitHub (Jan 25, 2026).
Original GitHub issue: https://github.com/langchain-ai/deepagentsjs/issues/141

Originally assigned to: @hntrl on GitHub.

Description

When using createDeepAgent in a Next.js 16 application with Turbopack, API calls fail with an Anthropic error indicating a missing id field in tool_use messages. This is blocking my enterprise deployment trying to use deepagents, would love if this could get prioritized

my repo uses the app from: https://www.next-forge.com/docs

Error Message

Error in middleware "todoListMiddleware": Error in middleware "FilesystemMiddleware":
Error in middleware "subAgentMiddleware": Error in middleware "PromptCachingMiddleware":
400 {"type":"error","error":{"type":"invalid_request_error",
"message":"messages.3.content.2.tool_use.id: Field required"},"request_id":"req_011CXTfGknp5jQ4vxZmVExmT"}

Image

Environment

  • deepagents: 1.4.1
  • @langchain/langgraph: 1.0.14
  • @langchain/anthropic: 1.3.7
  • @langchain/core: 1.1.12
  • Next.js: 16.0.10 (with Turbopack)
  • Node.js: 20.x
  • Framework: next-forge monorepo

Code

/**
 * Simple Agent - DeepAgents Implementation
 *
 * A minimal agent using the deepagents library, following the official
 * research-agent.ts example from langchain-ai/deepagentsjs.
 *
 * Reference: https://github.com/langchain-ai/deepagentsjs/blob/main/examples/research/research-agent.ts
 */

import { ChatAnthropic } from "@langchain/anthropic";
import { tool } from "@langchain/core/tools";
import { MemorySaver } from "@langchain/langgraph";
import { TavilySearch } from "@langchain/tavily";
import { createDeepAgent } from "deepagents";
import { z } from "zod";
import { SYSTEM_PROMPT } from "./prompts";

// Checkpointer for LangGraph Studio thread persistence
const checkpointer = new MemorySaver();

// =============================================================================
// Tools
// =============================================================================

/**
 * Web search tool using Tavily
 * Matches the pattern from deepagentsjs examples
 */
const internetSearch = tool(
  async ({
    query,
    maxResults = 5,
    topic = "general",
    includeRawContent = false,
  }: {
    query: string;
    maxResults?: number;
    topic?: "general" | "news" | "finance";
    includeRawContent?: boolean;
  }) => {
    const tavily = new TavilySearch({
      maxResults,
      topic,
      includeRawContent,
      // API key is read from TAVILY_API_KEY env var
    });

    const results = await tavily.invoke({ query });
    return results;
  },
  {
    name: "internet_search",
    description:
      "Search the web for current information. Use this when you need up-to-date facts, news, or information not in your training data.",
    schema: z.object({
      query: z.string().describe("The search query"),
      maxResults: z
        .number()
        .optional()
        .default(5)
        .describe("Maximum number of results to return"),
      topic: z
        .enum(["general", "news", "finance"])
        .optional()
        .default("general")
        .describe("Topic category for the search"),
      includeRawContent: z
        .boolean()
        .optional()
        .default(false)
        .describe("Whether to include raw page content"),
    }),
  }
);

// =============================================================================
// Agent Creation using DeepAgents
// =============================================================================

/**
 * The main agent created using createDeepAgent from the deepagents package.
 *
 * This pattern matches the official deepagentsjs examples:
 * - Uses createDeepAgent() factory
 * - Configures model, tools, and system prompt
 * - Exports the agent directly for LangGraph Studio compatibility
 */
export const agent = createDeepAgent({
  model: new ChatAnthropic({
    model: "claude-sonnet-4-5-20250929",
    temperature: 0,
  }),
  tools: [internetSearch],
  systemPrompt: SYSTEM_PROMPT,
  checkpointer,
});

// =============================================================================
// Convenience function for testing
// =============================================================================

/**
 * Simple invoke function for CLI testing
 */
export async function invokeAgent(userMessage: string) {
  const result = await agent.invoke({
    messages: [{ role: "user", content: userMessage }],
  });
  return result;
}

  langgraph.json:
  {
    "graphs": {
      "simple-agent": "./agent.ts:agent"
    }
  }

Steps to Reproduce

  1. Create a Next.js 16 app with Turbopack enabled
  2. Set up the agent as shown above
  3. Run langgraph dev to start local LangGraph server
  4. Connect via LangGraph SDK from Next.js frontend
  5. Send any complex message that triggers the agent multi-step thinking ("what's the weather in toronto, and then find me a restaurant that's good for that weather open on monday")

Expected Behavior

Agent should process the message and respond normally.

Actual Behavior

Middleware chain fails with tool_use.id: Field required error from Anthropic API.

Debugging Notes

  • The error originates in the middleware chain, not in user code
  • The issue appears to be that somewhere in todoListMiddleware, FilesystemMiddleware, subAgentMiddleware, or PromptCachingMiddleware, a tool_use block is being created without the
    required id field
  • Suspect this may be related to Turbopack's bundling/module resolution interacting with deepagents internals

Additional Context

Using https://github.com/haydenbleasel/next-forge monorepo template. T

When I deploy my langgraph agent locally to langsmith, I still get this error

Image

Query

what's the weather in toronto, and then find me a restaurant that's good for that weather open on monday

("hi" works fine)

(testing multistep)

Originally created by @masonsuper on GitHub (Jan 25, 2026). Original GitHub issue: https://github.com/langchain-ai/deepagentsjs/issues/141 Originally assigned to: @hntrl on GitHub. ### Description When using createDeepAgent in a Next.js 16 application with Turbopack, API calls fail with an Anthropic error indicating a missing id field in tool_use messages. This is blocking my enterprise deployment trying to use deepagents, would love if this could get prioritized my repo uses the app from: https://www.next-forge.com/docs ### Error Message Error in middleware "todoListMiddleware": Error in middleware "FilesystemMiddleware": Error in middleware "subAgentMiddleware": Error in middleware "PromptCachingMiddleware": 400 {"type":"error","error":{"type":"invalid_request_error", "message":"messages.3.content.2.tool_use.id: Field required"},"request_id":"req_011CXTfGknp5jQ4vxZmVExmT"} <img width="1906" height="1034" alt="Image" src="https://github.com/user-attachments/assets/c8714187-138b-412e-84c7-02c06a327f7b" /> ### Environment - deepagents: 1.4.1 - @langchain/langgraph: 1.0.14 - @langchain/anthropic: 1.3.7 - @langchain/core: 1.1.12 - Next.js: 16.0.10 (with Turbopack) - Node.js: 20.x - Framework: next-forge monorepo ### Code ``` /** * Simple Agent - DeepAgents Implementation * * A minimal agent using the deepagents library, following the official * research-agent.ts example from langchain-ai/deepagentsjs. * * Reference: https://github.com/langchain-ai/deepagentsjs/blob/main/examples/research/research-agent.ts */ import { ChatAnthropic } from "@langchain/anthropic"; import { tool } from "@langchain/core/tools"; import { MemorySaver } from "@langchain/langgraph"; import { TavilySearch } from "@langchain/tavily"; import { createDeepAgent } from "deepagents"; import { z } from "zod"; import { SYSTEM_PROMPT } from "./prompts"; // Checkpointer for LangGraph Studio thread persistence const checkpointer = new MemorySaver(); // ============================================================================= // Tools // ============================================================================= /** * Web search tool using Tavily * Matches the pattern from deepagentsjs examples */ const internetSearch = tool( async ({ query, maxResults = 5, topic = "general", includeRawContent = false, }: { query: string; maxResults?: number; topic?: "general" | "news" | "finance"; includeRawContent?: boolean; }) => { const tavily = new TavilySearch({ maxResults, topic, includeRawContent, // API key is read from TAVILY_API_KEY env var }); const results = await tavily.invoke({ query }); return results; }, { name: "internet_search", description: "Search the web for current information. Use this when you need up-to-date facts, news, or information not in your training data.", schema: z.object({ query: z.string().describe("The search query"), maxResults: z .number() .optional() .default(5) .describe("Maximum number of results to return"), topic: z .enum(["general", "news", "finance"]) .optional() .default("general") .describe("Topic category for the search"), includeRawContent: z .boolean() .optional() .default(false) .describe("Whether to include raw page content"), }), } ); // ============================================================================= // Agent Creation using DeepAgents // ============================================================================= /** * The main agent created using createDeepAgent from the deepagents package. * * This pattern matches the official deepagentsjs examples: * - Uses createDeepAgent() factory * - Configures model, tools, and system prompt * - Exports the agent directly for LangGraph Studio compatibility */ export const agent = createDeepAgent({ model: new ChatAnthropic({ model: "claude-sonnet-4-5-20250929", temperature: 0, }), tools: [internetSearch], systemPrompt: SYSTEM_PROMPT, checkpointer, }); // ============================================================================= // Convenience function for testing // ============================================================================= /** * Simple invoke function for CLI testing */ export async function invokeAgent(userMessage: string) { const result = await agent.invoke({ messages: [{ role: "user", content: userMessage }], }); return result; } ``` ``` langgraph.json: { "graphs": { "simple-agent": "./agent.ts:agent" } } ``` ### Steps to Reproduce 1. Create a Next.js 16 app with Turbopack enabled 2. Set up the agent as shown above 3. Run langgraph dev to start local LangGraph server 4. Connect via LangGraph SDK from Next.js frontend 5. Send any complex message that triggers the agent multi-step thinking ("what's the weather in toronto, and then find me a restaurant that's good for that weather open on monday") ### Expected Behavior Agent should process the message and respond normally. ### Actual Behavior Middleware chain fails with tool_use.id: Field required error from Anthropic API. ### Debugging Notes - The error originates in the middleware chain, not in user code - The issue appears to be that somewhere in todoListMiddleware, FilesystemMiddleware, subAgentMiddleware, or PromptCachingMiddleware, a tool_use block is being created without the required id field - Suspect this may be related to Turbopack's bundling/module resolution interacting with deepagents internals ### Additional Context Using https://github.com/haydenbleasel/next-forge monorepo template. T When I deploy my langgraph agent locally to langsmith, I still get this error <img width="1916" height="989" alt="Image" src="https://github.com/user-attachments/assets/c8593940-ede2-4fef-b26a-3e4ebb5d4cea" /> ### Query > what's the weather in toronto, and then find me a restaurant that's good for that weather open on monday ("hi" works fine) (testing multistep)
yindo closed this issue 2026-02-16 06:16:56 -05:00
Author
Owner

@masonsuper commented on GitHub (Jan 25, 2026):

  145 +  "@langchain/anthropic": "1.3.12",
  146 +  "@langchain/core": "1.1.12",
  147 +  "@langchain/langgraph": "1.0.14",
  148 +  "@langchain/langgraph-sdk": "1.4.6",
  149 +  "deepagents": "1.6.0"

fixed once I switched to these versions! took some messing around

@masonsuper commented on GitHub (Jan 25, 2026): 145 + "@langchain/anthropic": "1.3.12", 146 + "@langchain/core": "1.1.12", 147 + "@langchain/langgraph": "1.0.14", 148 + "@langchain/langgraph-sdk": "1.4.6", 149 + "deepagents": "1.6.0" fixed once I switched to these versions! took some messing around
Author
Owner

@masonsuper commented on GitHub (Jan 25, 2026):

  145 +  "@langchain/anthropic": "1.3.12",
  146 +  "@langchain/core": "1.1.12",
  147 +  "@langchain/langgraph": "1.0.14",
  148 +  "@langchain/langgraph-sdk": "1.4.6",
  149 +  "deepagents": "1.6.0"

fixed once I switched to these versions! took some messing around

nevermind, issue is back

@masonsuper commented on GitHub (Jan 25, 2026): > ``` > 145 + "@langchain/anthropic": "1.3.12", > 146 + "@langchain/core": "1.1.12", > 147 + "@langchain/langgraph": "1.0.14", > 148 + "@langchain/langgraph-sdk": "1.4.6", > 149 + "deepagents": "1.6.0" > ``` > > fixed once I switched to these versions! took some messing around nevermind, issue is back
Author
Owner

@hntrl commented on GitHub (Feb 3, 2026):

Addressing separately -- believe this has to do with incompatible versions

@hntrl commented on GitHub (Feb 3, 2026): Addressing separately -- believe this has to do with incompatible versions
yindo changed title from tool_use.id: Field required error when using deepagents with Next.js + Turbopack (blocking enterprise deployment) to [GH-ISSUE #141] tool_use.id: Field required error when using deepagents with Next.js + Turbopack (blocking enterprise deployment) 2026-06-05 17:21:06 -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#35