langchain-core 1.0.0a8__py3-none-any.whl → 1.0.0rc1__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 (135) hide show
  1. langchain_core/__init__.py +1 -1
  2. langchain_core/_api/__init__.py +0 -1
  3. langchain_core/_api/beta_decorator.py +17 -20
  4. langchain_core/_api/deprecation.py +30 -35
  5. langchain_core/_import_utils.py +1 -1
  6. langchain_core/agents.py +7 -6
  7. langchain_core/caches.py +4 -10
  8. langchain_core/callbacks/__init__.py +1 -8
  9. langchain_core/callbacks/base.py +232 -243
  10. langchain_core/callbacks/file.py +33 -33
  11. langchain_core/callbacks/manager.py +353 -416
  12. langchain_core/callbacks/stdout.py +21 -22
  13. langchain_core/callbacks/streaming_stdout.py +32 -32
  14. langchain_core/callbacks/usage.py +54 -51
  15. langchain_core/chat_history.py +42 -57
  16. langchain_core/document_loaders/langsmith.py +21 -21
  17. langchain_core/documents/__init__.py +0 -1
  18. langchain_core/documents/base.py +37 -40
  19. langchain_core/documents/transformers.py +28 -29
  20. langchain_core/embeddings/fake.py +46 -52
  21. langchain_core/exceptions.py +5 -5
  22. langchain_core/indexing/api.py +11 -11
  23. langchain_core/indexing/base.py +24 -24
  24. langchain_core/language_models/__init__.py +0 -2
  25. langchain_core/language_models/_utils.py +51 -53
  26. langchain_core/language_models/base.py +23 -24
  27. langchain_core/language_models/chat_models.py +121 -144
  28. langchain_core/language_models/fake_chat_models.py +5 -5
  29. langchain_core/language_models/llms.py +10 -12
  30. langchain_core/load/dump.py +1 -1
  31. langchain_core/load/load.py +16 -16
  32. langchain_core/load/serializable.py +35 -34
  33. langchain_core/messages/__init__.py +1 -16
  34. langchain_core/messages/ai.py +105 -104
  35. langchain_core/messages/base.py +26 -26
  36. langchain_core/messages/block_translators/__init__.py +17 -17
  37. langchain_core/messages/block_translators/anthropic.py +2 -2
  38. langchain_core/messages/block_translators/bedrock_converse.py +2 -2
  39. langchain_core/messages/block_translators/google_genai.py +2 -2
  40. langchain_core/messages/block_translators/groq.py +117 -21
  41. langchain_core/messages/block_translators/langchain_v0.py +2 -2
  42. langchain_core/messages/block_translators/openai.py +4 -4
  43. langchain_core/messages/chat.py +1 -1
  44. langchain_core/messages/content.py +189 -193
  45. langchain_core/messages/function.py +5 -5
  46. langchain_core/messages/human.py +15 -17
  47. langchain_core/messages/modifier.py +1 -1
  48. langchain_core/messages/system.py +12 -14
  49. langchain_core/messages/tool.py +45 -49
  50. langchain_core/messages/utils.py +384 -396
  51. langchain_core/output_parsers/__init__.py +1 -14
  52. langchain_core/output_parsers/base.py +22 -23
  53. langchain_core/output_parsers/json.py +3 -3
  54. langchain_core/output_parsers/list.py +1 -1
  55. langchain_core/output_parsers/openai_functions.py +46 -44
  56. langchain_core/output_parsers/openai_tools.py +7 -7
  57. langchain_core/output_parsers/pydantic.py +10 -11
  58. langchain_core/output_parsers/string.py +1 -1
  59. langchain_core/output_parsers/transform.py +2 -2
  60. langchain_core/output_parsers/xml.py +1 -1
  61. langchain_core/outputs/__init__.py +1 -1
  62. langchain_core/outputs/chat_generation.py +14 -14
  63. langchain_core/outputs/generation.py +5 -5
  64. langchain_core/outputs/llm_result.py +5 -5
  65. langchain_core/prompt_values.py +5 -5
  66. langchain_core/prompts/__init__.py +3 -23
  67. langchain_core/prompts/base.py +32 -37
  68. langchain_core/prompts/chat.py +216 -222
  69. langchain_core/prompts/dict.py +2 -2
  70. langchain_core/prompts/few_shot.py +76 -83
  71. langchain_core/prompts/few_shot_with_templates.py +6 -8
  72. langchain_core/prompts/image.py +11 -13
  73. langchain_core/prompts/loading.py +1 -1
  74. langchain_core/prompts/message.py +2 -2
  75. langchain_core/prompts/prompt.py +14 -16
  76. langchain_core/prompts/string.py +19 -7
  77. langchain_core/prompts/structured.py +24 -25
  78. langchain_core/rate_limiters.py +36 -38
  79. langchain_core/retrievers.py +41 -182
  80. langchain_core/runnables/base.py +565 -590
  81. langchain_core/runnables/branch.py +7 -7
  82. langchain_core/runnables/config.py +37 -44
  83. langchain_core/runnables/configurable.py +8 -9
  84. langchain_core/runnables/fallbacks.py +8 -8
  85. langchain_core/runnables/graph.py +28 -27
  86. langchain_core/runnables/graph_ascii.py +19 -18
  87. langchain_core/runnables/graph_mermaid.py +20 -31
  88. langchain_core/runnables/graph_png.py +7 -7
  89. langchain_core/runnables/history.py +20 -20
  90. langchain_core/runnables/passthrough.py +8 -8
  91. langchain_core/runnables/retry.py +3 -3
  92. langchain_core/runnables/router.py +1 -1
  93. langchain_core/runnables/schema.py +33 -33
  94. langchain_core/runnables/utils.py +30 -34
  95. langchain_core/stores.py +72 -102
  96. langchain_core/sys_info.py +27 -29
  97. langchain_core/tools/__init__.py +1 -14
  98. langchain_core/tools/base.py +63 -63
  99. langchain_core/tools/convert.py +92 -92
  100. langchain_core/tools/render.py +9 -9
  101. langchain_core/tools/retriever.py +1 -1
  102. langchain_core/tools/simple.py +6 -7
  103. langchain_core/tools/structured.py +17 -18
  104. langchain_core/tracers/__init__.py +1 -9
  105. langchain_core/tracers/base.py +35 -35
  106. langchain_core/tracers/context.py +12 -17
  107. langchain_core/tracers/event_stream.py +3 -3
  108. langchain_core/tracers/langchain.py +8 -8
  109. langchain_core/tracers/log_stream.py +17 -18
  110. langchain_core/tracers/memory_stream.py +2 -2
  111. langchain_core/tracers/schemas.py +0 -129
  112. langchain_core/utils/aiter.py +31 -31
  113. langchain_core/utils/env.py +5 -5
  114. langchain_core/utils/function_calling.py +48 -120
  115. langchain_core/utils/html.py +4 -4
  116. langchain_core/utils/input.py +2 -2
  117. langchain_core/utils/interactive_env.py +1 -1
  118. langchain_core/utils/iter.py +19 -19
  119. langchain_core/utils/json.py +1 -1
  120. langchain_core/utils/json_schema.py +2 -2
  121. langchain_core/utils/mustache.py +5 -5
  122. langchain_core/utils/pydantic.py +17 -17
  123. langchain_core/utils/strings.py +4 -4
  124. langchain_core/utils/utils.py +25 -28
  125. langchain_core/vectorstores/base.py +43 -64
  126. langchain_core/vectorstores/in_memory.py +83 -85
  127. langchain_core/version.py +1 -1
  128. {langchain_core-1.0.0a8.dist-info → langchain_core-1.0.0rc1.dist-info}/METADATA +23 -11
  129. langchain_core-1.0.0rc1.dist-info/RECORD +172 -0
  130. langchain_core/memory.py +0 -120
  131. langchain_core/pydantic_v1/__init__.py +0 -30
  132. langchain_core/pydantic_v1/dataclasses.py +0 -23
  133. langchain_core/pydantic_v1/main.py +0 -23
  134. langchain_core-1.0.0a8.dist-info/RECORD +0 -176
  135. {langchain_core-1.0.0a8.dist-info → langchain_core-1.0.0rc1.dist-info}/WHEEL +0 -0
@@ -1,4 +1,4 @@
1
- """``langchain-core`` defines the base abstractions for the LangChain ecosystem.
1
+ """`langchain-core` defines the base abstractions for the LangChain ecosystem.
2
2
 
3
3
  The interfaces for core components like chat models, LLMs, vector stores, retrievers,
4
4
  and more are defined here. The universal invocation protocol (Runnables) along with
@@ -6,7 +6,6 @@ This module is only relevant for LangChain developers, not for users.
6
6
 
7
7
  This module and its submodules are for internal use only. Do not use them in your
8
8
  own code. We may change the API at any time with no warning.
9
-
10
9
  """
11
10
 
12
11
  from typing import TYPE_CHECKING
@@ -40,40 +40,37 @@ def beta(
40
40
  """Decorator to mark a function, a class, or a property as beta.
41
41
 
42
42
  When marking a classmethod, a staticmethod, or a property, the
43
- ``@beta`` decorator should go *under* ``@classmethod`` and
44
- ``@staticmethod`` (i.e., `beta` should directly decorate the
45
- underlying callable), but *over* ``@property``.
43
+ `@beta` decorator should go *under* `@classmethod` and
44
+ `@staticmethod` (i.e., `beta` should directly decorate the
45
+ underlying callable), but *over* `@property`.
46
46
 
47
- When marking a class ``C`` intended to be used as a base class in a
48
- multiple inheritance hierarchy, ``C`` *must* define an ``__init__`` method
49
- (if ``C`` instead inherited its ``__init__`` from its own base class, then
50
- ``@beta`` would mess up ``__init__`` inheritance when installing its
51
- own (annotation-emitting) ``C.__init__``).
47
+ When marking a class `C` intended to be used as a base class in a
48
+ multiple inheritance hierarchy, `C` *must* define an `__init__` method
49
+ (if `C` instead inherited its `__init__` from its own base class, then
50
+ `@beta` would mess up `__init__` inheritance when installing its
51
+ own (annotation-emitting) `C.__init__`).
52
52
 
53
53
  Args:
54
- message : str, optional
54
+ message:
55
55
  Override the default beta message. The %(since)s,
56
56
  %(name)s, %(alternative)s, %(obj_type)s, %(addendum)s,
57
57
  and %(removal)s format specifiers will be replaced by the
58
58
  values of the respective arguments passed to this function.
59
- name : str, optional
59
+ name:
60
60
  The name of the beta object.
61
- obj_type : str, optional
61
+ obj_type:
62
62
  The object type being beta.
63
- addendum : str, optional
63
+ addendum:
64
64
  Additional text appended directly to the final message.
65
65
 
66
66
  Returns:
67
67
  A decorator which can be used to mark functions or classes as beta.
68
68
 
69
- Examples:
70
-
71
- .. code-block:: python
72
-
73
- @beta
74
- def the_function_to_annotate():
75
- pass
76
-
69
+ ```python
70
+ @beta
71
+ def the_function_to_annotate():
72
+ pass
73
+ ```
77
74
  """
78
75
 
79
76
  def beta(
@@ -82,62 +82,59 @@ def deprecated(
82
82
  """Decorator to mark a function, a class, or a property as deprecated.
83
83
 
84
84
  When deprecating a classmethod, a staticmethod, or a property, the
85
- ``@deprecated`` decorator should go *under* ``@classmethod`` and
86
- ``@staticmethod`` (i.e., `deprecated` should directly decorate the
87
- underlying callable), but *over* ``@property``.
85
+ `@deprecated` decorator should go *under* `@classmethod` and
86
+ `@staticmethod` (i.e., `deprecated` should directly decorate the
87
+ underlying callable), but *over* `@property`.
88
88
 
89
- When deprecating a class ``C`` intended to be used as a base class in a
90
- multiple inheritance hierarchy, ``C`` *must* define an ``__init__`` method
91
- (if ``C`` instead inherited its ``__init__`` from its own base class, then
92
- ``@deprecated`` would mess up ``__init__`` inheritance when installing its
93
- own (deprecation-emitting) ``C.__init__``).
89
+ When deprecating a class `C` intended to be used as a base class in a
90
+ multiple inheritance hierarchy, `C` *must* define an `__init__` method
91
+ (if `C` instead inherited its `__init__` from its own base class, then
92
+ `@deprecated` would mess up `__init__` inheritance when installing its
93
+ own (deprecation-emitting) `C.__init__`).
94
94
 
95
95
  Parameters are the same as for `warn_deprecated`, except that *obj_type*
96
96
  defaults to 'class' if decorating a class, 'attribute' if decorating a
97
97
  property, and 'function' otherwise.
98
98
 
99
99
  Args:
100
- since : str
100
+ since:
101
101
  The release at which this API became deprecated.
102
- message : str, optional
102
+ message:
103
103
  Override the default deprecation message. The %(since)s,
104
104
  %(name)s, %(alternative)s, %(obj_type)s, %(addendum)s,
105
105
  and %(removal)s format specifiers will be replaced by the
106
106
  values of the respective arguments passed to this function.
107
- name : str, optional
107
+ name:
108
108
  The name of the deprecated object.
109
- alternative : str, optional
109
+ alternative:
110
110
  An alternative API that the user may use in place of the
111
111
  deprecated API. The deprecation warning will tell the user
112
112
  about this alternative if provided.
113
- alternative_import: str, optional
113
+ alternative_import:
114
114
  An alternative import that the user may use instead.
115
- pending : bool, optional
116
- If True, uses a PendingDeprecationWarning instead of a
115
+ pending:
116
+ If `True`, uses a `PendingDeprecationWarning` instead of a
117
117
  DeprecationWarning. Cannot be used together with removal.
118
- obj_type : str, optional
118
+ obj_type:
119
119
  The object type being deprecated.
120
- addendum : str, optional
120
+ addendum:
121
121
  Additional text appended directly to the final message.
122
- removal : str, optional
122
+ removal:
123
123
  The expected removal version. With the default (an empty
124
124
  string), a removal version is automatically computed from
125
125
  since. Set to other Falsy values to not schedule a removal
126
126
  date. Cannot be used together with pending.
127
- package: str, optional
127
+ package:
128
128
  The package of the deprecated object.
129
129
 
130
130
  Returns:
131
131
  A decorator to mark a function or class as deprecated.
132
132
 
133
- Examples:
134
-
135
- .. code-block:: python
136
-
137
- @deprecated("1.4.0")
138
- def the_function_to_deprecate():
139
- pass
140
-
133
+ ```python
134
+ @deprecated("1.4.0")
135
+ def the_function_to_deprecate():
136
+ pass
137
+ ```
141
138
  """
142
139
  _validate_deprecation_params(
143
140
  removal, alternative, alternative_import, pending=pending
@@ -372,7 +369,7 @@ def deprecated(
372
369
  components = [
373
370
  _message,
374
371
  f"Use {_alternative} instead." if _alternative else "",
375
- f"Use ``{_alternative_import}`` instead." if _alternative_import else "",
372
+ f"Use `{_alternative_import}` instead." if _alternative_import else "",
376
373
  _addendum,
377
374
  ]
378
375
  details = " ".join([component.strip() for component in components if component])
@@ -440,7 +437,7 @@ def warn_deprecated(
440
437
  alternative_import:
441
438
  An alternative import that the user may use instead.
442
439
  pending:
443
- If True, uses a PendingDeprecationWarning instead of a
440
+ If `True`, uses a `PendingDeprecationWarning` instead of a
444
441
  DeprecationWarning. Cannot be used together with removal.
445
442
  obj_type:
446
443
  The object type being deprecated.
@@ -550,12 +547,10 @@ def rename_parameter(
550
547
  A decorator indicating that a parameter was renamed.
551
548
 
552
549
  Example:
553
-
554
- .. code-block:: python
555
-
556
- @_api.rename_parameter("3.1", "bad_name", "good_name")
557
- def func(good_name): ...
558
-
550
+ ```python
551
+ @_api.rename_parameter("3.1", "bad_name", "good_name")
552
+ def func(good_name): ...
553
+ ```
559
554
  """
560
555
 
561
556
  def decorator(f: Callable[_P, _R]) -> Callable[_P, _R]:
@@ -13,7 +13,7 @@ def import_attr(
13
13
 
14
14
  Args:
15
15
  attr_name: The name of the attribute to import.
16
- module_name: The name of the module to import from. If None, the attribute
16
+ module_name: The name of the module to import from. If `None`, the attribute
17
17
  is imported from the package itself.
18
18
  package: The name of the package where the module is located.
19
19
 
langchain_core/agents.py CHANGED
@@ -1,8 +1,9 @@
1
1
  """Schema definitions for representing agent actions, observations, and return values.
2
2
 
3
- **ATTENTION** The schema definitions are provided for backwards compatibility.
3
+ !!! warning
4
+ The schema definitions are provided for backwards compatibility.
4
5
 
5
- !!! important
6
+ !!! warning
6
7
  New agents should be built using the
7
8
  [langgraph library](https://github.com/langchain-ai/langgraph), which provides a
8
9
  simpler and more flexible way to define agents.
@@ -16,10 +17,10 @@ Agents use language models to choose a sequence of actions to take.
16
17
  A basic agent works in the following manner:
17
18
 
18
19
  1. Given a prompt an agent uses an LLM to request an action to take
19
- (e.g., a tool to run).
20
+ (e.g., a tool to run).
20
21
  2. The agent executes the action (e.g., runs the tool), and receives an observation.
21
22
  3. The agent returns the observation to the LLM, which can then be used to generate
22
- the next action.
23
+ the next action.
23
24
  4. When the agent reaches a stopping condition, it returns a final return value.
24
25
 
25
26
  The schemas for the agents themselves are defined in langchain.agents.agent.
@@ -86,7 +87,7 @@ class AgentAction(Serializable):
86
87
  """Get the namespace of the langchain object.
87
88
 
88
89
  Returns:
89
- ``["langchain", "schema", "agent"]``
90
+ `["langchain", "schema", "agent"]`
90
91
  """
91
92
  return ["langchain", "schema", "agent"]
92
93
 
@@ -163,7 +164,7 @@ class AgentFinish(Serializable):
163
164
  """Get the namespace of the langchain object.
164
165
 
165
166
  Returns:
166
- ``["langchain", "schema", "agent"]``
167
+ `["langchain", "schema", "agent"]`
167
168
  """
168
169
  return ["langchain", "schema", "agent"]
169
170
 
langchain_core/caches.py CHANGED
@@ -1,24 +1,18 @@
1
1
  """Cache classes.
2
2
 
3
3
  !!! warning
4
- Beta Feature!
4
+ Beta Feature!
5
5
 
6
6
  **Cache** provides an optional caching layer for LLMs.
7
7
 
8
8
  Cache is useful for two reasons:
9
9
 
10
10
  - It can save you money by reducing the number of API calls you make to the LLM
11
- provider if you're often requesting the same completion multiple times.
11
+ provider if you're often requesting the same completion multiple times.
12
12
  - It can speed up your application by reducing the number of API calls you make
13
- to the LLM provider.
13
+ to the LLM provider.
14
14
 
15
15
  Cache directly competes with Memory. See documentation for Pros and Cons.
16
-
17
- **Class hierarchy:**
18
-
19
- .. code-block::
20
-
21
- BaseCache --> <name>Cache # Examples: InMemoryCache, RedisCache, GPTCache
22
16
  """
23
17
 
24
18
  from __future__ import annotations
@@ -154,7 +148,7 @@ class InMemoryCache(BaseCache):
154
148
 
155
149
  Args:
156
150
  maxsize: The maximum number of items to store in the cache.
157
- If None, the cache has no maximum size.
151
+ If `None`, the cache has no maximum size.
158
152
  If the cache exceeds the maximum size, the oldest items are removed.
159
153
  Default is None.
160
154
 
@@ -1,11 +1,4 @@
1
- """**Callback handlers** allow listening to events in LangChain.
2
-
3
- **Class hierarchy:**
4
-
5
- .. code-block::
6
-
7
- BaseCallbackHandler --> <name>CallbackHandler # Example: AimCallbackHandler
8
- """
1
+ """**Callback handlers** allow listening to events in LangChain."""
9
2
 
10
3
  from typing import TYPE_CHECKING
11
4