langchain-core 1.0.0a6__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 +53 -51
  47. langchain_core/messages/block_translators/__init__.py +19 -22
  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 +10 -7
  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 +1476 -1626
  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 +284 -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.0a6.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.0a6.dist-info/METADATA +0 -67
  164. langchain_core-1.0.0a6.dist-info/RECORD +0 -181
  165. langchain_core-1.0.0a6.dist-info/entry_points.txt +0 -4
@@ -2,14 +2,11 @@
2
2
 
3
3
  from __future__ import annotations
4
4
 
5
- from collections.abc import Awaitable
5
+ from collections.abc import Awaitable, Callable
6
6
  from inspect import signature
7
7
  from typing import (
8
8
  TYPE_CHECKING,
9
9
  Any,
10
- Callable,
11
- Optional,
12
- Union,
13
10
  )
14
11
 
15
12
  from typing_extensions import override
@@ -34,9 +31,9 @@ class Tool(BaseTool):
34
31
  """Tool that takes in function or coroutine directly."""
35
32
 
36
33
  description: str = ""
37
- func: Optional[Callable[..., str]]
34
+ func: Callable[..., str] | None
38
35
  """The function to run when the tool is called."""
39
- coroutine: Optional[Callable[..., Awaitable[str]]] = None
36
+ coroutine: Callable[..., Awaitable[str]] | None = None
40
37
  """The asynchronous version of the function."""
41
38
 
42
39
  # --- Runnable ---
@@ -44,8 +41,8 @@ class Tool(BaseTool):
44
41
  @override
45
42
  async def ainvoke(
46
43
  self,
47
- input: Union[str, dict, ToolCall],
48
- config: Optional[RunnableConfig] = None,
44
+ input: str | dict | ToolCall,
45
+ config: RunnableConfig | None = None,
49
46
  **kwargs: Any,
50
47
  ) -> Any:
51
48
  if not self.coroutine:
@@ -70,9 +67,9 @@ class Tool(BaseTool):
70
67
  return {"tool_input": {"type": "string"}}
71
68
 
72
69
  def _to_args_and_kwargs(
73
- self, tool_input: Union[str, dict], tool_call_id: Optional[str]
70
+ self, tool_input: str | dict, tool_call_id: str | None
74
71
  ) -> tuple[tuple, dict]:
75
- """Convert tool input to pydantic model.
72
+ """Convert tool input to Pydantic model.
76
73
 
77
74
  Args:
78
75
  tool_input: The input to the tool.
@@ -82,8 +79,7 @@ class Tool(BaseTool):
82
79
  ToolException: If the tool input is invalid.
83
80
 
84
81
  Returns:
85
- the pydantic model args and kwargs.
86
-
82
+ The Pydantic model args and kwargs.
87
83
  """
88
84
  args, kwargs = super()._to_args_and_kwargs(tool_input, tool_call_id)
89
85
  # For backwards compatibility. The tool must be run with a single input
@@ -101,7 +97,7 @@ class Tool(BaseTool):
101
97
  self,
102
98
  *args: Any,
103
99
  config: RunnableConfig,
104
- run_manager: Optional[CallbackManagerForToolRun] = None,
100
+ run_manager: CallbackManagerForToolRun | None = None,
105
101
  **kwargs: Any,
106
102
  ) -> Any:
107
103
  """Use the tool.
@@ -128,7 +124,7 @@ class Tool(BaseTool):
128
124
  self,
129
125
  *args: Any,
130
126
  config: RunnableConfig,
131
- run_manager: Optional[AsyncCallbackManagerForToolRun] = None,
127
+ run_manager: AsyncCallbackManagerForToolRun | None = None,
132
128
  **kwargs: Any,
133
129
  ) -> Any:
134
130
  """Use the tool asynchronously.
@@ -157,7 +153,7 @@ class Tool(BaseTool):
157
153
 
158
154
  # TODO: this is for backwards compatibility, remove in future
159
155
  def __init__(
160
- self, name: str, func: Optional[Callable], description: str, **kwargs: Any
156
+ self, name: str, func: Callable | None, description: str, **kwargs: Any
161
157
  ) -> None:
162
158
  """Initialize tool."""
163
159
  super().__init__(name=name, func=func, description=description, **kwargs)
@@ -165,14 +161,13 @@ class Tool(BaseTool):
165
161
  @classmethod
166
162
  def from_function(
167
163
  cls,
168
- func: Optional[Callable],
164
+ func: Callable | None,
169
165
  name: str, # We keep these required to support backwards compatibility
170
166
  description: str,
171
167
  return_direct: bool = False, # noqa: FBT001,FBT002
172
- args_schema: Optional[ArgsSchema] = None,
173
- coroutine: Optional[
174
- Callable[..., Awaitable[Any]]
175
- ] = None, # This is last for compatibility, but should be after func
168
+ args_schema: ArgsSchema | None = None,
169
+ coroutine: Callable[..., Awaitable[Any]]
170
+ | None = None, # This is last for compatibility, but should be after func
176
171
  **kwargs: Any,
177
172
  ) -> Tool:
178
173
  """Initialize tool from a function.
@@ -181,10 +176,10 @@ class Tool(BaseTool):
181
176
  func: The function to create the tool from.
182
177
  name: The name of the tool.
183
178
  description: The description of the tool.
184
- return_direct: Whether to return the output directly. Defaults to False.
185
- args_schema: The schema of the tool's input arguments. Defaults to None.
186
- coroutine: The asynchronous version of the function. Defaults to None.
187
- kwargs: Additional arguments to pass to the tool.
179
+ return_direct: Whether to return the output directly.
180
+ args_schema: The schema of the tool's input arguments.
181
+ coroutine: The asynchronous version of the function.
182
+ **kwargs: Additional arguments to pass to the tool.
188
183
 
189
184
  Returns:
190
185
  The tool.
@@ -3,16 +3,13 @@
3
3
  from __future__ import annotations
4
4
 
5
5
  import textwrap
6
- from collections.abc import Awaitable
6
+ from collections.abc import Awaitable, Callable
7
7
  from inspect import signature
8
8
  from typing import (
9
9
  TYPE_CHECKING,
10
10
  Annotated,
11
11
  Any,
12
- Callable,
13
12
  Literal,
14
- Optional,
15
- Union,
16
13
  )
17
14
 
18
15
  from pydantic import Field, SkipValidation
@@ -44,9 +41,9 @@ class StructuredTool(BaseTool):
44
41
  ..., description="The tool schema."
45
42
  )
46
43
  """The input arguments' schema."""
47
- func: Optional[Callable[..., Any]] = None
44
+ func: Callable[..., Any] | None = None
48
45
  """The function to run when the tool is called."""
49
- coroutine: Optional[Callable[..., Awaitable[Any]]] = None
46
+ coroutine: Callable[..., Awaitable[Any]] | None = None
50
47
  """The asynchronous version of the function."""
51
48
 
52
49
  # --- Runnable ---
@@ -55,8 +52,8 @@ class StructuredTool(BaseTool):
55
52
  @override
56
53
  async def ainvoke(
57
54
  self,
58
- input: Union[str, dict, ToolCall],
59
- config: Optional[RunnableConfig] = None,
55
+ input: str | dict | ToolCall,
56
+ config: RunnableConfig | None = None,
60
57
  **kwargs: Any,
61
58
  ) -> Any:
62
59
  if not self.coroutine:
@@ -71,7 +68,7 @@ class StructuredTool(BaseTool):
71
68
  self,
72
69
  *args: Any,
73
70
  config: RunnableConfig,
74
- run_manager: Optional[CallbackManagerForToolRun] = None,
71
+ run_manager: CallbackManagerForToolRun | None = None,
75
72
  **kwargs: Any,
76
73
  ) -> Any:
77
74
  """Use the tool.
@@ -98,7 +95,7 @@ class StructuredTool(BaseTool):
98
95
  self,
99
96
  *args: Any,
100
97
  config: RunnableConfig,
101
- run_manager: Optional[AsyncCallbackManagerForToolRun] = None,
98
+ run_manager: AsyncCallbackManagerForToolRun | None = None,
102
99
  **kwargs: Any,
103
100
  ) -> Any:
104
101
  """Use the tool asynchronously.
@@ -128,12 +125,12 @@ class StructuredTool(BaseTool):
128
125
  @classmethod
129
126
  def from_function(
130
127
  cls,
131
- func: Optional[Callable] = None,
132
- coroutine: Optional[Callable[..., Awaitable[Any]]] = None,
133
- name: Optional[str] = None,
134
- description: Optional[str] = None,
128
+ func: Callable | None = None,
129
+ coroutine: Callable[..., Awaitable[Any]] | None = None,
130
+ name: str | None = None,
131
+ description: str | None = None,
135
132
  return_direct: bool = False, # noqa: FBT001,FBT002
136
- args_schema: Optional[ArgsSchema] = None,
133
+ args_schema: ArgsSchema | None = None,
137
134
  infer_schema: bool = True, # noqa: FBT001,FBT002
138
135
  *,
139
136
  response_format: Literal["content", "content_and_artifact"] = "content",
@@ -152,22 +149,19 @@ class StructuredTool(BaseTool):
152
149
  description: The description of the tool.
153
150
  Defaults to the function docstring.
154
151
  return_direct: Whether to return the result directly or as a callback.
155
- Defaults to False.
156
- args_schema: The schema of the tool's input arguments. Defaults to None.
152
+ args_schema: The schema of the tool's input arguments.
157
153
  infer_schema: Whether to infer the schema from the function's signature.
158
- Defaults to True.
159
- response_format: The tool response format. If "content" then the output of
160
- the tool is interpreted as the contents of a ToolMessage. If
161
- "content_and_artifact" then the output is expected to be a two-tuple
162
- corresponding to the (content, artifact) of a ToolMessage.
163
- Defaults to "content".
164
- parse_docstring: if ``infer_schema`` and ``parse_docstring``, will attempt
154
+ response_format: The tool response format.
155
+
156
+ If `"content"` then the output of the tool is interpreted as the
157
+ contents of a `ToolMessage`. If `"content_and_artifact"` then the output
158
+ is expected to be a two-tuple corresponding to the `(content, artifact)`
159
+ of a `ToolMessage`.
160
+ parse_docstring: If `infer_schema` and `parse_docstring`, will attempt
165
161
  to parse parameter descriptions from Google Style function docstrings.
166
- Defaults to False.
167
- error_on_invalid_docstring: if ``parse_docstring`` is provided, configure
168
- whether to raise ValueError on invalid Google Style docstrings.
169
- Defaults to False.
170
- kwargs: Additional arguments to pass to the tool
162
+ error_on_invalid_docstring: if `parse_docstring` is provided, configure
163
+ whether to raise `ValueError` on invalid Google Style docstrings.
164
+ **kwargs: Additional arguments to pass to the tool
171
165
 
172
166
  Returns:
173
167
  The tool.
@@ -176,18 +170,17 @@ class StructuredTool(BaseTool):
176
170
  ValueError: If the function is not provided.
177
171
  ValueError: If the function does not have a docstring and description
178
172
  is not provided.
179
- TypeError: If the ``args_schema`` is not a ``BaseModel`` or dict.
173
+ TypeError: If the `args_schema` is not a `BaseModel` or dict.
180
174
 
181
175
  Examples:
182
-
183
- .. code-block:: python
184
-
185
- def add(a: int, b: int) -> int:
186
- \"\"\"Add two numbers\"\"\"
187
- return a + b
188
- tool = StructuredTool.from_function(add)
189
- tool.run(1, 2) # 3
190
-
176
+ ```python
177
+ def add(a: int, b: int) -> int:
178
+ \"\"\"Add two numbers\"\"\"
179
+ return a + b
180
+ tool = StructuredTool.from_function(add)
181
+ tool.run(1, 2) # 3
182
+
183
+ ```
191
184
  """
192
185
  if func is not None:
193
186
  source_function = func
@@ -1,12 +1,4 @@
1
- """**Tracers** are classes for tracing runs.
2
-
3
- **Class hierarchy:**
4
-
5
- .. code-block::
6
-
7
- BaseCallbackHandler --> BaseTracer --> <name>Tracer # Examples: LangChainTracer, RootListenersTracer
8
- --> <name> # Examples: LogStreamCallbackHandler
9
- """ # noqa: E501
1
+ """**Tracers** are classes for tracing runs."""
10
2
 
11
3
  from typing import TYPE_CHECKING
12
4