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
@@ -2,10 +2,10 @@
2
2
 
3
3
  This module is only relevant for LangChain developers, not for users.
4
4
 
5
- .. warning::
5
+ !!! warning
6
6
 
7
- This module and its submodules are for internal use only. Do not use them
8
- in your own code. We may change the API at any time with no warning.
7
+ This module and its submodules are for internal use only. Do not use them in your
8
+ own code. We may change the API at any time with no warning.
9
9
 
10
10
  """
11
11
 
@@ -4,18 +4,18 @@ This module was loosely adapted from matplotlibs _api/deprecation.py module:
4
4
 
5
5
  https://github.com/matplotlib/matplotlib/blob/main/lib/matplotlib/_api/deprecation.py
6
6
 
7
- .. warning::
7
+ !!! warning
8
8
 
9
- This module is for internal use only. Do not use it in your own code.
10
- We may change the API at any time with no warning.
9
+ This module is for internal use only. Do not use it in your own code. We may change
10
+ the API at any time with no warning.
11
11
  """
12
12
 
13
13
  import contextlib
14
14
  import functools
15
15
  import inspect
16
16
  import warnings
17
- from collections.abc import Generator
18
- from typing import Any, Callable, TypeVar, Union, cast
17
+ from collections.abc import Callable, Generator
18
+ from typing import Any, TypeVar, cast
19
19
 
20
20
  from langchain_core._api.internal import is_caller_internal
21
21
 
@@ -27,7 +27,7 @@ class LangChainBetaWarning(DeprecationWarning):
27
27
  # PUBLIC API
28
28
 
29
29
 
30
- T = TypeVar("T", bound=Union[Callable[..., Any], type])
30
+ T = TypeVar("T", bound=Callable[..., Any] | type)
31
31
 
32
32
 
33
33
  def beta(
@@ -4,23 +4,21 @@ This module was adapted from matplotlibs _api/deprecation.py module:
4
4
 
5
5
  https://github.com/matplotlib/matplotlib/blob/main/lib/matplotlib/_api/deprecation.py
6
6
 
7
- .. warning::
7
+ !!! warning
8
8
 
9
- This module is for internal use only. Do not use it in your own code.
10
- We may change the API at any time with no warning.
9
+ This module is for internal use only. Do not use it in your own code. We may change
10
+ the API at any time with no warning.
11
11
  """
12
12
 
13
13
  import contextlib
14
14
  import functools
15
15
  import inspect
16
16
  import warnings
17
- from collections.abc import Generator
17
+ from collections.abc import Callable, Generator
18
18
  from typing import (
19
19
  Any,
20
- Callable,
21
20
  ParamSpec,
22
21
  TypeVar,
23
- Union,
24
22
  cast,
25
23
  )
26
24
 
@@ -42,7 +40,7 @@ class LangChainPendingDeprecationWarning(PendingDeprecationWarning):
42
40
 
43
41
 
44
42
  # Last Any should be FieldInfoV1 but this leads to circular imports
45
- T = TypeVar("T", bound=Union[type, Callable[..., Any], Any])
43
+ T = TypeVar("T", bound=type | Callable[..., Any] | Any)
46
44
 
47
45
 
48
46
  def _validate_deprecation_params(
@@ -276,7 +274,7 @@ def deprecated(
276
274
  if not _obj_type:
277
275
  _obj_type = "attribute"
278
276
  wrapped = None
279
- _name = _name or cast("Union[type, Callable]", obj.fget).__qualname__
277
+ _name = _name or cast("type | Callable", obj.fget).__qualname__
280
278
  old_doc = obj.__doc__
281
279
 
282
280
  class _DeprecatedProperty(property):
@@ -284,19 +282,17 @@ def deprecated(
284
282
 
285
283
  def __init__(
286
284
  self,
287
- fget: Union[Callable[[Any], Any], None] = None,
288
- fset: Union[Callable[[Any, Any], None], None] = None,
289
- fdel: Union[Callable[[Any], None], None] = None,
290
- doc: Union[str, None] = None,
285
+ fget: Callable[[Any], Any] | None = None,
286
+ fset: Callable[[Any, Any], None] | None = None,
287
+ fdel: Callable[[Any], None] | None = None,
288
+ doc: str | None = None,
291
289
  ) -> None:
292
290
  super().__init__(fget, fset, fdel, doc)
293
291
  self.__orig_fget = fget
294
292
  self.__orig_fset = fset
295
293
  self.__orig_fdel = fdel
296
294
 
297
- def __get__(
298
- self, instance: Any, owner: Union[type, None] = None
299
- ) -> Any:
295
+ def __get__(self, instance: Any, owner: type | None = None) -> Any:
300
296
  if instance is not None or owner is not None:
301
297
  emit_warning()
302
298
  if self.fget is None:
@@ -315,7 +311,7 @@ def deprecated(
315
311
  if self.fdel is not None:
316
312
  self.fdel(instance)
317
313
 
318
- def __set_name__(self, owner: Union[type, None], set_name: str) -> None:
314
+ def __set_name__(self, owner: type | None, set_name: str) -> None:
319
315
  nonlocal _name
320
316
  if _name == "<lambda>":
321
317
  _name = set_name
@@ -330,7 +326,7 @@ def deprecated(
330
326
  )
331
327
 
332
328
  else:
333
- _name = _name or cast("Union[type, Callable]", obj).__qualname__
329
+ _name = _name or cast("type | Callable", obj).__qualname__
334
330
  if not _obj_type:
335
331
  # edge case: when a function is within another function
336
332
  # within a test, this will call it a "method" not a "function"
@@ -363,19 +359,15 @@ def deprecated(
363
359
  _alternative
364
360
  and _alternative.rsplit(".", maxsplit=1)[-1].lower()
365
361
  == _alternative.rsplit(".", maxsplit=1)[-1]
366
- ):
367
- _alternative = f":meth:`~{_alternative}`"
368
- elif _alternative:
369
- _alternative = f":class:`~{_alternative}`"
362
+ ) or _alternative:
363
+ _alternative = f"`{_alternative}`"
370
364
 
371
365
  if (
372
366
  _alternative_import
373
367
  and _alternative_import.rsplit(".", maxsplit=1)[-1].lower()
374
368
  == _alternative_import.rsplit(".", maxsplit=1)[-1]
375
- ):
376
- _alternative_import = f":meth:`~{_alternative_import}`"
377
- elif _alternative_import:
378
- _alternative_import = f":class:`~{_alternative_import}`"
369
+ ) or _alternative_import:
370
+ _alternative_import = f"`{_alternative_import}`"
379
371
 
380
372
  components = [
381
373
  _message,
@@ -395,7 +387,7 @@ def deprecated(
395
387
  else:
396
388
  removal_str = ""
397
389
  new_doc = f"""\
398
- .. deprecated:: {since} {details} {removal_str}
390
+ !!! deprecated "{since} {details} {removal_str}"
399
391
 
400
392
  {old_doc}\
401
393
  """
@@ -544,9 +536,9 @@ def rename_parameter(
544
536
  ) -> Callable[[Callable[_P, _R]], Callable[_P, _R]]:
545
537
  """Decorator indicating that parameter *old* of *func* is renamed to *new*.
546
538
 
547
- The actual implementation of *func* should use *new*, not *old*. If *old*
548
- is passed to *func*, a DeprecationWarning is emitted, and its value is
549
- used, even if *new* is also passed by keyword.
539
+ The actual implementation of *func* should use *new*, not *old*. If *old* is passed
540
+ to *func*, a DeprecationWarning is emitted, and its value is used, even if *new* is
541
+ also passed by keyword.
550
542
 
551
543
  Args:
552
544
  since: The version in which the parameter was renamed.
@@ -1,6 +1,5 @@
1
1
  import os
2
2
  from pathlib import Path
3
- from typing import Optional, Union
4
3
 
5
4
  HERE = Path(__file__).parent
6
5
 
@@ -9,9 +8,7 @@ PACKAGE_DIR = HERE.parent
9
8
  SEPARATOR = os.sep
10
9
 
11
10
 
12
- def get_relative_path(
13
- file: Union[Path, str], *, relative_to: Path = PACKAGE_DIR
14
- ) -> str:
11
+ def get_relative_path(file: Path | str, *, relative_to: Path = PACKAGE_DIR) -> str:
15
12
  """Get the path of the file as a relative path to the package directory.
16
13
 
17
14
  Args:
@@ -27,9 +24,9 @@ def get_relative_path(
27
24
 
28
25
 
29
26
  def as_import_path(
30
- file: Union[Path, str],
27
+ file: Path | str,
31
28
  *,
32
- suffix: Optional[str] = None,
29
+ suffix: str | None = None,
33
30
  relative_to: Path = PACKAGE_DIR,
34
31
  ) -> str:
35
32
  """Path of the file as a LangChain import exclude langchain top namespace.
@@ -1,11 +1,10 @@
1
1
  from importlib import import_module
2
- from typing import Union
3
2
 
4
3
 
5
4
  def import_attr(
6
5
  attr_name: str,
7
- module_name: Union[str, None],
8
- package: Union[str, None],
6
+ module_name: str | None,
7
+ package: str | None,
9
8
  ) -> object:
10
9
  """Import an attribute from a module located in a package.
11
10
 
langchain_core/agents.py CHANGED
@@ -2,13 +2,14 @@
2
2
 
3
3
  **ATTENTION** The schema definitions are provided for backwards compatibility.
4
4
 
5
- New agents should be built using the langgraph library
6
- (https://github.com/langchain-ai/langgraph)), which provides a simpler
7
- and more flexible way to define agents.
5
+ !!! important
6
+ New agents should be built using the
7
+ [langgraph library](https://github.com/langchain-ai/langgraph), which provides a
8
+ simpler and more flexible way to define agents.
8
9
 
9
- Please see the migration guide for information on how to migrate existing
10
- agents to modern langgraph agents:
11
- https://python.langchain.com/docs/how_to/migrate_agent/
10
+ Please see the
11
+ [migration guide](https://python.langchain.com/docs/how_to/migrate_agent/) for
12
+ information on how to migrate existing agents to modern langgraph agents.
12
13
 
13
14
  Agents use language models to choose a sequence of actions to take.
14
15
 
@@ -28,7 +29,7 @@ from __future__ import annotations
28
29
 
29
30
  import json
30
31
  from collections.abc import Sequence
31
- from typing import Any, Literal, Union
32
+ from typing import Any, Literal
32
33
 
33
34
  from langchain_core.load.serializable import Serializable
34
35
  from langchain_core.messages import (
@@ -48,7 +49,7 @@ class AgentAction(Serializable):
48
49
 
49
50
  tool: str
50
51
  """The name of the Tool to execute."""
51
- tool_input: Union[str, dict]
52
+ tool_input: str | dict
52
53
  """The input to pass in to the Tool."""
53
54
  log: str
54
55
  """Additional information to log about the action.
@@ -61,9 +62,7 @@ class AgentAction(Serializable):
61
62
  type: Literal["AgentAction"] = "AgentAction"
62
63
 
63
64
  # Override init to support instantiation by position for backward compat.
64
- def __init__(
65
- self, tool: str, tool_input: Union[str, dict], log: str, **kwargs: Any
66
- ):
65
+ def __init__(self, tool: str, tool_input: str | dict, log: str, **kwargs: Any):
67
66
  """Create an AgentAction.
68
67
 
69
68
  Args:
langchain_core/caches.py CHANGED
@@ -1,6 +1,6 @@
1
1
  """Cache classes.
2
2
 
3
- .. warning::
3
+ !!! warning
4
4
  Beta Feature!
5
5
 
6
6
  **Cache** provides an optional caching layer for LLMs.
@@ -25,7 +25,7 @@ from __future__ import annotations
25
25
 
26
26
  from abc import ABC, abstractmethod
27
27
  from collections.abc import Sequence
28
- from typing import Any, Optional
28
+ from typing import Any
29
29
 
30
30
  from typing_extensions import override
31
31
 
@@ -52,7 +52,7 @@ class BaseCache(ABC):
52
52
  """
53
53
 
54
54
  @abstractmethod
55
- def lookup(self, prompt: str, llm_string: str) -> Optional[RETURN_VAL_TYPE]:
55
+ def lookup(self, prompt: str, llm_string: str) -> RETURN_VAL_TYPE | None:
56
56
  """Look up based on prompt and llm_string.
57
57
 
58
58
  A cache implementation is expected to generate a key from the 2-tuple
@@ -97,7 +97,7 @@ class BaseCache(ABC):
97
97
  def clear(self, **kwargs: Any) -> None:
98
98
  """Clear cache that can take additional keyword arguments."""
99
99
 
100
- async def alookup(self, prompt: str, llm_string: str) -> Optional[RETURN_VAL_TYPE]:
100
+ async def alookup(self, prompt: str, llm_string: str) -> RETURN_VAL_TYPE | None:
101
101
  """Async look up based on prompt and llm_string.
102
102
 
103
103
  A cache implementation is expected to generate a key from the 2-tuple
@@ -149,7 +149,7 @@ class BaseCache(ABC):
149
149
  class InMemoryCache(BaseCache):
150
150
  """Cache that stores things in memory."""
151
151
 
152
- def __init__(self, *, maxsize: Optional[int] = None) -> None:
152
+ def __init__(self, *, maxsize: int | None = None) -> None:
153
153
  """Initialize with empty cache.
154
154
 
155
155
  Args:
@@ -167,7 +167,7 @@ class InMemoryCache(BaseCache):
167
167
  raise ValueError(msg)
168
168
  self._maxsize = maxsize
169
169
 
170
- def lookup(self, prompt: str, llm_string: str) -> Optional[RETURN_VAL_TYPE]:
170
+ def lookup(self, prompt: str, llm_string: str) -> RETURN_VAL_TYPE | None:
171
171
  """Look up based on prompt and llm_string.
172
172
 
173
173
  Args:
@@ -201,7 +201,7 @@ class InMemoryCache(BaseCache):
201
201
  """Clear cache."""
202
202
  self._cache = {}
203
203
 
204
- async def alookup(self, prompt: str, llm_string: str) -> Optional[RETURN_VAL_TYPE]:
204
+ async def alookup(self, prompt: str, llm_string: str) -> RETURN_VAL_TYPE | None:
205
205
  """Async look up based on prompt and llm_string.
206
206
 
207
207
  Args: