@langchain/langgraph 0.2.47 → 0.2.49

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -127,4 +127,4 @@ export type CreateReactAgentParams<A extends AnnotationRoot<any> = AnnotationRoo
127
127
  * // Returns the messages in the state at each step of execution
128
128
  * ```
129
129
  */
130
- export declare function createReactAgent<A extends AnnotationRoot<any> = AnnotationRoot<{}>, StructuredResponseFormat extends Record<string, any> = Record<string, any>>(params: CreateReactAgentParams<A, StructuredResponseFormat>): CompiledStateGraph<(typeof MessagesAnnotation)["State"], (typeof MessagesAnnotation)["Update"], any, typeof MessagesAnnotation.spec & A["spec"], ReturnType<typeof createReactAgentAnnotation<StructuredResponseFormat>>["spec"] & A["spec"]>;
130
+ export declare function createReactAgent<A extends AnnotationRoot<any> = typeof MessagesAnnotation, StructuredResponseFormat extends Record<string, any> = Record<string, any>>(params: CreateReactAgentParams<A, StructuredResponseFormat>): CompiledStateGraph<A["State"], A["Update"], any, typeof MessagesAnnotation.spec & A["spec"], ReturnType<typeof createReactAgentAnnotation<StructuredResponseFormat>>["spec"] & A["spec"]>;
@@ -66,22 +66,30 @@ class StreamMessagesHandler extends base_1.BaseCallbackHandler {
66
66
  this.seen[message.id] !== undefined) {
67
67
  return;
68
68
  }
69
- // For instance in ChatAnthropic, the first chunk has an message ID
70
- // but the subsequent chunks do not. To avoid clients seeing two messages
71
- // we rename the message ID if it's being auto-set to `run-${runId}`
72
- // (see https://github.com/langchain-ai/langchainjs/pull/6646).
73
69
  let messageId = message.id;
74
- if (messageId == null || messageId === `run-${runId}`) {
75
- messageId = this.stableMessageIdMap[runId] ?? messageId ?? `run-${runId}`;
70
+ if ((0, messages_1.isToolMessage)(message)) {
71
+ // Distinguish tool messages by tool call ID.
72
+ messageId ??= `run-${runId}-tool-${message.tool_call_id}`;
73
+ }
74
+ else {
75
+ // For instance in ChatAnthropic, the first chunk has an message ID
76
+ // but the subsequent chunks do not. To avoid clients seeing two messages
77
+ // we rename the message ID if it's being auto-set to `run-${runId}`
78
+ // (see https://github.com/langchain-ai/langchainjs/pull/6646).
79
+ if (messageId == null || messageId === `run-${runId}`) {
80
+ messageId =
81
+ this.stableMessageIdMap[runId] ?? messageId ?? `run-${runId}`;
82
+ }
83
+ this.stableMessageIdMap[runId] ??= messageId;
76
84
  }
77
- this.stableMessageIdMap[runId] ??= messageId;
78
85
  if (messageId !== message.id) {
79
86
  // eslint-disable-next-line no-param-reassign
80
87
  message.id = messageId;
81
88
  // eslint-disable-next-line no-param-reassign
82
89
  message.lc_kwargs.id = messageId;
83
90
  }
84
- this.seen[message.id] = message;
91
+ if (message.id != null)
92
+ this.seen[message.id] = message;
85
93
  this.streamFn([meta[0], "messages", [message, meta[1]]]);
86
94
  }
87
95
  handleChatModelStart(_llm, _messages, runId, _parentRunId, _extraParams, tags, metadata, name) {
@@ -1,5 +1,5 @@
1
1
  import { BaseCallbackHandler, } from "@langchain/core/callbacks/base";
2
- import { AIMessageChunk, isBaseMessage, } from "@langchain/core/messages";
2
+ import { AIMessageChunk, isBaseMessage, isToolMessage, } from "@langchain/core/messages";
3
3
  import { TAG_HIDDEN, TAG_NOSTREAM } from "../constants.js";
4
4
  function isChatGenerationChunk(x) {
5
5
  return isBaseMessage(x?.message);
@@ -63,22 +63,30 @@ export class StreamMessagesHandler extends BaseCallbackHandler {
63
63
  this.seen[message.id] !== undefined) {
64
64
  return;
65
65
  }
66
- // For instance in ChatAnthropic, the first chunk has an message ID
67
- // but the subsequent chunks do not. To avoid clients seeing two messages
68
- // we rename the message ID if it's being auto-set to `run-${runId}`
69
- // (see https://github.com/langchain-ai/langchainjs/pull/6646).
70
66
  let messageId = message.id;
71
- if (messageId == null || messageId === `run-${runId}`) {
72
- messageId = this.stableMessageIdMap[runId] ?? messageId ?? `run-${runId}`;
67
+ if (isToolMessage(message)) {
68
+ // Distinguish tool messages by tool call ID.
69
+ messageId ??= `run-${runId}-tool-${message.tool_call_id}`;
70
+ }
71
+ else {
72
+ // For instance in ChatAnthropic, the first chunk has an message ID
73
+ // but the subsequent chunks do not. To avoid clients seeing two messages
74
+ // we rename the message ID if it's being auto-set to `run-${runId}`
75
+ // (see https://github.com/langchain-ai/langchainjs/pull/6646).
76
+ if (messageId == null || messageId === `run-${runId}`) {
77
+ messageId =
78
+ this.stableMessageIdMap[runId] ?? messageId ?? `run-${runId}`;
79
+ }
80
+ this.stableMessageIdMap[runId] ??= messageId;
73
81
  }
74
- this.stableMessageIdMap[runId] ??= messageId;
75
82
  if (messageId !== message.id) {
76
83
  // eslint-disable-next-line no-param-reassign
77
84
  message.id = messageId;
78
85
  // eslint-disable-next-line no-param-reassign
79
86
  message.lc_kwargs.id = messageId;
80
87
  }
81
- this.seen[message.id] = message;
88
+ if (message.id != null)
89
+ this.seen[message.id] = message;
82
90
  this.streamFn([meta[0], "messages", [message, meta[1]]]);
83
91
  }
84
92
  handleChatModelStart(_llm, _messages, runId, _parentRunId, _extraParams, tags, metadata, name) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@langchain/langgraph",
3
- "version": "0.2.47",
3
+ "version": "0.2.49",
4
4
  "description": "LangGraph",
5
5
  "type": "module",
6
6
  "engines": {