langchain-core 1.0.0a6__py3-none-any.whl → 1.0.0a7__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.

Potentially problematic release.


This version of langchain-core might be problematic. Click here for more details.

Files changed (131) hide show
  1. langchain_core/_api/__init__.py +3 -3
  2. langchain_core/_api/beta_decorator.py +6 -6
  3. langchain_core/_api/deprecation.py +21 -29
  4. langchain_core/_api/path.py +3 -6
  5. langchain_core/_import_utils.py +2 -3
  6. langchain_core/agents.py +10 -11
  7. langchain_core/caches.py +7 -7
  8. langchain_core/callbacks/base.py +91 -91
  9. langchain_core/callbacks/file.py +11 -11
  10. langchain_core/callbacks/manager.py +86 -89
  11. langchain_core/callbacks/stdout.py +8 -8
  12. langchain_core/callbacks/usage.py +4 -4
  13. langchain_core/chat_history.py +1 -37
  14. langchain_core/document_loaders/base.py +2 -2
  15. langchain_core/document_loaders/langsmith.py +15 -15
  16. langchain_core/documents/base.py +16 -16
  17. langchain_core/documents/compressor.py +4 -4
  18. langchain_core/example_selectors/length_based.py +1 -1
  19. langchain_core/example_selectors/semantic_similarity.py +17 -19
  20. langchain_core/exceptions.py +3 -3
  21. langchain_core/globals.py +3 -151
  22. langchain_core/indexing/api.py +44 -43
  23. langchain_core/indexing/base.py +30 -30
  24. langchain_core/indexing/in_memory.py +3 -3
  25. langchain_core/language_models/_utils.py +5 -7
  26. langchain_core/language_models/base.py +18 -132
  27. langchain_core/language_models/chat_models.py +118 -227
  28. langchain_core/language_models/fake.py +11 -11
  29. langchain_core/language_models/fake_chat_models.py +35 -29
  30. langchain_core/language_models/llms.py +91 -201
  31. langchain_core/load/dump.py +1 -1
  32. langchain_core/load/load.py +11 -12
  33. langchain_core/load/mapping.py +2 -4
  34. langchain_core/load/serializable.py +2 -4
  35. langchain_core/messages/ai.py +17 -20
  36. langchain_core/messages/base.py +23 -25
  37. langchain_core/messages/block_translators/__init__.py +2 -5
  38. langchain_core/messages/block_translators/anthropic.py +3 -3
  39. langchain_core/messages/block_translators/bedrock_converse.py +2 -2
  40. langchain_core/messages/block_translators/langchain_v0.py +2 -2
  41. langchain_core/messages/block_translators/openai.py +6 -6
  42. langchain_core/messages/content.py +120 -124
  43. langchain_core/messages/human.py +7 -7
  44. langchain_core/messages/system.py +7 -7
  45. langchain_core/messages/tool.py +24 -24
  46. langchain_core/messages/utils.py +67 -79
  47. langchain_core/output_parsers/base.py +12 -14
  48. langchain_core/output_parsers/json.py +4 -4
  49. langchain_core/output_parsers/list.py +3 -5
  50. langchain_core/output_parsers/openai_functions.py +3 -3
  51. langchain_core/output_parsers/openai_tools.py +3 -3
  52. langchain_core/output_parsers/pydantic.py +2 -2
  53. langchain_core/output_parsers/transform.py +13 -15
  54. langchain_core/output_parsers/xml.py +7 -9
  55. langchain_core/outputs/chat_generation.py +4 -4
  56. langchain_core/outputs/chat_result.py +1 -3
  57. langchain_core/outputs/generation.py +2 -2
  58. langchain_core/outputs/llm_result.py +5 -5
  59. langchain_core/prompts/__init__.py +1 -5
  60. langchain_core/prompts/base.py +10 -15
  61. langchain_core/prompts/chat.py +31 -82
  62. langchain_core/prompts/dict.py +2 -2
  63. langchain_core/prompts/few_shot.py +5 -5
  64. langchain_core/prompts/few_shot_with_templates.py +4 -4
  65. langchain_core/prompts/loading.py +3 -5
  66. langchain_core/prompts/prompt.py +4 -16
  67. langchain_core/prompts/string.py +2 -1
  68. langchain_core/prompts/structured.py +16 -23
  69. langchain_core/rate_limiters.py +3 -4
  70. langchain_core/retrievers.py +14 -14
  71. langchain_core/runnables/base.py +928 -1042
  72. langchain_core/runnables/branch.py +36 -40
  73. langchain_core/runnables/config.py +27 -35
  74. langchain_core/runnables/configurable.py +108 -124
  75. langchain_core/runnables/fallbacks.py +76 -72
  76. langchain_core/runnables/graph.py +39 -45
  77. langchain_core/runnables/graph_ascii.py +9 -11
  78. langchain_core/runnables/graph_mermaid.py +18 -19
  79. langchain_core/runnables/graph_png.py +8 -9
  80. langchain_core/runnables/history.py +114 -127
  81. langchain_core/runnables/passthrough.py +113 -139
  82. langchain_core/runnables/retry.py +43 -48
  83. langchain_core/runnables/router.py +23 -28
  84. langchain_core/runnables/schema.py +42 -44
  85. langchain_core/runnables/utils.py +28 -31
  86. langchain_core/stores.py +9 -13
  87. langchain_core/structured_query.py +8 -8
  88. langchain_core/tools/base.py +62 -115
  89. langchain_core/tools/convert.py +31 -35
  90. langchain_core/tools/render.py +1 -1
  91. langchain_core/tools/retriever.py +4 -4
  92. langchain_core/tools/simple.py +13 -17
  93. langchain_core/tools/structured.py +12 -15
  94. langchain_core/tracers/base.py +62 -64
  95. langchain_core/tracers/context.py +17 -35
  96. langchain_core/tracers/core.py +49 -53
  97. langchain_core/tracers/evaluation.py +11 -11
  98. langchain_core/tracers/event_stream.py +58 -60
  99. langchain_core/tracers/langchain.py +13 -13
  100. langchain_core/tracers/log_stream.py +22 -24
  101. langchain_core/tracers/root_listeners.py +14 -14
  102. langchain_core/tracers/run_collector.py +2 -4
  103. langchain_core/tracers/schemas.py +8 -8
  104. langchain_core/tracers/stdout.py +2 -1
  105. langchain_core/utils/__init__.py +0 -3
  106. langchain_core/utils/_merge.py +2 -2
  107. langchain_core/utils/aiter.py +24 -28
  108. langchain_core/utils/env.py +4 -4
  109. langchain_core/utils/function_calling.py +31 -41
  110. langchain_core/utils/html.py +3 -4
  111. langchain_core/utils/input.py +3 -3
  112. langchain_core/utils/iter.py +15 -19
  113. langchain_core/utils/json.py +3 -2
  114. langchain_core/utils/json_schema.py +6 -6
  115. langchain_core/utils/mustache.py +3 -5
  116. langchain_core/utils/pydantic.py +16 -18
  117. langchain_core/utils/usage.py +1 -1
  118. langchain_core/utils/utils.py +29 -29
  119. langchain_core/vectorstores/base.py +18 -21
  120. langchain_core/vectorstores/in_memory.py +14 -87
  121. langchain_core/vectorstores/utils.py +2 -2
  122. langchain_core/version.py +1 -1
  123. {langchain_core-1.0.0a6.dist-info → langchain_core-1.0.0a7.dist-info}/METADATA +10 -21
  124. langchain_core-1.0.0a7.dist-info/RECORD +176 -0
  125. {langchain_core-1.0.0a6.dist-info → langchain_core-1.0.0a7.dist-info}/WHEEL +1 -1
  126. langchain_core/messages/block_translators/ollama.py +0 -47
  127. langchain_core/prompts/pipeline.py +0 -138
  128. langchain_core/tracers/langchain_v1.py +0 -31
  129. langchain_core/utils/loading.py +0 -35
  130. langchain_core-1.0.0a6.dist-info/RECORD +0 -181
  131. langchain_core-1.0.0a6.dist-info/entry_points.txt +0 -4
@@ -1,6 +1,6 @@
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
 
@@ -27,18 +27,18 @@ Furthermore, provider-specific fields **within** a standard block are fully supp
27
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::
30
+ !!! warning
31
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::
34
+ !!! note
35
35
  Following widespread adoption of `PEP 728 <https://peps.python.org/pep-0728/>`__, we
36
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
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
 
@@ -129,7 +129,7 @@ Factory functions offer benefits such as:
129
129
 
130
130
  """
131
131
 
132
- from typing import Any, Literal, Optional, Union, get_args, get_type_hints
132
+ from typing import Any, Literal, get_args, get_type_hints
133
133
 
134
134
  from typing_extensions import NotRequired, TypedDict
135
135
 
@@ -139,12 +139,12 @@ from langchain_core.utils.utils import ensure_id
139
139
  class Citation(TypedDict):
140
140
  """Annotation for citing data from a document.
141
141
 
142
- .. note::
142
+ !!! note
143
143
  ``start``/``end`` indices refer to the **response text**,
144
144
  not the source text. This means that the indices are relative to the model's
145
145
  response, not the original document (as specified in the ``url``).
146
146
 
147
- .. note::
147
+ !!! note
148
148
  ``create_citation`` may also be used as a factory to create a ``Citation``.
149
149
  Benefits include:
150
150
 
@@ -211,7 +211,7 @@ class NonStandardAnnotation(TypedDict):
211
211
  """Provider-specific annotation data."""
212
212
 
213
213
 
214
- Annotation = Union[Citation, NonStandardAnnotation]
214
+ Annotation = Citation | NonStandardAnnotation
215
215
 
216
216
 
217
217
  class TextContentBlock(TypedDict):
@@ -220,7 +220,7 @@ class TextContentBlock(TypedDict):
220
220
  This typically represents the main text content of a message, such as the response
221
221
  from a language model or the text of a user message.
222
222
 
223
- .. note::
223
+ !!! note
224
224
  ``create_text_block`` may also be used as a factory to create a
225
225
  ``TextContentBlock``. Benefits include:
226
226
 
@@ -247,7 +247,7 @@ class TextContentBlock(TypedDict):
247
247
  annotations: NotRequired[list[Annotation]]
248
248
  """``Citation``s and other annotations."""
249
249
 
250
- index: NotRequired[Union[int, str]]
250
+ index: NotRequired[int | str]
251
251
  """Index of block in aggregate response. Used during streaming."""
252
252
 
253
253
  extras: NotRequired[dict[str, Any]]
@@ -266,7 +266,7 @@ class ToolCall(TypedDict):
266
266
  This represents a request to call the tool named "foo" with arguments {"a": 1}
267
267
  and an identifier of "123".
268
268
 
269
- .. note::
269
+ !!! note
270
270
  ``create_tool_call`` may also be used as a factory to create a
271
271
  ``ToolCall``. Benefits include:
272
272
 
@@ -278,7 +278,7 @@ class ToolCall(TypedDict):
278
278
  type: Literal["tool_call"]
279
279
  """Used for discrimination."""
280
280
 
281
- id: Optional[str]
281
+ id: str | None
282
282
  """An identifier associated with the tool call.
283
283
 
284
284
  An identifier is needed to associate a tool call request with a tool
@@ -293,7 +293,7 @@ class ToolCall(TypedDict):
293
293
  args: dict[str, Any]
294
294
  """The arguments to the tool call."""
295
295
 
296
- index: NotRequired[Union[int, str]]
296
+ index: NotRequired[int | str]
297
297
  """Index of block in aggregate response. Used during streaming."""
298
298
 
299
299
  extras: NotRequired[dict[str, Any]]
@@ -326,7 +326,7 @@ class ToolCallChunk(TypedDict):
326
326
  type: Literal["tool_call_chunk"]
327
327
  """Used for serialization."""
328
328
 
329
- id: Optional[str]
329
+ id: str | None
330
330
  """An identifier associated with the tool call.
331
331
 
332
332
  An identifier is needed to associate a tool call request with a tool
@@ -334,13 +334,13 @@ class ToolCallChunk(TypedDict):
334
334
 
335
335
  """
336
336
 
337
- name: Optional[str]
337
+ name: str | None
338
338
  """The name of the tool to be called."""
339
339
 
340
- args: Optional[str]
340
+ args: str | None
341
341
  """The arguments to the tool call."""
342
342
 
343
- index: NotRequired[Union[int, str]]
343
+ index: NotRequired[int | str]
344
344
  """The index of the tool call in a sequence."""
345
345
 
346
346
  extras: NotRequired[dict[str, Any]]
@@ -360,7 +360,7 @@ class InvalidToolCall(TypedDict):
360
360
  type: Literal["invalid_tool_call"]
361
361
  """Used for discrimination."""
362
362
 
363
- id: Optional[str]
363
+ id: str | None
364
364
  """An identifier associated with the tool call.
365
365
 
366
366
  An identifier is needed to associate a tool call request with a tool
@@ -368,16 +368,16 @@ class InvalidToolCall(TypedDict):
368
368
 
369
369
  """
370
370
 
371
- name: Optional[str]
371
+ name: str | None
372
372
  """The name of the tool to be called."""
373
373
 
374
- args: Optional[str]
374
+ args: str | None
375
375
  """The arguments to the tool call."""
376
376
 
377
- error: Optional[str]
377
+ error: str | None
378
378
  """An error message associated with the tool call."""
379
379
 
380
- index: NotRequired[Union[int, str]]
380
+ index: NotRequired[int | str]
381
381
  """Index of block in aggregate response. Used during streaming."""
382
382
 
383
383
  extras: NotRequired[dict[str, Any]]
@@ -399,7 +399,7 @@ class ServerToolCall(TypedDict):
399
399
  args: dict[str, Any]
400
400
  """The arguments to the tool call."""
401
401
 
402
- index: NotRequired[Union[int, str]]
402
+ index: NotRequired[int | str]
403
403
  """Index of block in aggregate response. Used during streaming."""
404
404
 
405
405
  extras: NotRequired[dict[str, Any]]
@@ -421,7 +421,7 @@ class ServerToolCallChunk(TypedDict):
421
421
  id: NotRequired[str]
422
422
  """An identifier associated with the tool call."""
423
423
 
424
- index: NotRequired[Union[int, str]]
424
+ index: NotRequired[int | str]
425
425
  """Index of block in aggregate response. Used during streaming."""
426
426
 
427
427
  extras: NotRequired[dict[str, Any]]
@@ -446,7 +446,7 @@ class ServerToolResult(TypedDict):
446
446
  output: NotRequired[Any]
447
447
  """Output of the executed tool."""
448
448
 
449
- index: NotRequired[Union[int, str]]
449
+ index: NotRequired[int | str]
450
450
  """Index of block in aggregate response. Used during streaming."""
451
451
 
452
452
  extras: NotRequired[dict[str, Any]]
@@ -456,7 +456,7 @@ class ServerToolResult(TypedDict):
456
456
  class ReasoningContentBlock(TypedDict):
457
457
  """Reasoning output from a LLM.
458
458
 
459
- .. note::
459
+ !!! note
460
460
  ``create_reasoning_block`` may also be used as a factory to create a
461
461
  ``ReasoningContentBlock``. Benefits include:
462
462
 
@@ -485,7 +485,7 @@ class ReasoningContentBlock(TypedDict):
485
485
 
486
486
  """
487
487
 
488
- index: NotRequired[Union[int, str]]
488
+ index: NotRequired[int | str]
489
489
  """Index of block in aggregate response. Used during streaming."""
490
490
 
491
491
  extras: NotRequired[dict[str, Any]]
@@ -498,7 +498,7 @@ class ReasoningContentBlock(TypedDict):
498
498
  class ImageContentBlock(TypedDict):
499
499
  """Image data.
500
500
 
501
- .. note::
501
+ !!! note
502
502
  ``create_image_block`` may also be used as a factory to create a
503
503
  ``ImageContentBlock``. Benefits include:
504
504
 
@@ -529,7 +529,7 @@ class ImageContentBlock(TypedDict):
529
529
 
530
530
  """
531
531
 
532
- index: NotRequired[Union[int, str]]
532
+ index: NotRequired[int | str]
533
533
  """Index of block in aggregate response. Used during streaming."""
534
534
 
535
535
  url: NotRequired[str]
@@ -545,7 +545,7 @@ class ImageContentBlock(TypedDict):
545
545
  class VideoContentBlock(TypedDict):
546
546
  """Video data.
547
547
 
548
- .. note::
548
+ !!! note
549
549
  ``create_video_block`` may also be used as a factory to create a
550
550
  ``VideoContentBlock``. Benefits include:
551
551
 
@@ -576,7 +576,7 @@ class VideoContentBlock(TypedDict):
576
576
 
577
577
  """
578
578
 
579
- index: NotRequired[Union[int, str]]
579
+ index: NotRequired[int | str]
580
580
  """Index of block in aggregate response. Used during streaming."""
581
581
 
582
582
  url: NotRequired[str]
@@ -592,7 +592,7 @@ class VideoContentBlock(TypedDict):
592
592
  class AudioContentBlock(TypedDict):
593
593
  """Audio data.
594
594
 
595
- .. note::
595
+ !!! note
596
596
  ``create_audio_block`` may also be used as a factory to create an
597
597
  ``AudioContentBlock``. Benefits include:
598
598
  * Automatic ID generation (when not provided)
@@ -622,7 +622,7 @@ class AudioContentBlock(TypedDict):
622
622
 
623
623
  """
624
624
 
625
- index: NotRequired[Union[int, str]]
625
+ index: NotRequired[int | str]
626
626
  """Index of block in aggregate response. Used during streaming."""
627
627
 
628
628
  url: NotRequired[str]
@@ -638,17 +638,17 @@ class AudioContentBlock(TypedDict):
638
638
  class PlainTextContentBlock(TypedDict):
639
639
  """Plaintext data (e.g., from a document).
640
640
 
641
- .. note::
641
+ !!! note
642
642
  A ``PlainTextContentBlock`` existed in ``langchain-core<1.0.0``. Although the
643
643
  name has carried over, the structure has changed significantly. The only shared
644
644
  keys between the old and new versions are ``type`` and ``text``, though the
645
645
  ``type`` value has changed from ``'text'`` to ``'text-plain'``.
646
646
 
647
- .. note::
647
+ !!! note
648
648
  Title and context are optional fields that may be passed to the model. See
649
649
  Anthropic `example <https://docs.anthropic.com/en/docs/build-with-claude/citations#citable-vs-non-citable-content>`__.
650
650
 
651
- .. note::
651
+ !!! note
652
652
  ``create_plaintext_block`` may also be used as a factory to create a
653
653
  ``PlainTextContentBlock``. Benefits include:
654
654
 
@@ -675,7 +675,7 @@ class PlainTextContentBlock(TypedDict):
675
675
  mime_type: Literal["text/plain"]
676
676
  """MIME type of the file. Required for base64."""
677
677
 
678
- index: NotRequired[Union[int, str]]
678
+ index: NotRequired[int | str]
679
679
  """Index of block in aggregate response. Used during streaming."""
680
680
 
681
681
  url: NotRequired[str]
@@ -707,7 +707,7 @@ class FileContentBlock(TypedDict):
707
707
  content block type (e.g., ``ImageContentBlock``, ``AudioContentBlock``,
708
708
  ``PlainTextContentBlock``).
709
709
 
710
- .. note::
710
+ !!! note
711
711
  ``create_file_block`` may also be used as a factory to create a
712
712
  ``FileContentBlock``. Benefits include:
713
713
 
@@ -738,7 +738,7 @@ class FileContentBlock(TypedDict):
738
738
 
739
739
  """
740
740
 
741
- index: NotRequired[Union[int, str]]
741
+ index: NotRequired[int | str]
742
742
  """Index of block in aggregate response. Used during streaming."""
743
743
 
744
744
  url: NotRequired[str]
@@ -769,7 +769,7 @@ class NonStandardContentBlock(TypedDict):
769
769
  Has no ``extras`` field, as provider-specific data should be included in the
770
770
  ``value`` field.
771
771
 
772
- .. note::
772
+ !!! note
773
773
  ``create_non_standard_block`` may also be used as a factory to create a
774
774
  ``NonStandardContentBlock``. Benefits include:
775
775
 
@@ -793,35 +793,31 @@ class NonStandardContentBlock(TypedDict):
793
793
  value: dict[str, Any]
794
794
  """Provider-specific data."""
795
795
 
796
- index: NotRequired[Union[int, str]]
796
+ index: NotRequired[int | str]
797
797
  """Index of block in aggregate response. Used during streaming."""
798
798
 
799
799
 
800
800
  # --- 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
- ]
801
+ DataContentBlock = (
802
+ ImageContentBlock
803
+ | VideoContentBlock
804
+ | AudioContentBlock
805
+ | PlainTextContentBlock
806
+ | FileContentBlock
807
+ )
808
+
809
+ ToolContentBlock = (
810
+ ToolCall | ToolCallChunk | ServerToolCall | ServerToolCallChunk | ServerToolResult
811
+ )
812
+
813
+ ContentBlock = (
814
+ TextContentBlock
815
+ | InvalidToolCall
816
+ | ReasoningContentBlock
817
+ | NonStandardContentBlock
818
+ | DataContentBlock
819
+ | ToolContentBlock
820
+ )
825
821
 
826
822
 
827
823
  KNOWN_BLOCK_TYPES = {
@@ -879,7 +875,7 @@ def _get_data_content_block_types() -> tuple[str, ...]:
879
875
  def is_data_content_block(block: dict) -> bool:
880
876
  """Check if the provided content block is a data content block.
881
877
 
882
- Returns for both v0 (old-style) and v1 (new-style) multimodal data blocks.
878
+ Returns True for both v0 (old-style) and v1 (new-style) multimodal data blocks.
883
879
 
884
880
  Args:
885
881
  block: The content block to check.
@@ -922,9 +918,9 @@ def is_data_content_block(block: dict) -> bool:
922
918
  def create_text_block(
923
919
  text: str,
924
920
  *,
925
- id: Optional[str] = None,
926
- annotations: Optional[list[Annotation]] = None,
927
- index: Optional[Union[int, str]] = None,
921
+ id: str | None = None,
922
+ annotations: list[Annotation] | None = None,
923
+ index: int | str | None = None,
928
924
  **kwargs: Any,
929
925
  ) -> TextContentBlock:
930
926
  """Create a ``TextContentBlock``.
@@ -938,7 +934,7 @@ def create_text_block(
938
934
  Returns:
939
935
  A properly formatted ``TextContentBlock``.
940
936
 
941
- .. note::
937
+ !!! note
942
938
  The ``id`` is generated automatically if not provided, using a UUID4 format
943
939
  prefixed with ``'lc_'`` to indicate it is a LangChain-generated ID.
944
940
 
@@ -962,12 +958,12 @@ def create_text_block(
962
958
 
963
959
  def create_image_block(
964
960
  *,
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,
961
+ url: str | None = None,
962
+ base64: str | None = None,
963
+ file_id: str | None = None,
964
+ mime_type: str | None = None,
965
+ id: str | None = None,
966
+ index: int | str | None = None,
971
967
  **kwargs: Any,
972
968
  ) -> ImageContentBlock:
973
969
  """Create an ``ImageContentBlock``.
@@ -987,7 +983,7 @@ def create_image_block(
987
983
  ValueError: If no image source is provided or if ``base64`` is used without
988
984
  ``mime_type``.
989
985
 
990
- .. note::
986
+ !!! note
991
987
  The ``id`` is generated automatically if not provided, using a UUID4 format
992
988
  prefixed with ``'lc_'`` to indicate it is a LangChain-generated ID.
993
989
 
@@ -1018,12 +1014,12 @@ def create_image_block(
1018
1014
 
1019
1015
  def create_video_block(
1020
1016
  *,
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,
1017
+ url: str | None = None,
1018
+ base64: str | None = None,
1019
+ file_id: str | None = None,
1020
+ mime_type: str | None = None,
1021
+ id: str | None = None,
1022
+ index: int | str | None = None,
1027
1023
  **kwargs: Any,
1028
1024
  ) -> VideoContentBlock:
1029
1025
  """Create a ``VideoContentBlock``.
@@ -1043,7 +1039,7 @@ def create_video_block(
1043
1039
  ValueError: If no video source is provided or if ``base64`` is used without
1044
1040
  ``mime_type``.
1045
1041
 
1046
- .. note::
1042
+ !!! note
1047
1043
  The ``id`` is generated automatically if not provided, using a UUID4 format
1048
1044
  prefixed with ``'lc_'`` to indicate it is a LangChain-generated ID.
1049
1045
 
@@ -1078,12 +1074,12 @@ def create_video_block(
1078
1074
 
1079
1075
  def create_audio_block(
1080
1076
  *,
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,
1077
+ url: str | None = None,
1078
+ base64: str | None = None,
1079
+ file_id: str | None = None,
1080
+ mime_type: str | None = None,
1081
+ id: str | None = None,
1082
+ index: int | str | None = None,
1087
1083
  **kwargs: Any,
1088
1084
  ) -> AudioContentBlock:
1089
1085
  """Create an ``AudioContentBlock``.
@@ -1103,7 +1099,7 @@ def create_audio_block(
1103
1099
  ValueError: If no audio source is provided or if ``base64`` is used without
1104
1100
  ``mime_type``.
1105
1101
 
1106
- .. note::
1102
+ !!! note
1107
1103
  The ``id`` is generated automatically if not provided, using a UUID4 format
1108
1104
  prefixed with ``'lc_'`` to indicate it is a LangChain-generated ID.
1109
1105
 
@@ -1138,12 +1134,12 @@ def create_audio_block(
1138
1134
 
1139
1135
  def create_file_block(
1140
1136
  *,
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,
1137
+ url: str | None = None,
1138
+ base64: str | None = None,
1139
+ file_id: str | None = None,
1140
+ mime_type: str | None = None,
1141
+ id: str | None = None,
1142
+ index: int | str | None = None,
1147
1143
  **kwargs: Any,
1148
1144
  ) -> FileContentBlock:
1149
1145
  """Create a ``FileContentBlock``.
@@ -1163,7 +1159,7 @@ def create_file_block(
1163
1159
  ValueError: If no file source is provided or if ``base64`` is used without
1164
1160
  ``mime_type``.
1165
1161
 
1166
- .. note::
1162
+ !!! note
1167
1163
  The ``id`` is generated automatically if not provided, using a UUID4 format
1168
1164
  prefixed with ``'lc_'`` to indicate it is a LangChain-generated ID.
1169
1165
 
@@ -1197,14 +1193,14 @@ def create_file_block(
1197
1193
 
1198
1194
 
1199
1195
  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,
1196
+ text: str | None = None,
1197
+ url: str | None = None,
1198
+ base64: str | None = None,
1199
+ file_id: str | None = None,
1200
+ title: str | None = None,
1201
+ context: str | None = None,
1202
+ id: str | None = None,
1203
+ index: int | str | None = None,
1208
1204
  **kwargs: Any,
1209
1205
  ) -> PlainTextContentBlock:
1210
1206
  """Create a ``PlainTextContentBlock``.
@@ -1222,7 +1218,7 @@ def create_plaintext_block(
1222
1218
  Returns:
1223
1219
  A properly formatted ``PlainTextContentBlock``.
1224
1220
 
1225
- .. note::
1221
+ !!! note
1226
1222
  The ``id`` is generated automatically if not provided, using a UUID4 format
1227
1223
  prefixed with ``'lc_'`` to indicate it is a LangChain-generated ID.
1228
1224
 
@@ -1259,8 +1255,8 @@ def create_tool_call(
1259
1255
  name: str,
1260
1256
  args: dict[str, Any],
1261
1257
  *,
1262
- id: Optional[str] = None,
1263
- index: Optional[Union[int, str]] = None,
1258
+ id: str | None = None,
1259
+ index: int | str | None = None,
1264
1260
  **kwargs: Any,
1265
1261
  ) -> ToolCall:
1266
1262
  """Create a ``ToolCall``.
@@ -1274,7 +1270,7 @@ def create_tool_call(
1274
1270
  Returns:
1275
1271
  A properly formatted ``ToolCall``.
1276
1272
 
1277
- .. note::
1273
+ !!! note
1278
1274
  The ``id`` is generated automatically if not provided, using a UUID4 format
1279
1275
  prefixed with ``'lc_'`` to indicate it is a LangChain-generated ID.
1280
1276
 
@@ -1297,9 +1293,9 @@ def create_tool_call(
1297
1293
 
1298
1294
 
1299
1295
  def create_reasoning_block(
1300
- reasoning: Optional[str] = None,
1301
- id: Optional[str] = None,
1302
- index: Optional[Union[int, str]] = None,
1296
+ reasoning: str | None = None,
1297
+ id: str | None = None,
1298
+ index: int | str | None = None,
1303
1299
  **kwargs: Any,
1304
1300
  ) -> ReasoningContentBlock:
1305
1301
  """Create a ``ReasoningContentBlock``.
@@ -1312,7 +1308,7 @@ def create_reasoning_block(
1312
1308
  Returns:
1313
1309
  A properly formatted ``ReasoningContentBlock``.
1314
1310
 
1315
- .. note::
1311
+ !!! note
1316
1312
  The ``id`` is generated automatically if not provided, using a UUID4 format
1317
1313
  prefixed with ``'lc_'`` to indicate it is a LangChain-generated ID.
1318
1314
 
@@ -1335,12 +1331,12 @@ def create_reasoning_block(
1335
1331
 
1336
1332
  def create_citation(
1337
1333
  *,
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,
1334
+ url: str | None = None,
1335
+ title: str | None = None,
1336
+ start_index: int | None = None,
1337
+ end_index: int | None = None,
1338
+ cited_text: str | None = None,
1339
+ id: str | None = None,
1344
1340
  **kwargs: Any,
1345
1341
  ) -> Citation:
1346
1342
  """Create a ``Citation``.
@@ -1356,7 +1352,7 @@ def create_citation(
1356
1352
  Returns:
1357
1353
  A properly formatted ``Citation``.
1358
1354
 
1359
- .. note::
1355
+ !!! note
1360
1356
  The ``id`` is generated automatically if not provided, using a UUID4 format
1361
1357
  prefixed with ``'lc_'`` to indicate it is a LangChain-generated ID.
1362
1358
 
@@ -1384,8 +1380,8 @@ def create_citation(
1384
1380
  def create_non_standard_block(
1385
1381
  value: dict[str, Any],
1386
1382
  *,
1387
- id: Optional[str] = None,
1388
- index: Optional[Union[int, str]] = None,
1383
+ id: str | None = None,
1384
+ index: int | str | None = None,
1389
1385
  ) -> NonStandardContentBlock:
1390
1386
  """Create a ``NonStandardContentBlock``.
1391
1387
 
@@ -1397,7 +1393,7 @@ def create_non_standard_block(
1397
1393
  Returns:
1398
1394
  A properly formatted ``NonStandardContentBlock``.
1399
1395
 
1400
- .. note::
1396
+ !!! note
1401
1397
  The ``id`` is generated automatically if not provided, using a UUID4 format
1402
1398
  prefixed with ``'lc_'`` to indicate it is a LangChain-generated ID.
1403
1399
 
@@ -1,6 +1,6 @@
1
1
  """Human message."""
2
2
 
3
- from typing import Any, Literal, Optional, Union, cast, overload
3
+ from typing import Any, Literal, cast, overload
4
4
 
5
5
  from langchain_core.messages import content as types
6
6
  from langchain_core.messages.base import BaseMessage, BaseMessageChunk
@@ -38,28 +38,28 @@ class HumanMessage(BaseMessage):
38
38
  @overload
39
39
  def __init__(
40
40
  self,
41
- content: Union[str, list[Union[str, dict]]],
41
+ content: str | list[str | dict],
42
42
  **kwargs: Any,
43
43
  ) -> None: ...
44
44
 
45
45
  @overload
46
46
  def __init__(
47
47
  self,
48
- content: Optional[Union[str, list[Union[str, dict]]]] = None,
49
- content_blocks: Optional[list[types.ContentBlock]] = None,
48
+ content: str | list[str | dict] | None = None,
49
+ content_blocks: list[types.ContentBlock] | None = None,
50
50
  **kwargs: Any,
51
51
  ) -> None: ...
52
52
 
53
53
  def __init__(
54
54
  self,
55
- content: Optional[Union[str, list[Union[str, dict]]]] = None,
56
- content_blocks: Optional[list[types.ContentBlock]] = None,
55
+ content: str | list[str | dict] | None = None,
56
+ content_blocks: list[types.ContentBlock] | None = None,
57
57
  **kwargs: Any,
58
58
  ) -> None:
59
59
  """Specify ``content`` as positional arg or ``content_blocks`` for typing."""
60
60
  if content_blocks is not None:
61
61
  super().__init__(
62
- content=cast("Union[str, list[Union[str, dict]]]", content_blocks),
62
+ content=cast("str | list[str | dict]", content_blocks),
63
63
  **kwargs,
64
64
  )
65
65
  else: