You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/docs/concepts/messages.mdx
+35-1Lines changed: 35 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -147,7 +147,7 @@ An `AIMessage` has the following attributes. The attributes which are **standard
147
147
|`tool_calls`| Standardized | Tool calls associated with the message. See [tool calling](/docs/concepts/tool_calling) for details. |
148
148
|`invalid_tool_calls`| Standardized | Tool calls with parsing errors associated with the message. See [tool calling](/docs/concepts/tool_calling) for details. |
149
149
|`usage_metadata`| Standardized | Usage metadata for a message, such as [token counts](/docs/concepts/tokens). See [Usage Metadata API Reference](https://python.langchain.com/api_reference/core/messages/langchain_core.messages.ai.UsageMetadata.html). |
150
-
|`id`| Standardized | An optional unique identifier for the message, ideally provided by the provider/model that created the message. |
150
+
|`id`| Standardized | An optional unique identifier for the message, ideally provided by the provider/model that created the message. See [Message IDs](#message-ids) for details. |
@@ -243,3 +243,37 @@ At the moment, the output of the model will be in terms of LangChain messages, s
243
243
need OpenAI format for the output as well.
244
244
245
245
The [convert_to_openai_messages](https://python.langchain.com/api_reference/core/messages/langchain_core.messages.utils.convert_to_openai_messages.html) utility function can be used to convert from LangChain messages to OpenAI format.
246
+
247
+
## Message IDs
248
+
249
+
LangChain messages include an optional `id` field that serves as a unique identifier. Understanding when and how these IDs are assigned can be helpful for debugging, tracing, and working with message history.
250
+
251
+
### When Messages Get IDs
252
+
253
+
Messages receive IDs in the following scenarios:
254
+
255
+
**Automatically assigned by LangChain:**
256
+
- When generated through chat model invocation (`.invoke()`, `.stream()`, `.astream()`) with an active run manager/tracing context
0 commit comments