langchain-core 1.0.0a5__py3-none-any.whl → 1.0.3__py3-none-any.whl

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.
Files changed (165) hide show
  1. langchain_core/__init__.py +1 -1
  2. langchain_core/_api/__init__.py +3 -4
  3. langchain_core/_api/beta_decorator.py +23 -26
  4. langchain_core/_api/deprecation.py +51 -64
  5. langchain_core/_api/path.py +3 -6
  6. langchain_core/_import_utils.py +3 -4
  7. langchain_core/agents.py +20 -22
  8. langchain_core/caches.py +65 -66
  9. langchain_core/callbacks/__init__.py +1 -8
  10. langchain_core/callbacks/base.py +321 -336
  11. langchain_core/callbacks/file.py +44 -44
  12. langchain_core/callbacks/manager.py +436 -513
  13. langchain_core/callbacks/stdout.py +29 -30
  14. langchain_core/callbacks/streaming_stdout.py +32 -32
  15. langchain_core/callbacks/usage.py +60 -57
  16. langchain_core/chat_history.py +53 -68
  17. langchain_core/document_loaders/base.py +27 -25
  18. langchain_core/document_loaders/blob_loaders.py +1 -1
  19. langchain_core/document_loaders/langsmith.py +44 -48
  20. langchain_core/documents/__init__.py +23 -3
  21. langchain_core/documents/base.py +98 -90
  22. langchain_core/documents/compressor.py +10 -10
  23. langchain_core/documents/transformers.py +34 -35
  24. langchain_core/embeddings/fake.py +50 -54
  25. langchain_core/example_selectors/length_based.py +1 -1
  26. langchain_core/example_selectors/semantic_similarity.py +28 -32
  27. langchain_core/exceptions.py +21 -20
  28. langchain_core/globals.py +3 -151
  29. langchain_core/indexing/__init__.py +1 -1
  30. langchain_core/indexing/api.py +121 -126
  31. langchain_core/indexing/base.py +73 -75
  32. langchain_core/indexing/in_memory.py +4 -6
  33. langchain_core/language_models/__init__.py +14 -29
  34. langchain_core/language_models/_utils.py +58 -61
  35. langchain_core/language_models/base.py +53 -162
  36. langchain_core/language_models/chat_models.py +298 -387
  37. langchain_core/language_models/fake.py +11 -11
  38. langchain_core/language_models/fake_chat_models.py +42 -36
  39. langchain_core/language_models/llms.py +125 -235
  40. langchain_core/load/dump.py +9 -12
  41. langchain_core/load/load.py +18 -28
  42. langchain_core/load/mapping.py +2 -4
  43. langchain_core/load/serializable.py +42 -40
  44. langchain_core/messages/__init__.py +10 -16
  45. langchain_core/messages/ai.py +148 -148
  46. langchain_core/messages/base.py +58 -52
  47. langchain_core/messages/block_translators/__init__.py +27 -17
  48. langchain_core/messages/block_translators/anthropic.py +6 -6
  49. langchain_core/messages/block_translators/bedrock_converse.py +5 -5
  50. langchain_core/messages/block_translators/google_genai.py +505 -20
  51. langchain_core/messages/block_translators/google_vertexai.py +4 -32
  52. langchain_core/messages/block_translators/groq.py +117 -21
  53. langchain_core/messages/block_translators/langchain_v0.py +5 -5
  54. langchain_core/messages/block_translators/openai.py +11 -11
  55. langchain_core/messages/chat.py +2 -6
  56. langchain_core/messages/content.py +337 -328
  57. langchain_core/messages/function.py +6 -10
  58. langchain_core/messages/human.py +24 -31
  59. langchain_core/messages/modifier.py +2 -2
  60. langchain_core/messages/system.py +19 -29
  61. langchain_core/messages/tool.py +74 -90
  62. langchain_core/messages/utils.py +474 -504
  63. langchain_core/output_parsers/__init__.py +13 -10
  64. langchain_core/output_parsers/base.py +61 -61
  65. langchain_core/output_parsers/format_instructions.py +9 -4
  66. langchain_core/output_parsers/json.py +12 -10
  67. langchain_core/output_parsers/list.py +21 -23
  68. langchain_core/output_parsers/openai_functions.py +49 -47
  69. langchain_core/output_parsers/openai_tools.py +16 -21
  70. langchain_core/output_parsers/pydantic.py +13 -14
  71. langchain_core/output_parsers/string.py +5 -5
  72. langchain_core/output_parsers/transform.py +15 -17
  73. langchain_core/output_parsers/xml.py +35 -34
  74. langchain_core/outputs/__init__.py +1 -1
  75. langchain_core/outputs/chat_generation.py +18 -18
  76. langchain_core/outputs/chat_result.py +1 -3
  77. langchain_core/outputs/generation.py +10 -11
  78. langchain_core/outputs/llm_result.py +10 -10
  79. langchain_core/prompt_values.py +11 -17
  80. langchain_core/prompts/__init__.py +3 -27
  81. langchain_core/prompts/base.py +48 -56
  82. langchain_core/prompts/chat.py +275 -325
  83. langchain_core/prompts/dict.py +5 -5
  84. langchain_core/prompts/few_shot.py +81 -88
  85. langchain_core/prompts/few_shot_with_templates.py +11 -13
  86. langchain_core/prompts/image.py +12 -14
  87. langchain_core/prompts/loading.py +4 -6
  88. langchain_core/prompts/message.py +3 -3
  89. langchain_core/prompts/prompt.py +24 -39
  90. langchain_core/prompts/string.py +26 -10
  91. langchain_core/prompts/structured.py +49 -53
  92. langchain_core/rate_limiters.py +51 -60
  93. langchain_core/retrievers.py +61 -198
  94. langchain_core/runnables/base.py +1478 -1630
  95. langchain_core/runnables/branch.py +53 -57
  96. langchain_core/runnables/config.py +72 -89
  97. langchain_core/runnables/configurable.py +120 -137
  98. langchain_core/runnables/fallbacks.py +83 -79
  99. langchain_core/runnables/graph.py +91 -97
  100. langchain_core/runnables/graph_ascii.py +27 -28
  101. langchain_core/runnables/graph_mermaid.py +38 -50
  102. langchain_core/runnables/graph_png.py +15 -16
  103. langchain_core/runnables/history.py +135 -148
  104. langchain_core/runnables/passthrough.py +124 -150
  105. langchain_core/runnables/retry.py +46 -51
  106. langchain_core/runnables/router.py +25 -30
  107. langchain_core/runnables/schema.py +75 -80
  108. langchain_core/runnables/utils.py +60 -67
  109. langchain_core/stores.py +85 -121
  110. langchain_core/structured_query.py +8 -8
  111. langchain_core/sys_info.py +27 -29
  112. langchain_core/tools/__init__.py +1 -14
  113. langchain_core/tools/base.py +285 -229
  114. langchain_core/tools/convert.py +160 -155
  115. langchain_core/tools/render.py +10 -10
  116. langchain_core/tools/retriever.py +12 -11
  117. langchain_core/tools/simple.py +19 -24
  118. langchain_core/tools/structured.py +32 -39
  119. langchain_core/tracers/__init__.py +1 -9
  120. langchain_core/tracers/base.py +97 -99
  121. langchain_core/tracers/context.py +29 -52
  122. langchain_core/tracers/core.py +49 -53
  123. langchain_core/tracers/evaluation.py +11 -11
  124. langchain_core/tracers/event_stream.py +65 -64
  125. langchain_core/tracers/langchain.py +21 -21
  126. langchain_core/tracers/log_stream.py +45 -45
  127. langchain_core/tracers/memory_stream.py +3 -3
  128. langchain_core/tracers/root_listeners.py +16 -16
  129. langchain_core/tracers/run_collector.py +2 -4
  130. langchain_core/tracers/schemas.py +0 -129
  131. langchain_core/tracers/stdout.py +3 -3
  132. langchain_core/utils/__init__.py +1 -4
  133. langchain_core/utils/_merge.py +2 -2
  134. langchain_core/utils/aiter.py +57 -61
  135. langchain_core/utils/env.py +9 -9
  136. langchain_core/utils/function_calling.py +89 -186
  137. langchain_core/utils/html.py +7 -8
  138. langchain_core/utils/input.py +6 -6
  139. langchain_core/utils/interactive_env.py +1 -1
  140. langchain_core/utils/iter.py +36 -40
  141. langchain_core/utils/json.py +4 -3
  142. langchain_core/utils/json_schema.py +9 -9
  143. langchain_core/utils/mustache.py +8 -10
  144. langchain_core/utils/pydantic.py +33 -35
  145. langchain_core/utils/strings.py +6 -9
  146. langchain_core/utils/usage.py +1 -1
  147. langchain_core/utils/utils.py +66 -62
  148. langchain_core/vectorstores/base.py +182 -216
  149. langchain_core/vectorstores/in_memory.py +101 -176
  150. langchain_core/vectorstores/utils.py +5 -5
  151. langchain_core/version.py +1 -1
  152. langchain_core-1.0.3.dist-info/METADATA +69 -0
  153. langchain_core-1.0.3.dist-info/RECORD +172 -0
  154. {langchain_core-1.0.0a5.dist-info → langchain_core-1.0.3.dist-info}/WHEEL +1 -1
  155. langchain_core/memory.py +0 -120
  156. langchain_core/messages/block_translators/ollama.py +0 -47
  157. langchain_core/prompts/pipeline.py +0 -138
  158. langchain_core/pydantic_v1/__init__.py +0 -30
  159. langchain_core/pydantic_v1/dataclasses.py +0 -23
  160. langchain_core/pydantic_v1/main.py +0 -23
  161. langchain_core/tracers/langchain_v1.py +0 -31
  162. langchain_core/utils/loading.py +0 -35
  163. langchain_core-1.0.0a5.dist-info/METADATA +0 -77
  164. langchain_core-1.0.0a5.dist-info/RECORD +0 -181
  165. langchain_core-1.0.0a5.dist-info/entry_points.txt +0 -4
@@ -1,11 +1,11 @@
1
1
  """Standard, multimodal content blocks for Large Language Model I/O.
2
2
 
3
- .. warning::
3
+ !!! warning
4
4
  This module is under active development. The API is unstable and subject to
5
5
  change in future releases.
6
6
 
7
7
  This module provides standardized data structures for representing inputs to and
8
- outputs from LLMs. The core abstraction is the **Content Block**, a ``TypedDict``.
8
+ outputs from LLMs. The core abstraction is the **Content Block**, a `TypedDict`.
9
9
 
10
10
  **Rationale**
11
11
 
@@ -20,59 +20,59 @@ blocks into the format required by its API.
20
20
  **Extensibility**
21
21
 
22
22
  Data **not yet mapped** to a standard block may be represented using the
23
- ``NonStandardContentBlock``, which allows for provider-specific data to be included
23
+ `NonStandardContentBlock`, which allows for provider-specific data to be included
24
24
  without losing the benefits of type checking and validation.
25
25
 
26
26
  Furthermore, provider-specific fields **within** a standard block are fully supported
27
- by default in the ``extras`` field of each block. This allows for additional metadata
27
+ by default in the `extras` field of each block. This allows for additional metadata
28
28
  to be included without breaking the standard structure.
29
29
 
30
- .. warning::
31
- Do not heavily rely on the ``extras`` field for provider-specific data! This field
30
+ !!! warning
31
+ Do not heavily rely on the `extras` field for provider-specific data! This field
32
32
  is subject to deprecation in future releases as we move towards PEP 728.
33
33
 
34
- .. note::
35
- Following widespread adoption of `PEP 728 <https://peps.python.org/pep-0728/>`__, we
36
- will add ``extra_items=Any`` as a param to Content Blocks. This will signify to type
34
+ !!! note
35
+ Following widespread adoption of [PEP 728](https://peps.python.org/pep-0728/), we
36
+ will add `extra_items=Any` as a param to Content Blocks. This will signify to type
37
37
  checkers that additional provider-specific fields are allowed outside of the
38
- ``extras`` field, and that will become the new standard approach to adding
38
+ `extras` field, and that will become the new standard approach to adding
39
39
  provider-specific metadata.
40
40
 
41
- .. dropdown::
41
+ ??? note
42
42
 
43
43
  **Example with PEP 728 provider-specific fields:**
44
44
 
45
- .. code-block:: python
46
-
47
- # Content block definition
48
- # NOTE: `extra_items=Any`
49
- class TextContentBlock(TypedDict, extra_items=Any):
50
- type: Literal["text"]
51
- id: NotRequired[str]
52
- text: str
53
- annotations: NotRequired[list[Annotation]]
54
- index: NotRequired[int]
55
-
56
- .. code-block:: python
57
-
58
- from langchain_core.messages.content import TextContentBlock
59
-
60
- # Create a text content block with provider-specific fields
61
- my_block: TextContentBlock = {
62
- # Add required fields
63
- "type": "text",
64
- "text": "Hello, world!",
65
- # Additional fields not specified in the TypedDict
66
- # These are valid with PEP 728 and are typed as Any
67
- "openai_metadata": {"model": "gpt-4", "temperature": 0.7},
68
- "anthropic_usage": {"input_tokens": 10, "output_tokens": 20},
69
- "custom_field": "any value",
70
- }
71
-
72
- # Mutating an existing block to add provider-specific fields
73
- openai_data = my_block["openai_metadata"] # Type: Any
74
-
75
- PEP 728 is enabled with ``# type: ignore[call-arg]`` comments to suppress
45
+ ```python
46
+ # Content block definition
47
+ # NOTE: `extra_items=Any`
48
+ class TextContentBlock(TypedDict, extra_items=Any):
49
+ type: Literal["text"]
50
+ id: NotRequired[str]
51
+ text: str
52
+ annotations: NotRequired[list[Annotation]]
53
+ index: NotRequired[int]
54
+ ```
55
+
56
+ ```python
57
+ from langchain_core.messages.content import TextContentBlock
58
+
59
+ # Create a text content block with provider-specific fields
60
+ my_block: TextContentBlock = {
61
+ # Add required fields
62
+ "type": "text",
63
+ "text": "Hello, world!",
64
+ # Additional fields not specified in the TypedDict
65
+ # These are valid with PEP 728 and are typed as Any
66
+ "openai_metadata": {"model": "gpt-4", "temperature": 0.7},
67
+ "anthropic_usage": {"input_tokens": 10, "output_tokens": 20},
68
+ "custom_field": "any value",
69
+ }
70
+
71
+ # Mutating an existing block to add provider-specific fields
72
+ openai_data = my_block["openai_metadata"] # Type: Any
73
+ ```
74
+
75
+ PEP 728 is enabled with `# type: ignore[call-arg]` comments to suppress
76
76
  warnings from type checkers that don't yet support it. The functionality works
77
77
  correctly in Python 3.13+ and will be fully supported as the ecosystem catches
78
78
  up.
@@ -81,55 +81,54 @@ to be included without breaking the standard structure.
81
81
 
82
82
  The module defines several types of content blocks, including:
83
83
 
84
- - ``TextContentBlock``: Standard text output.
85
- - ``Citation``: For annotations that link text output to a source document.
86
- - ``ToolCall``: For function calling.
87
- - ``ReasoningContentBlock``: To capture a model's thought process.
84
+ - `TextContentBlock`: Standard text output.
85
+ - `Citation`: For annotations that link text output to a source document.
86
+ - `ToolCall`: For function calling.
87
+ - `ReasoningContentBlock`: To capture a model's thought process.
88
88
  - Multimodal data:
89
- - ``ImageContentBlock``
90
- - ``AudioContentBlock``
91
- - ``VideoContentBlock``
92
- - ``PlainTextContentBlock`` (e.g. .txt or .md files)
93
- - ``FileContentBlock`` (e.g. PDFs, etc.)
89
+ - `ImageContentBlock`
90
+ - `AudioContentBlock`
91
+ - `VideoContentBlock`
92
+ - `PlainTextContentBlock` (e.g. .txt or .md files)
93
+ - `FileContentBlock` (e.g. PDFs, etc.)
94
94
 
95
95
  **Example Usage**
96
96
 
97
- .. code-block:: python
98
-
99
- # Direct construction:
100
- from langchain_core.messages.content import TextContentBlock, ImageContentBlock
101
-
102
- multimodal_message: AIMessage(
103
- content_blocks=[
104
- TextContentBlock(type="text", text="What is shown in this image?"),
105
- ImageContentBlock(
106
- type="image",
107
- url="https://www.langchain.com/images/brand/langchain_logo_text_w_white.png",
108
- mime_type="image/png",
109
- ),
110
- ]
111
- )
112
-
113
- # Using factories:
114
- from langchain_core.messages.content import create_text_block, create_image_block
115
-
116
- multimodal_message: AIMessage(
117
- content=[
118
- create_text_block("What is shown in this image?"),
119
- create_image_block(
120
- url="https://www.langchain.com/images/brand/langchain_logo_text_w_white.png",
121
- mime_type="image/png",
122
- ),
123
- ]
124
- )
97
+ ```python
98
+ # Direct construction:
99
+ from langchain_core.messages.content import TextContentBlock, ImageContentBlock
100
+
101
+ multimodal_message: AIMessage(
102
+ content_blocks=[
103
+ TextContentBlock(type="text", text="What is shown in this image?"),
104
+ ImageContentBlock(
105
+ type="image",
106
+ url="https://www.langchain.com/images/brand/langchain_logo_text_w_white.png",
107
+ mime_type="image/png",
108
+ ),
109
+ ]
110
+ )
111
+
112
+ # Using factories:
113
+ from langchain_core.messages.content import create_text_block, create_image_block
114
+
115
+ multimodal_message: AIMessage(
116
+ content=[
117
+ create_text_block("What is shown in this image?"),
118
+ create_image_block(
119
+ url="https://www.langchain.com/images/brand/langchain_logo_text_w_white.png",
120
+ mime_type="image/png",
121
+ ),
122
+ ]
123
+ )
124
+ ```
125
125
 
126
126
  Factory functions offer benefits such as:
127
127
  - Automatic ID generation (when not provided)
128
- - No need to manually specify the ``type`` field
129
-
128
+ - No need to manually specify the `type` field
130
129
  """
131
130
 
132
- from typing import Any, Literal, Optional, Union, get_args, get_type_hints
131
+ from typing import Any, Literal, get_args, get_type_hints
133
132
 
134
133
  from typing_extensions import NotRequired, TypedDict
135
134
 
@@ -139,13 +138,13 @@ from langchain_core.utils.utils import ensure_id
139
138
  class Citation(TypedDict):
140
139
  """Annotation for citing data from a document.
141
140
 
142
- .. note::
143
- ``start``/``end`` indices refer to the **response text**,
141
+ !!! note
142
+ `start`/`end` indices refer to the **response text**,
144
143
  not the source text. This means that the indices are relative to the model's
145
- response, not the original document (as specified in the ``url``).
144
+ response, not the original document (as specified in the `url`).
146
145
 
147
- .. note::
148
- ``create_citation`` may also be used as a factory to create a ``Citation``.
146
+ !!! note "Factory function"
147
+ `create_citation` may also be used as a factory to create a `Citation`.
149
148
  Benefits include:
150
149
 
151
150
  * Automatic ID generation (when not provided)
@@ -157,10 +156,12 @@ class Citation(TypedDict):
157
156
  """Type of the content block. Used for discrimination."""
158
157
 
159
158
  id: NotRequired[str]
160
- """Content block identifier. Either:
159
+ """Content block identifier.
160
+
161
+ Either:
161
162
 
162
163
  - Generated by the provider (e.g., OpenAI's file ID)
163
- - Generated by LangChain upon creation (``UUID4`` prefixed with ``'lc_'``))
164
+ - Generated by LangChain upon creation (`UUID4` prefixed with `'lc_'`))
164
165
 
165
166
  """
166
167
 
@@ -174,10 +175,10 @@ class Citation(TypedDict):
174
175
  """
175
176
 
176
177
  start_index: NotRequired[int]
177
- """Start index of the **response text** (``TextContentBlock.text``)."""
178
+ """Start index of the **response text** (`TextContentBlock.text`)."""
178
179
 
179
180
  end_index: NotRequired[int]
180
- """End index of the **response text** (``TextContentBlock.text``)"""
181
+ """End index of the **response text** (`TextContentBlock.text`)"""
181
182
 
182
183
  cited_text: NotRequired[str]
183
184
  """Excerpt of source text being cited."""
@@ -202,8 +203,9 @@ class NonStandardAnnotation(TypedDict):
202
203
  """Content block identifier.
203
204
 
204
205
  Either:
206
+
205
207
  - Generated by the provider (e.g., OpenAI's file ID)
206
- - Generated by LangChain upon creation (``UUID4`` prefixed with ``'lc_'``))
208
+ - Generated by LangChain upon creation (`UUID4` prefixed with `'lc_'`))
207
209
 
208
210
  """
209
211
 
@@ -211,7 +213,8 @@ class NonStandardAnnotation(TypedDict):
211
213
  """Provider-specific annotation data."""
212
214
 
213
215
 
214
- Annotation = Union[Citation, NonStandardAnnotation]
216
+ Annotation = Citation | NonStandardAnnotation
217
+ """A union of all defined `Annotation` types."""
215
218
 
216
219
 
217
220
  class TextContentBlock(TypedDict):
@@ -220,9 +223,9 @@ class TextContentBlock(TypedDict):
220
223
  This typically represents the main text content of a message, such as the response
221
224
  from a language model or the text of a user message.
222
225
 
223
- .. note::
224
- ``create_text_block`` may also be used as a factory to create a
225
- ``TextContentBlock``. Benefits include:
226
+ !!! note "Factory function"
227
+ `create_text_block` may also be used as a factory to create a
228
+ `TextContentBlock`. Benefits include:
226
229
 
227
230
  * Automatic ID generation (when not provided)
228
231
  * Required arguments strictly validated at creation time
@@ -236,8 +239,9 @@ class TextContentBlock(TypedDict):
236
239
  """Content block identifier.
237
240
 
238
241
  Either:
242
+
239
243
  - Generated by the provider (e.g., OpenAI's file ID)
240
- - Generated by LangChain upon creation (``UUID4`` prefixed with ``'lc_'``))
244
+ - Generated by LangChain upon creation (`UUID4` prefixed with `'lc_'`))
241
245
 
242
246
  """
243
247
 
@@ -245,9 +249,9 @@ class TextContentBlock(TypedDict):
245
249
  """Block text."""
246
250
 
247
251
  annotations: NotRequired[list[Annotation]]
248
- """``Citation``s and other annotations."""
252
+ """`Citation`s and other annotations."""
249
253
 
250
- index: NotRequired[Union[int, str]]
254
+ index: NotRequired[int | str]
251
255
  """Index of block in aggregate response. Used during streaming."""
252
256
 
253
257
  extras: NotRequired[dict[str, Any]]
@@ -255,20 +259,19 @@ class TextContentBlock(TypedDict):
255
259
 
256
260
 
257
261
  class ToolCall(TypedDict):
258
- """Represents a request to call a tool.
262
+ """Represents an AI's request to call a tool.
259
263
 
260
264
  Example:
261
-
262
- .. code-block:: python
263
-
264
- {"name": "foo", "args": {"a": 1}, "id": "123"}
265
+ ```python
266
+ {"name": "foo", "args": {"a": 1}, "id": "123"}
267
+ ```
265
268
 
266
269
  This represents a request to call the tool named "foo" with arguments {"a": 1}
267
270
  and an identifier of "123".
268
271
 
269
- .. note::
270
- ``create_tool_call`` may also be used as a factory to create a
271
- ``ToolCall``. Benefits include:
272
+ !!! note "Factory function"
273
+ `create_tool_call` may also be used as a factory to create a
274
+ `ToolCall`. Benefits include:
272
275
 
273
276
  * Automatic ID generation (when not provided)
274
277
  * Required arguments strictly validated at creation time
@@ -278,7 +281,7 @@ class ToolCall(TypedDict):
278
281
  type: Literal["tool_call"]
279
282
  """Used for discrimination."""
280
283
 
281
- id: Optional[str]
284
+ id: str | None
282
285
  """An identifier associated with the tool call.
283
286
 
284
287
  An identifier is needed to associate a tool call request with a tool
@@ -293,7 +296,7 @@ class ToolCall(TypedDict):
293
296
  args: dict[str, Any]
294
297
  """The arguments to the tool call."""
295
298
 
296
- index: NotRequired[Union[int, str]]
299
+ index: NotRequired[int | str]
297
300
  """Index of block in aggregate response. Used during streaming."""
298
301
 
299
302
  extras: NotRequired[dict[str, Any]]
@@ -301,24 +304,22 @@ class ToolCall(TypedDict):
301
304
 
302
305
 
303
306
  class ToolCallChunk(TypedDict):
304
- """A chunk of a tool call (e.g., as part of a stream).
307
+ """A chunk of a tool call (yielded when streaming).
305
308
 
306
- When merging ``ToolCallChunks`` (e.g., via ``AIMessageChunk.__add__``),
309
+ When merging `ToolCallChunks` (e.g., via `AIMessageChunk.__add__`),
307
310
  all string attributes are concatenated. Chunks are only merged if their
308
- values of ``index`` are equal and not ``None``.
311
+ values of `index` are equal and not `None`.
309
312
 
310
313
  Example:
311
-
312
- .. code-block:: python
313
-
314
- left_chunks = [ToolCallChunk(name="foo", args='{"a":', index=0)]
315
- right_chunks = [ToolCallChunk(name=None, args="1}", index=0)]
316
-
317
- (
318
- AIMessageChunk(content="", tool_call_chunks=left_chunks)
319
- + AIMessageChunk(content="", tool_call_chunks=right_chunks)
320
- ).tool_call_chunks == [ToolCallChunk(name="foo", args='{"a":1}', index=0)]
321
-
314
+ ```python
315
+ left_chunks = [ToolCallChunk(name="foo", args='{"a":', index=0)]
316
+ right_chunks = [ToolCallChunk(name=None, args="1}", index=0)]
317
+
318
+ (
319
+ AIMessageChunk(content="", tool_call_chunks=left_chunks)
320
+ + AIMessageChunk(content="", tool_call_chunks=right_chunks)
321
+ ).tool_call_chunks == [ToolCallChunk(name="foo", args='{"a":1}', index=0)]
322
+ ```
322
323
  """
323
324
 
324
325
  # TODO: Consider making fields NotRequired[str] in the future.
@@ -326,7 +327,7 @@ class ToolCallChunk(TypedDict):
326
327
  type: Literal["tool_call_chunk"]
327
328
  """Used for serialization."""
328
329
 
329
- id: Optional[str]
330
+ id: str | None
330
331
  """An identifier associated with the tool call.
331
332
 
332
333
  An identifier is needed to associate a tool call request with a tool
@@ -334,13 +335,13 @@ class ToolCallChunk(TypedDict):
334
335
 
335
336
  """
336
337
 
337
- name: Optional[str]
338
+ name: str | None
338
339
  """The name of the tool to be called."""
339
340
 
340
- args: Optional[str]
341
+ args: str | None
341
342
  """The arguments to the tool call."""
342
343
 
343
- index: NotRequired[Union[int, str]]
344
+ index: NotRequired[int | str]
344
345
  """The index of the tool call in a sequence."""
345
346
 
346
347
  extras: NotRequired[dict[str, Any]]
@@ -350,7 +351,7 @@ class ToolCallChunk(TypedDict):
350
351
  class InvalidToolCall(TypedDict):
351
352
  """Allowance for errors made by LLM.
352
353
 
353
- Here we add an ``error`` key to surface errors made during generation
354
+ Here we add an `error` key to surface errors made during generation
354
355
  (e.g., invalid JSON arguments.)
355
356
 
356
357
  """
@@ -360,7 +361,7 @@ class InvalidToolCall(TypedDict):
360
361
  type: Literal["invalid_tool_call"]
361
362
  """Used for discrimination."""
362
363
 
363
- id: Optional[str]
364
+ id: str | None
364
365
  """An identifier associated with the tool call.
365
366
 
366
367
  An identifier is needed to associate a tool call request with a tool
@@ -368,16 +369,16 @@ class InvalidToolCall(TypedDict):
368
369
 
369
370
  """
370
371
 
371
- name: Optional[str]
372
+ name: str | None
372
373
  """The name of the tool to be called."""
373
374
 
374
- args: Optional[str]
375
+ args: str | None
375
376
  """The arguments to the tool call."""
376
377
 
377
- error: Optional[str]
378
+ error: str | None
378
379
  """An error message associated with the tool call."""
379
380
 
380
- index: NotRequired[Union[int, str]]
381
+ index: NotRequired[int | str]
381
382
  """Index of block in aggregate response. Used during streaming."""
382
383
 
383
384
  extras: NotRequired[dict[str, Any]]
@@ -385,7 +386,10 @@ class InvalidToolCall(TypedDict):
385
386
 
386
387
 
387
388
  class ServerToolCall(TypedDict):
388
- """Tool call that is executed server-side."""
389
+ """Tool call that is executed server-side.
390
+
391
+ For example: code execution, web search, etc.
392
+ """
389
393
 
390
394
  type: Literal["server_tool_call"]
391
395
  """Used for discrimination."""
@@ -399,7 +403,7 @@ class ServerToolCall(TypedDict):
399
403
  args: dict[str, Any]
400
404
  """The arguments to the tool call."""
401
405
 
402
- index: NotRequired[Union[int, str]]
406
+ index: NotRequired[int | str]
403
407
  """Index of block in aggregate response. Used during streaming."""
404
408
 
405
409
  extras: NotRequired[dict[str, Any]]
@@ -407,7 +411,7 @@ class ServerToolCall(TypedDict):
407
411
 
408
412
 
409
413
  class ServerToolCallChunk(TypedDict):
410
- """A chunk of a tool call (as part of a stream)."""
414
+ """A chunk of a server-side tool call (yielded when streaming)."""
411
415
 
412
416
  type: Literal["server_tool_call_chunk"]
413
417
  """Used for discrimination."""
@@ -421,7 +425,7 @@ class ServerToolCallChunk(TypedDict):
421
425
  id: NotRequired[str]
422
426
  """An identifier associated with the tool call."""
423
427
 
424
- index: NotRequired[Union[int, str]]
428
+ index: NotRequired[int | str]
425
429
  """Index of block in aggregate response. Used during streaming."""
426
430
 
427
431
  extras: NotRequired[dict[str, Any]]
@@ -446,7 +450,7 @@ class ServerToolResult(TypedDict):
446
450
  output: NotRequired[Any]
447
451
  """Output of the executed tool."""
448
452
 
449
- index: NotRequired[Union[int, str]]
453
+ index: NotRequired[int | str]
450
454
  """Index of block in aggregate response. Used during streaming."""
451
455
 
452
456
  extras: NotRequired[dict[str, Any]]
@@ -456,9 +460,9 @@ class ServerToolResult(TypedDict):
456
460
  class ReasoningContentBlock(TypedDict):
457
461
  """Reasoning output from a LLM.
458
462
 
459
- .. note::
460
- ``create_reasoning_block`` may also be used as a factory to create a
461
- ``ReasoningContentBlock``. Benefits include:
463
+ !!! note "Factory function"
464
+ `create_reasoning_block` may also be used as a factory to create a
465
+ `ReasoningContentBlock`. Benefits include:
462
466
 
463
467
  * Automatic ID generation (when not provided)
464
468
  * Required arguments strictly validated at creation time
@@ -472,8 +476,9 @@ class ReasoningContentBlock(TypedDict):
472
476
  """Content block identifier.
473
477
 
474
478
  Either:
479
+
475
480
  - Generated by the provider (e.g., OpenAI's file ID)
476
- - Generated by LangChain upon creation (``UUID4`` prefixed with ``'lc_'``))
481
+ - Generated by LangChain upon creation (`UUID4` prefixed with `'lc_'`))
477
482
 
478
483
  """
479
484
 
@@ -481,11 +486,11 @@ class ReasoningContentBlock(TypedDict):
481
486
  """Reasoning text.
482
487
 
483
488
  Either the thought summary or the raw reasoning text itself. This is often parsed
484
- from ``<think>`` tags in the model's response.
489
+ from `<think>` tags in the model's response.
485
490
 
486
491
  """
487
492
 
488
- index: NotRequired[Union[int, str]]
493
+ index: NotRequired[int | str]
489
494
  """Index of block in aggregate response. Used during streaming."""
490
495
 
491
496
  extras: NotRequired[dict[str, Any]]
@@ -498,9 +503,9 @@ class ReasoningContentBlock(TypedDict):
498
503
  class ImageContentBlock(TypedDict):
499
504
  """Image data.
500
505
 
501
- .. note::
502
- ``create_image_block`` may also be used as a factory to create a
503
- ``ImageContentBlock``. Benefits include:
506
+ !!! note "Factory function"
507
+ `create_image_block` may also be used as a factory to create a
508
+ `ImageContentBlock`. Benefits include:
504
509
 
505
510
  * Automatic ID generation (when not provided)
506
511
  * Required arguments strictly validated at creation time
@@ -514,8 +519,9 @@ class ImageContentBlock(TypedDict):
514
519
  """Content block identifier.
515
520
 
516
521
  Either:
522
+
517
523
  - Generated by the provider (e.g., OpenAI's file ID)
518
- - Generated by LangChain upon creation (``UUID4`` prefixed with ``'lc_'``))
524
+ - Generated by LangChain upon creation (`UUID4` prefixed with `'lc_'`))
519
525
 
520
526
  """
521
527
 
@@ -525,11 +531,11 @@ class ImageContentBlock(TypedDict):
525
531
  mime_type: NotRequired[str]
526
532
  """MIME type of the image. Required for base64.
527
533
 
528
- `Examples from IANA <https://www.iana.org/assignments/media-types/media-types.xhtml#image>`__
534
+ [Examples from IANA](https://www.iana.org/assignments/media-types/media-types.xhtml#image)
529
535
 
530
536
  """
531
537
 
532
- index: NotRequired[Union[int, str]]
538
+ index: NotRequired[int | str]
533
539
  """Index of block in aggregate response. Used during streaming."""
534
540
 
535
541
  url: NotRequired[str]
@@ -545,9 +551,9 @@ class ImageContentBlock(TypedDict):
545
551
  class VideoContentBlock(TypedDict):
546
552
  """Video data.
547
553
 
548
- .. note::
549
- ``create_video_block`` may also be used as a factory to create a
550
- ``VideoContentBlock``. Benefits include:
554
+ !!! note "Factory function"
555
+ `create_video_block` may also be used as a factory to create a
556
+ `VideoContentBlock`. Benefits include:
551
557
 
552
558
  * Automatic ID generation (when not provided)
553
559
  * Required arguments strictly validated at creation time
@@ -561,8 +567,9 @@ class VideoContentBlock(TypedDict):
561
567
  """Content block identifier.
562
568
 
563
569
  Either:
570
+
564
571
  - Generated by the provider (e.g., OpenAI's file ID)
565
- - Generated by LangChain upon creation (``UUID4`` prefixed with ``'lc_'``))
572
+ - Generated by LangChain upon creation (`UUID4` prefixed with `'lc_'`))
566
573
 
567
574
  """
568
575
 
@@ -572,11 +579,11 @@ class VideoContentBlock(TypedDict):
572
579
  mime_type: NotRequired[str]
573
580
  """MIME type of the video. Required for base64.
574
581
 
575
- `Examples from IANA <https://www.iana.org/assignments/media-types/media-types.xhtml#video>`__
582
+ [Examples from IANA](https://www.iana.org/assignments/media-types/media-types.xhtml#video)
576
583
 
577
584
  """
578
585
 
579
- index: NotRequired[Union[int, str]]
586
+ index: NotRequired[int | str]
580
587
  """Index of block in aggregate response. Used during streaming."""
581
588
 
582
589
  url: NotRequired[str]
@@ -592,9 +599,9 @@ class VideoContentBlock(TypedDict):
592
599
  class AudioContentBlock(TypedDict):
593
600
  """Audio data.
594
601
 
595
- .. note::
596
- ``create_audio_block`` may also be used as a factory to create an
597
- ``AudioContentBlock``. Benefits include:
602
+ !!! note "Factory function"
603
+ `create_audio_block` may also be used as a factory to create an
604
+ `AudioContentBlock`. Benefits include:
598
605
  * Automatic ID generation (when not provided)
599
606
  * Required arguments strictly validated at creation time
600
607
 
@@ -607,8 +614,9 @@ class AudioContentBlock(TypedDict):
607
614
  """Content block identifier.
608
615
 
609
616
  Either:
617
+
610
618
  - Generated by the provider (e.g., OpenAI's file ID)
611
- - Generated by LangChain upon creation (``UUID4`` prefixed with ``'lc_'``))
619
+ - Generated by LangChain upon creation (`UUID4` prefixed with `'lc_'`))
612
620
 
613
621
  """
614
622
 
@@ -618,11 +626,11 @@ class AudioContentBlock(TypedDict):
618
626
  mime_type: NotRequired[str]
619
627
  """MIME type of the audio. Required for base64.
620
628
 
621
- `Examples from IANA <https://www.iana.org/assignments/media-types/media-types.xhtml#audio>`__
629
+ [Examples from IANA](https://www.iana.org/assignments/media-types/media-types.xhtml#audio)
622
630
 
623
631
  """
624
632
 
625
- index: NotRequired[Union[int, str]]
633
+ index: NotRequired[int | str]
626
634
  """Index of block in aggregate response. Used during streaming."""
627
635
 
628
636
  url: NotRequired[str]
@@ -636,21 +644,21 @@ class AudioContentBlock(TypedDict):
636
644
 
637
645
 
638
646
  class PlainTextContentBlock(TypedDict):
639
- """Plaintext data (e.g., from a document).
647
+ """Plaintext data (e.g., from a `.txt` or `.md` document).
640
648
 
641
- .. note::
642
- A ``PlainTextContentBlock`` existed in ``langchain-core<1.0.0``. Although the
649
+ !!! note
650
+ A `PlainTextContentBlock` existed in `langchain-core<1.0.0`. Although the
643
651
  name has carried over, the structure has changed significantly. The only shared
644
- keys between the old and new versions are ``type`` and ``text``, though the
645
- ``type`` value has changed from ``'text'`` to ``'text-plain'``.
652
+ keys between the old and new versions are `type` and `text`, though the
653
+ `type` value has changed from `'text'` to `'text-plain'`.
646
654
 
647
- .. note::
655
+ !!! note
648
656
  Title and context are optional fields that may be passed to the model. See
649
- Anthropic `example <https://docs.anthropic.com/en/docs/build-with-claude/citations#citable-vs-non-citable-content>`__.
657
+ Anthropic [example](https://docs.claude.com/en/docs/build-with-claude/citations#citable-vs-non-citable-content).
650
658
 
651
- .. note::
652
- ``create_plaintext_block`` may also be used as a factory to create a
653
- ``PlainTextContentBlock``. Benefits include:
659
+ !!! note "Factory function"
660
+ `create_plaintext_block` may also be used as a factory to create a
661
+ `PlainTextContentBlock`. Benefits include:
654
662
 
655
663
  * Automatic ID generation (when not provided)
656
664
  * Required arguments strictly validated at creation time
@@ -664,8 +672,9 @@ class PlainTextContentBlock(TypedDict):
664
672
  """Content block identifier.
665
673
 
666
674
  Either:
675
+
667
676
  - Generated by the provider (e.g., OpenAI's file ID)
668
- - Generated by LangChain upon creation (``UUID4`` prefixed with ``'lc_'``))
677
+ - Generated by LangChain upon creation (`UUID4` prefixed with `'lc_'`))
669
678
 
670
679
  """
671
680
 
@@ -675,7 +684,7 @@ class PlainTextContentBlock(TypedDict):
675
684
  mime_type: Literal["text/plain"]
676
685
  """MIME type of the file. Required for base64."""
677
686
 
678
- index: NotRequired[Union[int, str]]
687
+ index: NotRequired[int | str]
679
688
  """Index of block in aggregate response. Used during streaming."""
680
689
 
681
690
  url: NotRequired[str]
@@ -698,18 +707,18 @@ class PlainTextContentBlock(TypedDict):
698
707
 
699
708
 
700
709
  class FileContentBlock(TypedDict):
701
- """File data that doesn't fit into other multimodal blocks.
710
+ """File data that doesn't fit into other multimodal block types.
702
711
 
703
712
  This block is intended for files that are not images, audio, or plaintext. For
704
713
  example, it can be used for PDFs, Word documents, etc.
705
714
 
706
715
  If the file is an image, audio, or plaintext, you should use the corresponding
707
- content block type (e.g., ``ImageContentBlock``, ``AudioContentBlock``,
708
- ``PlainTextContentBlock``).
716
+ content block type (e.g., `ImageContentBlock`, `AudioContentBlock`,
717
+ `PlainTextContentBlock`).
709
718
 
710
- .. note::
711
- ``create_file_block`` may also be used as a factory to create a
712
- ``FileContentBlock``. Benefits include:
719
+ !!! note "Factory function"
720
+ `create_file_block` may also be used as a factory to create a
721
+ `FileContentBlock`. Benefits include:
713
722
 
714
723
  * Automatic ID generation (when not provided)
715
724
  * Required arguments strictly validated at creation time
@@ -723,8 +732,9 @@ class FileContentBlock(TypedDict):
723
732
  """Content block identifier.
724
733
 
725
734
  Either:
735
+
726
736
  - Generated by the provider (e.g., OpenAI's file ID)
727
- - Generated by LangChain upon creation (``UUID4`` prefixed with ``'lc_'``))
737
+ - Generated by LangChain upon creation (`UUID4` prefixed with `'lc_'`))
728
738
 
729
739
  """
730
740
 
@@ -734,11 +744,11 @@ class FileContentBlock(TypedDict):
734
744
  mime_type: NotRequired[str]
735
745
  """MIME type of the file. Required for base64.
736
746
 
737
- `Examples from IANA <https://www.iana.org/assignments/media-types/media-types.xhtml>`__
747
+ [Examples from IANA](https://www.iana.org/assignments/media-types/media-types.xhtml)
738
748
 
739
749
  """
740
750
 
741
- index: NotRequired[Union[int, str]]
751
+ index: NotRequired[int | str]
742
752
  """Index of block in aggregate response. Used during streaming."""
743
753
 
744
754
  url: NotRequired[str]
@@ -757,21 +767,21 @@ class FileContentBlock(TypedDict):
757
767
 
758
768
 
759
769
  class NonStandardContentBlock(TypedDict):
760
- """Provider-specific data.
770
+ """Provider-specific content data.
761
771
 
762
772
  This block contains data for which there is not yet a standard type.
763
773
 
764
774
  The purpose of this block should be to simply hold a provider-specific payload.
765
775
  If a provider's non-standard output includes reasoning and tool calls, it should be
766
776
  the adapter's job to parse that payload and emit the corresponding standard
767
- ``ReasoningContentBlock`` and ``ToolCalls``.
777
+ `ReasoningContentBlock` and `ToolCalls`.
768
778
 
769
- Has no ``extras`` field, as provider-specific data should be included in the
770
- ``value`` field.
779
+ Has no `extras` field, as provider-specific data should be included in the
780
+ `value` field.
771
781
 
772
- .. note::
773
- ``create_non_standard_block`` may also be used as a factory to create a
774
- ``NonStandardContentBlock``. Benefits include:
782
+ !!! note "Factory function"
783
+ `create_non_standard_block` may also be used as a factory to create a
784
+ `NonStandardContentBlock`. Benefits include:
775
785
 
776
786
  * Automatic ID generation (when not provided)
777
787
  * Required arguments strictly validated at creation time
@@ -785,43 +795,42 @@ class NonStandardContentBlock(TypedDict):
785
795
  """Content block identifier.
786
796
 
787
797
  Either:
798
+
788
799
  - Generated by the provider (e.g., OpenAI's file ID)
789
- - Generated by LangChain upon creation (``UUID4`` prefixed with ``'lc_'``))
800
+ - Generated by LangChain upon creation (`UUID4` prefixed with `'lc_'`))
790
801
 
791
802
  """
792
803
 
793
804
  value: dict[str, Any]
794
- """Provider-specific data."""
805
+ """Provider-specific content data."""
795
806
 
796
- index: NotRequired[Union[int, str]]
807
+ index: NotRequired[int | str]
797
808
  """Index of block in aggregate response. Used during streaming."""
798
809
 
799
810
 
800
811
  # --- Aliases ---
801
- DataContentBlock = Union[
802
- ImageContentBlock,
803
- VideoContentBlock,
804
- AudioContentBlock,
805
- PlainTextContentBlock,
806
- FileContentBlock,
807
- ]
808
-
809
- ToolContentBlock = Union[
810
- ToolCall,
811
- ToolCallChunk,
812
- ServerToolCall,
813
- ServerToolCallChunk,
814
- ServerToolResult,
815
- ]
816
-
817
- ContentBlock = Union[
818
- TextContentBlock,
819
- InvalidToolCall,
820
- ReasoningContentBlock,
821
- NonStandardContentBlock,
822
- DataContentBlock,
823
- ToolContentBlock,
824
- ]
812
+ DataContentBlock = (
813
+ ImageContentBlock
814
+ | VideoContentBlock
815
+ | AudioContentBlock
816
+ | PlainTextContentBlock
817
+ | FileContentBlock
818
+ )
819
+ """A union of all defined multimodal data `ContentBlock` types."""
820
+
821
+ ToolContentBlock = (
822
+ ToolCall | ToolCallChunk | ServerToolCall | ServerToolCallChunk | ServerToolResult
823
+ )
824
+
825
+ ContentBlock = (
826
+ TextContentBlock
827
+ | InvalidToolCall
828
+ | ReasoningContentBlock
829
+ | NonStandardContentBlock
830
+ | DataContentBlock
831
+ | ToolContentBlock
832
+ )
833
+ """A union of all defined `ContentBlock` types and aliases."""
825
834
 
826
835
 
827
836
  KNOWN_BLOCK_TYPES = {
@@ -846,7 +855,7 @@ KNOWN_BLOCK_TYPES = {
846
855
  "non_standard",
847
856
  # citation and non_standard_annotation intentionally omitted
848
857
  }
849
- """These are block types known to ``langchain-core>=1.0.0``.
858
+ """These are block types known to `langchain-core>=1.0.0`.
850
859
 
851
860
  If a block has a type not in this set, it is considered to be provider-specific.
852
861
  """
@@ -879,13 +888,13 @@ def _get_data_content_block_types() -> tuple[str, ...]:
879
888
  def is_data_content_block(block: dict) -> bool:
880
889
  """Check if the provided content block is a data content block.
881
890
 
882
- Returns for both v0 (old-style) and v1 (new-style) multimodal data blocks.
891
+ Returns True for both v0 (old-style) and v1 (new-style) multimodal data blocks.
883
892
 
884
893
  Args:
885
894
  block: The content block to check.
886
895
 
887
896
  Returns:
888
- True if the content block is a data content block, False otherwise.
897
+ `True` if the content block is a data content block, `False` otherwise.
889
898
 
890
899
  """
891
900
  if block.get("type") not in _get_data_content_block_types():
@@ -922,25 +931,25 @@ def is_data_content_block(block: dict) -> bool:
922
931
  def create_text_block(
923
932
  text: str,
924
933
  *,
925
- id: Optional[str] = None,
926
- annotations: Optional[list[Annotation]] = None,
927
- index: Optional[Union[int, str]] = None,
934
+ id: str | None = None,
935
+ annotations: list[Annotation] | None = None,
936
+ index: int | str | None = None,
928
937
  **kwargs: Any,
929
938
  ) -> TextContentBlock:
930
- """Create a ``TextContentBlock``.
939
+ """Create a `TextContentBlock`.
931
940
 
932
941
  Args:
933
942
  text: The text content of the block.
934
943
  id: Content block identifier. Generated automatically if not provided.
935
- annotations: ``Citation``s and other annotations for the text.
944
+ annotations: `Citation`s and other annotations for the text.
936
945
  index: Index of block in aggregate response. Used during streaming.
937
946
 
938
947
  Returns:
939
- A properly formatted ``TextContentBlock``.
948
+ A properly formatted `TextContentBlock`.
940
949
 
941
- .. note::
942
- The ``id`` is generated automatically if not provided, using a UUID4 format
943
- prefixed with ``'lc_'`` to indicate it is a LangChain-generated ID.
950
+ !!! note
951
+ The `id` is generated automatically if not provided, using a UUID4 format
952
+ prefixed with `'lc_'` to indicate it is a LangChain-generated ID.
944
953
 
945
954
  """
946
955
  block = TextContentBlock(
@@ -962,15 +971,15 @@ def create_text_block(
962
971
 
963
972
  def create_image_block(
964
973
  *,
965
- url: Optional[str] = None,
966
- base64: Optional[str] = None,
967
- file_id: Optional[str] = None,
968
- mime_type: Optional[str] = None,
969
- id: Optional[str] = None,
970
- index: Optional[Union[int, str]] = None,
974
+ url: str | None = None,
975
+ base64: str | None = None,
976
+ file_id: str | None = None,
977
+ mime_type: str | None = None,
978
+ id: str | None = None,
979
+ index: int | str | None = None,
971
980
  **kwargs: Any,
972
981
  ) -> ImageContentBlock:
973
- """Create an ``ImageContentBlock``.
982
+ """Create an `ImageContentBlock`.
974
983
 
975
984
  Args:
976
985
  url: URL of the image.
@@ -981,15 +990,15 @@ def create_image_block(
981
990
  index: Index of block in aggregate response. Used during streaming.
982
991
 
983
992
  Returns:
984
- A properly formatted ``ImageContentBlock``.
993
+ A properly formatted `ImageContentBlock`.
985
994
 
986
995
  Raises:
987
- ValueError: If no image source is provided or if ``base64`` is used without
988
- ``mime_type``.
996
+ ValueError: If no image source is provided or if `base64` is used without
997
+ `mime_type`.
989
998
 
990
- .. note::
991
- The ``id`` is generated automatically if not provided, using a UUID4 format
992
- prefixed with ``'lc_'`` to indicate it is a LangChain-generated ID.
999
+ !!! note
1000
+ The `id` is generated automatically if not provided, using a UUID4 format
1001
+ prefixed with `'lc_'` to indicate it is a LangChain-generated ID.
993
1002
 
994
1003
  """
995
1004
  if not any([url, base64, file_id]):
@@ -1018,15 +1027,15 @@ def create_image_block(
1018
1027
 
1019
1028
  def create_video_block(
1020
1029
  *,
1021
- url: Optional[str] = None,
1022
- base64: Optional[str] = None,
1023
- file_id: Optional[str] = None,
1024
- mime_type: Optional[str] = None,
1025
- id: Optional[str] = None,
1026
- index: Optional[Union[int, str]] = None,
1030
+ url: str | None = None,
1031
+ base64: str | None = None,
1032
+ file_id: str | None = None,
1033
+ mime_type: str | None = None,
1034
+ id: str | None = None,
1035
+ index: int | str | None = None,
1027
1036
  **kwargs: Any,
1028
1037
  ) -> VideoContentBlock:
1029
- """Create a ``VideoContentBlock``.
1038
+ """Create a `VideoContentBlock`.
1030
1039
 
1031
1040
  Args:
1032
1041
  url: URL of the video.
@@ -1037,15 +1046,15 @@ def create_video_block(
1037
1046
  index: Index of block in aggregate response. Used during streaming.
1038
1047
 
1039
1048
  Returns:
1040
- A properly formatted ``VideoContentBlock``.
1049
+ A properly formatted `VideoContentBlock`.
1041
1050
 
1042
1051
  Raises:
1043
- ValueError: If no video source is provided or if ``base64`` is used without
1044
- ``mime_type``.
1052
+ ValueError: If no video source is provided or if `base64` is used without
1053
+ `mime_type`.
1045
1054
 
1046
- .. note::
1047
- The ``id`` is generated automatically if not provided, using a UUID4 format
1048
- prefixed with ``'lc_'`` to indicate it is a LangChain-generated ID.
1055
+ !!! note
1056
+ The `id` is generated automatically if not provided, using a UUID4 format
1057
+ prefixed with `'lc_'` to indicate it is a LangChain-generated ID.
1049
1058
 
1050
1059
  """
1051
1060
  if not any([url, base64, file_id]):
@@ -1078,15 +1087,15 @@ def create_video_block(
1078
1087
 
1079
1088
  def create_audio_block(
1080
1089
  *,
1081
- url: Optional[str] = None,
1082
- base64: Optional[str] = None,
1083
- file_id: Optional[str] = None,
1084
- mime_type: Optional[str] = None,
1085
- id: Optional[str] = None,
1086
- index: Optional[Union[int, str]] = None,
1090
+ url: str | None = None,
1091
+ base64: str | None = None,
1092
+ file_id: str | None = None,
1093
+ mime_type: str | None = None,
1094
+ id: str | None = None,
1095
+ index: int | str | None = None,
1087
1096
  **kwargs: Any,
1088
1097
  ) -> AudioContentBlock:
1089
- """Create an ``AudioContentBlock``.
1098
+ """Create an `AudioContentBlock`.
1090
1099
 
1091
1100
  Args:
1092
1101
  url: URL of the audio.
@@ -1097,15 +1106,15 @@ def create_audio_block(
1097
1106
  index: Index of block in aggregate response. Used during streaming.
1098
1107
 
1099
1108
  Returns:
1100
- A properly formatted ``AudioContentBlock``.
1109
+ A properly formatted `AudioContentBlock`.
1101
1110
 
1102
1111
  Raises:
1103
- ValueError: If no audio source is provided or if ``base64`` is used without
1104
- ``mime_type``.
1112
+ ValueError: If no audio source is provided or if `base64` is used without
1113
+ `mime_type`.
1105
1114
 
1106
- .. note::
1107
- The ``id`` is generated automatically if not provided, using a UUID4 format
1108
- prefixed with ``'lc_'`` to indicate it is a LangChain-generated ID.
1115
+ !!! note
1116
+ The `id` is generated automatically if not provided, using a UUID4 format
1117
+ prefixed with `'lc_'` to indicate it is a LangChain-generated ID.
1109
1118
 
1110
1119
  """
1111
1120
  if not any([url, base64, file_id]):
@@ -1138,15 +1147,15 @@ def create_audio_block(
1138
1147
 
1139
1148
  def create_file_block(
1140
1149
  *,
1141
- url: Optional[str] = None,
1142
- base64: Optional[str] = None,
1143
- file_id: Optional[str] = None,
1144
- mime_type: Optional[str] = None,
1145
- id: Optional[str] = None,
1146
- index: Optional[Union[int, str]] = None,
1150
+ url: str | None = None,
1151
+ base64: str | None = None,
1152
+ file_id: str | None = None,
1153
+ mime_type: str | None = None,
1154
+ id: str | None = None,
1155
+ index: int | str | None = None,
1147
1156
  **kwargs: Any,
1148
1157
  ) -> FileContentBlock:
1149
- """Create a ``FileContentBlock``.
1158
+ """Create a `FileContentBlock`.
1150
1159
 
1151
1160
  Args:
1152
1161
  url: URL of the file.
@@ -1157,15 +1166,15 @@ def create_file_block(
1157
1166
  index: Index of block in aggregate response. Used during streaming.
1158
1167
 
1159
1168
  Returns:
1160
- A properly formatted ``FileContentBlock``.
1169
+ A properly formatted `FileContentBlock`.
1161
1170
 
1162
1171
  Raises:
1163
- ValueError: If no file source is provided or if ``base64`` is used without
1164
- ``mime_type``.
1172
+ ValueError: If no file source is provided or if `base64` is used without
1173
+ `mime_type`.
1165
1174
 
1166
- .. note::
1167
- The ``id`` is generated automatically if not provided, using a UUID4 format
1168
- prefixed with ``'lc_'`` to indicate it is a LangChain-generated ID.
1175
+ !!! note
1176
+ The `id` is generated automatically if not provided, using a UUID4 format
1177
+ prefixed with `'lc_'` to indicate it is a LangChain-generated ID.
1169
1178
 
1170
1179
  """
1171
1180
  if not any([url, base64, file_id]):
@@ -1197,17 +1206,17 @@ def create_file_block(
1197
1206
 
1198
1207
 
1199
1208
  def create_plaintext_block(
1200
- text: Optional[str] = None,
1201
- url: Optional[str] = None,
1202
- base64: Optional[str] = None,
1203
- file_id: Optional[str] = None,
1204
- title: Optional[str] = None,
1205
- context: Optional[str] = None,
1206
- id: Optional[str] = None,
1207
- index: Optional[Union[int, str]] = None,
1209
+ text: str | None = None,
1210
+ url: str | None = None,
1211
+ base64: str | None = None,
1212
+ file_id: str | None = None,
1213
+ title: str | None = None,
1214
+ context: str | None = None,
1215
+ id: str | None = None,
1216
+ index: int | str | None = None,
1208
1217
  **kwargs: Any,
1209
1218
  ) -> PlainTextContentBlock:
1210
- """Create a ``PlainTextContentBlock``.
1219
+ """Create a `PlainTextContentBlock`.
1211
1220
 
1212
1221
  Args:
1213
1222
  text: The plaintext content.
@@ -1220,11 +1229,11 @@ def create_plaintext_block(
1220
1229
  index: Index of block in aggregate response. Used during streaming.
1221
1230
 
1222
1231
  Returns:
1223
- A properly formatted ``PlainTextContentBlock``.
1232
+ A properly formatted `PlainTextContentBlock`.
1224
1233
 
1225
- .. note::
1226
- The ``id`` is generated automatically if not provided, using a UUID4 format
1227
- prefixed with ``'lc_'`` to indicate it is a LangChain-generated ID.
1234
+ !!! note
1235
+ The `id` is generated automatically if not provided, using a UUID4 format
1236
+ prefixed with `'lc_'` to indicate it is a LangChain-generated ID.
1228
1237
 
1229
1238
  """
1230
1239
  block = PlainTextContentBlock(
@@ -1259,11 +1268,11 @@ def create_tool_call(
1259
1268
  name: str,
1260
1269
  args: dict[str, Any],
1261
1270
  *,
1262
- id: Optional[str] = None,
1263
- index: Optional[Union[int, str]] = None,
1271
+ id: str | None = None,
1272
+ index: int | str | None = None,
1264
1273
  **kwargs: Any,
1265
1274
  ) -> ToolCall:
1266
- """Create a ``ToolCall``.
1275
+ """Create a `ToolCall`.
1267
1276
 
1268
1277
  Args:
1269
1278
  name: The name of the tool to be called.
@@ -1272,11 +1281,11 @@ def create_tool_call(
1272
1281
  index: Index of block in aggregate response. Used during streaming.
1273
1282
 
1274
1283
  Returns:
1275
- A properly formatted ``ToolCall``.
1284
+ A properly formatted `ToolCall`.
1276
1285
 
1277
- .. note::
1278
- The ``id`` is generated automatically if not provided, using a UUID4 format
1279
- prefixed with ``'lc_'`` to indicate it is a LangChain-generated ID.
1286
+ !!! note
1287
+ The `id` is generated automatically if not provided, using a UUID4 format
1288
+ prefixed with `'lc_'` to indicate it is a LangChain-generated ID.
1280
1289
 
1281
1290
  """
1282
1291
  block = ToolCall(
@@ -1297,12 +1306,12 @@ def create_tool_call(
1297
1306
 
1298
1307
 
1299
1308
  def create_reasoning_block(
1300
- reasoning: Optional[str] = None,
1301
- id: Optional[str] = None,
1302
- index: Optional[Union[int, str]] = None,
1309
+ reasoning: str | None = None,
1310
+ id: str | None = None,
1311
+ index: int | str | None = None,
1303
1312
  **kwargs: Any,
1304
1313
  ) -> ReasoningContentBlock:
1305
- """Create a ``ReasoningContentBlock``.
1314
+ """Create a `ReasoningContentBlock`.
1306
1315
 
1307
1316
  Args:
1308
1317
  reasoning: The reasoning text or thought summary.
@@ -1310,11 +1319,11 @@ def create_reasoning_block(
1310
1319
  index: Index of block in aggregate response. Used during streaming.
1311
1320
 
1312
1321
  Returns:
1313
- A properly formatted ``ReasoningContentBlock``.
1322
+ A properly formatted `ReasoningContentBlock`.
1314
1323
 
1315
- .. note::
1316
- The ``id`` is generated automatically if not provided, using a UUID4 format
1317
- prefixed with ``'lc_'`` to indicate it is a LangChain-generated ID.
1324
+ !!! note
1325
+ The `id` is generated automatically if not provided, using a UUID4 format
1326
+ prefixed with `'lc_'` to indicate it is a LangChain-generated ID.
1318
1327
 
1319
1328
  """
1320
1329
  block = ReasoningContentBlock(
@@ -1335,15 +1344,15 @@ def create_reasoning_block(
1335
1344
 
1336
1345
  def create_citation(
1337
1346
  *,
1338
- url: Optional[str] = None,
1339
- title: Optional[str] = None,
1340
- start_index: Optional[int] = None,
1341
- end_index: Optional[int] = None,
1342
- cited_text: Optional[str] = None,
1343
- id: Optional[str] = None,
1347
+ url: str | None = None,
1348
+ title: str | None = None,
1349
+ start_index: int | None = None,
1350
+ end_index: int | None = None,
1351
+ cited_text: str | None = None,
1352
+ id: str | None = None,
1344
1353
  **kwargs: Any,
1345
1354
  ) -> Citation:
1346
- """Create a ``Citation``.
1355
+ """Create a `Citation`.
1347
1356
 
1348
1357
  Args:
1349
1358
  url: URL of the document source.
@@ -1354,11 +1363,11 @@ def create_citation(
1354
1363
  id: Content block identifier. Generated automatically if not provided.
1355
1364
 
1356
1365
  Returns:
1357
- A properly formatted ``Citation``.
1366
+ A properly formatted `Citation`.
1358
1367
 
1359
- .. note::
1360
- The ``id`` is generated automatically if not provided, using a UUID4 format
1361
- prefixed with ``'lc_'`` to indicate it is a LangChain-generated ID.
1368
+ !!! note
1369
+ The `id` is generated automatically if not provided, using a UUID4 format
1370
+ prefixed with `'lc_'` to indicate it is a LangChain-generated ID.
1362
1371
 
1363
1372
  """
1364
1373
  block = Citation(type="citation", id=ensure_id(id))
@@ -1384,22 +1393,22 @@ def create_citation(
1384
1393
  def create_non_standard_block(
1385
1394
  value: dict[str, Any],
1386
1395
  *,
1387
- id: Optional[str] = None,
1388
- index: Optional[Union[int, str]] = None,
1396
+ id: str | None = None,
1397
+ index: int | str | None = None,
1389
1398
  ) -> NonStandardContentBlock:
1390
- """Create a ``NonStandardContentBlock``.
1399
+ """Create a `NonStandardContentBlock`.
1391
1400
 
1392
1401
  Args:
1393
- value: Provider-specific data.
1402
+ value: Provider-specific content data.
1394
1403
  id: Content block identifier. Generated automatically if not provided.
1395
1404
  index: Index of block in aggregate response. Used during streaming.
1396
1405
 
1397
1406
  Returns:
1398
- A properly formatted ``NonStandardContentBlock``.
1407
+ A properly formatted `NonStandardContentBlock`.
1399
1408
 
1400
- .. note::
1401
- The ``id`` is generated automatically if not provided, using a UUID4 format
1402
- prefixed with ``'lc_'`` to indicate it is a LangChain-generated ID.
1409
+ !!! note
1410
+ The `id` is generated automatically if not provided, using a UUID4 format
1411
+ prefixed with `'lc_'` to indicate it is a LangChain-generated ID.
1403
1412
 
1404
1413
  """
1405
1414
  block = NonStandardContentBlock(