File tree 7 files changed +18
-0
lines changed
langchain-core/src/messages
7 files changed +18
-0
lines changed Original file line number Diff line number Diff line change @@ -244,6 +244,7 @@ export class AIMessageChunk extends BaseMessageChunk {
244
244
chunk . response_metadata
245
245
) ,
246
246
tool_call_chunks : [ ] ,
247
+ id : this . id ?? chunk . id ,
247
248
} ;
248
249
if (
249
250
this . tool_call_chunks !== undefined ||
Original file line number Diff line number Diff line change @@ -106,6 +106,11 @@ export type BaseMessageFields = {
106
106
/** Response metadata. For example: response headers, logprobs, token counts. */
107
107
// eslint-disable-next-line @typescript-eslint/no-explicit-any
108
108
response_metadata ?: Record < string , any > ;
109
+ /**
110
+ * An optional unique identifier for the message. This should ideally be
111
+ * provided by the provider/model which created the message.
112
+ */
113
+ id ?: string ;
109
114
} ;
110
115
111
116
export function mergeContent (
@@ -170,6 +175,12 @@ export abstract class BaseMessage
170
175
/** Response metadata. For example: response headers, logprobs, token counts. */
171
176
response_metadata : NonNullable < BaseMessageFields [ "response_metadata" ] > ;
172
177
178
+ /**
179
+ * An optional unique identifier for the message. This should ideally be
180
+ * provided by the provider/model which created the message.
181
+ */
182
+ id ?: string ;
183
+
173
184
/** The type of the message. */
174
185
abstract _getType ( ) : MessageType ;
175
186
@@ -200,6 +211,7 @@ export abstract class BaseMessage
200
211
this . content = fields . content ;
201
212
this . additional_kwargs = fields . additional_kwargs ;
202
213
this . response_metadata = fields . response_metadata ;
214
+ this . id = fields . id ;
203
215
}
204
216
205
217
toDict ( ) : StoredMessage {
Original file line number Diff line number Diff line change @@ -90,6 +90,7 @@ export class ChatMessageChunk extends BaseMessageChunk {
90
90
chunk . response_metadata
91
91
) ,
92
92
role : this . role ,
93
+ id : this . id ?? chunk . id ,
93
94
} ) ;
94
95
}
95
96
}
Original file line number Diff line number Diff line change @@ -69,6 +69,7 @@ export class FunctionMessageChunk extends BaseMessageChunk {
69
69
chunk . response_metadata
70
70
) ,
71
71
name : this . name ?? "" ,
72
+ id : this . id ?? chunk . id ,
72
73
} ) ;
73
74
}
74
75
}
Original file line number Diff line number Diff line change @@ -43,6 +43,7 @@ export class HumanMessageChunk extends BaseMessageChunk {
43
43
this . response_metadata ,
44
44
chunk . response_metadata
45
45
) ,
46
+ id : this . id ?? chunk . id ,
46
47
} ) ;
47
48
}
48
49
}
Original file line number Diff line number Diff line change @@ -43,6 +43,7 @@ export class SystemMessageChunk extends BaseMessageChunk {
43
43
this . response_metadata ,
44
44
chunk . response_metadata
45
45
) ,
46
+ id : this . id ?? chunk . id ,
46
47
} ) ;
47
48
}
48
49
}
Original file line number Diff line number Diff line change @@ -88,6 +88,7 @@ export class ToolMessageChunk extends BaseMessageChunk {
88
88
chunk . response_metadata
89
89
) ,
90
90
tool_call_id : this . tool_call_id ,
91
+ id : this . id ?? chunk . id ,
91
92
} ) ;
92
93
}
93
94
}
You can’t perform that action at this time.
0 commit comments