[GH-ISSUE #295] MiddlewareError2: Invalid response from "wrapModelCall" in middleware "SkillsMiddleware": expected AIMessage or Command, got object at MiddlewareError2.wrap (D:\AllItemProduct\helix-client\out\main\index.js:84643:12) #244

Closed
opened 2026-06-05 17:21:14 -04:00 by yindo · 4 comments
Owner

Originally created by @caohuiyihao on GitHub (Mar 10, 2026).
Original GitHub issue: https://github.com/langchain-ai/deepagentsjs/issues/295

Originally assigned to: @maahir30 on GitHub.

After the response content was outputted normally, an error was suddenly caught: MiddlewareError2: Invalid response from "wrapModelCall" in middleware "SkillsMiddleware": expected AIMessage or Command, got object at MiddlewareError2.wrap (D:\AllItemProduct\helix-client\out\main\index.js:84643:12) This issue only occurs when using deepagents to create agents. If using langchain to create agents, there is no such problem. Used versions: "deepagents": "1.8.2", "langchain": "1.2.29", "@langchain/langgraph": "1.2.0", "@langchain/openai": "1.2.12",
I tried removing the skills configuration, but the error persisted: MiddlewareError2: Invalid response from "wrapModelCall" in middleware "patchToolCallsMiddleware": expected AIMessage or Command, got object. I also tried removing the tools configuration, but the error still occurred: MiddlewareError2: Invalid response from "wrapModelCall" in middleware "patchToolCallsMiddleware": expected AIMessage or Command, got object

`const backend = getBackend();

this.agent = createDeepAgent({
  backend,
  interruptOn: {
    delete_file: true,
    write_file: false,
    delete_file_dir: true,
    move_file: true,
    copy_file: false,
    get_file_info: false,
    get_file_list: false,
    shell_command: false,
  },
  checkpointer,
  name: this.name,
  model,
  systemPrompt: this.systemPrompt,
  // middleware: [autoSkillMiddleware()],
  middleware: [],
  // tools,
  // skills: [`${SKILLS_DIR}`],
});`
Originally created by @caohuiyihao on GitHub (Mar 10, 2026). Original GitHub issue: https://github.com/langchain-ai/deepagentsjs/issues/295 Originally assigned to: @maahir30 on GitHub. After the response content was outputted normally, an error was suddenly caught: MiddlewareError2: Invalid response from "wrapModelCall" in middleware "SkillsMiddleware": expected AIMessage or Command, got object at MiddlewareError2.wrap (D:\AllItemProduct\helix-client\out\main\index.js:84643:12) This issue only occurs when using deepagents to create agents. If using langchain to create agents, there is no such problem. Used versions: "deepagents": "1.8.2", "langchain": "1.2.29", "@langchain/langgraph": "1.2.0", "@langchain/openai": "1.2.12", I tried removing the skills configuration, but the error persisted: MiddlewareError2: Invalid response from "wrapModelCall" in middleware "patchToolCallsMiddleware": expected AIMessage or Command, got object. I also tried removing the tools configuration, but the error still occurred: MiddlewareError2: Invalid response from "wrapModelCall" in middleware "patchToolCallsMiddleware": expected AIMessage or Command, got object `const backend = getBackend(); this.agent = createDeepAgent({ backend, interruptOn: { delete_file: true, write_file: false, delete_file_dir: true, move_file: true, copy_file: false, get_file_info: false, get_file_list: false, shell_command: false, }, checkpointer, name: this.name, model, systemPrompt: this.systemPrompt, // middleware: [autoSkillMiddleware()], middleware: [], // tools, // skills: [`${SKILLS_DIR}`], });`
yindo added the bugtriage: high-impact labels 2026-06-05 17:21:14 -04:00
yindo closed this issue 2026-06-05 17:21:14 -04:00
Author
Owner

@ohyear09 commented on GitHub (Mar 11, 2026):

same error: Invalid response from "wrapModelCall" in middleware "patchToolCallsMiddleware": expected AIMessage or Command, got object

<!-- gh-comment-id:4037804049 --> @ohyear09 commented on GitHub (Mar 11, 2026): same error: Invalid response from "wrapModelCall" in middleware "patchToolCallsMiddleware": expected AIMessage or Command, got object
Author
Owner

@caohuiyihao commented on GitHub (Mar 11, 2026):

same error: Invalid response from "wrapModelCall" in middleware "patchToolCallsMiddleware": expected AIMessage or Command, got object

The issue of return format verification is caused by the deepagent package intercepting the return format verification when it does not meet the requirements. You can try replacing the model, but this will not fundamentally solve the problem. The community has previously discussed this issue on https://forum.langchain.com/t/agent-structured-output-middleware-error/2067, but it seems to have not been resolved yet. Please keep an eye on this issue, and if it is resolved, please let me know as soon as possible. Thank you

<!-- gh-comment-id:4037877457 --> @caohuiyihao commented on GitHub (Mar 11, 2026): > same error: Invalid response from "wrapModelCall" in middleware "patchToolCallsMiddleware": expected AIMessage or Command, got object The issue of return format verification is caused by the deepagent package intercepting the return format verification when it does not meet the requirements. You can try replacing the model, but this will not fundamentally solve the problem. The community has previously discussed this issue on https://forum.langchain.com/t/agent-structured-output-middleware-error/2067, but it seems to have not been resolved yet. Please keep an eye on this issue, and if it is resolved, please let me know as soon as possible. Thank you
Author
Owner

@maahir30 commented on GitHub (Mar 19, 2026):

Thanks for reporting this. Could you share the exact versions of langchain, @langchain/core, and @langchain/langgraph from your lockfile?

Looks like this error comes from langchain's middleware validation layer, not from deepagentsjs. Could you try upgrading langchain to >=1.2.34 and see if that resolves it?

<!-- gh-comment-id:4094532178 --> @maahir30 commented on GitHub (Mar 19, 2026): Thanks for reporting this. Could you share the exact versions of `langchain`, `@langchain/core`, and `@langchain/langgraph` from your lockfile? Looks like this error comes from langchain's middleware validation layer, not from deepagentsjs. Could you try upgrading langchain to >=1.2.34 and see if that resolves it?
Author
Owner

@hntrl commented on GitHub (Jun 2, 2026):

Closing due to inactivity. If you have more details on if and how this is still happening that would be much appreciated.

<!-- gh-comment-id:4605505723 --> @hntrl commented on GitHub (Jun 2, 2026): Closing due to inactivity. If you have more details on if and how this is still happening that would be much appreciated.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: langchain-ai/deepagentsjs#244