[PR #102] [CLOSED] fix: resolve instanceof AIMessageChunk failing for Ollama provider #121

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

📋 Pull Request Information

Original PR: https://github.com/langchain-ai/deepagentsjs/pull/102
Author: @VedantMadane
Created: 1/10/2026
Status: Closed

Base: mainHead: fix/ollama-instanceof-64


📝 Commits (1)

  • 08911a1 fix: resolve instanceof AIMessageChunk failing for Ollama provider

📊 Changes

5 files changed (+119 additions, -3 deletions)

View changed files

📝 libs/deepagents/package.json (+1 -0)
📝 libs/deepagents/src/middleware/fs.ts (+2 -2)
libs/deepagents/src/ollama-instanceof.int.test.ts (+82 -0)
📝 libs/deepagents/tsdown.config.ts (+6 -0)
📝 pnpm-lock.yaml (+28 -1)

📄 Description

Closes #64

Problem

When streaming responses using the Ollama provider, chunks look like AIMessageChunk objects but instanceof AIMessageChunk returns false. This happens because @langchain/core was being bundled, creating a duplicate module instance with a different prototype chain.

Solution

  1. Externalize @langchain/core in tsdown bundler config to prevent duplicate module instances
  2. Replace internal instanceof ToolMessage checks with the more robust ToolMessage.isInstance() pattern

Testing

  • Added integration test that verifies Ollama-streamed chunks pass both instanceof AIMessageChunk and AIMessageChunk.isInstance()
  • All 178 existing unit tests pass

🔄 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/102 **Author:** [@VedantMadane](https://github.com/VedantMadane) **Created:** 1/10/2026 **Status:** ❌ Closed **Base:** `main` ← **Head:** `fix/ollama-instanceof-64` --- ### 📝 Commits (1) - [`08911a1`](https://github.com/langchain-ai/deepagentsjs/commit/08911a14d300d20264e00ec425ec681f82752b9e) fix: resolve instanceof AIMessageChunk failing for Ollama provider ### 📊 Changes **5 files changed** (+119 additions, -3 deletions) <details> <summary>View changed files</summary> 📝 `libs/deepagents/package.json` (+1 -0) 📝 `libs/deepagents/src/middleware/fs.ts` (+2 -2) ➕ `libs/deepagents/src/ollama-instanceof.int.test.ts` (+82 -0) 📝 `libs/deepagents/tsdown.config.ts` (+6 -0) 📝 `pnpm-lock.yaml` (+28 -1) </details> ### 📄 Description Closes #64 ## Problem When streaming responses using the Ollama provider, chunks look like AIMessageChunk objects but instanceof AIMessageChunk returns false. This happens because @langchain/core was being bundled, creating a duplicate module instance with a different prototype chain. ## Solution 1. Externalize @langchain/core in tsdown bundler config to prevent duplicate module instances 2. Replace internal instanceof ToolMessage checks with the more robust ToolMessage.isInstance() pattern ## Testing - Added integration test that verifies Ollama-streamed chunks pass both instanceof AIMessageChunk and AIMessageChunk.isInstance() - All 178 existing unit tests pass --- <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:13 -05:00
yindo closed this issue 2026-02-16 06:17:13 -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#121