langchain-core 0.3.79__py3-none-any.whl → 1.0.0__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 (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 +52 -65
  5. langchain_core/_api/path.py +3 -6
  6. langchain_core/_import_utils.py +3 -4
  7. langchain_core/agents.py +19 -19
  8. langchain_core/caches.py +53 -63
  9. langchain_core/callbacks/__init__.py +1 -8
  10. langchain_core/callbacks/base.py +323 -334
  11. langchain_core/callbacks/file.py +44 -44
  12. langchain_core/callbacks/manager.py +441 -507
  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 +48 -63
  17. langchain_core/document_loaders/base.py +23 -23
  18. langchain_core/document_loaders/langsmith.py +37 -37
  19. langchain_core/documents/__init__.py +0 -1
  20. langchain_core/documents/base.py +62 -65
  21. langchain_core/documents/compressor.py +4 -4
  22. langchain_core/documents/transformers.py +28 -29
  23. langchain_core/embeddings/fake.py +50 -54
  24. langchain_core/example_selectors/length_based.py +1 -1
  25. langchain_core/example_selectors/semantic_similarity.py +21 -25
  26. langchain_core/exceptions.py +10 -11
  27. langchain_core/globals.py +3 -151
  28. langchain_core/indexing/api.py +61 -66
  29. langchain_core/indexing/base.py +58 -58
  30. langchain_core/indexing/in_memory.py +3 -3
  31. langchain_core/language_models/__init__.py +14 -27
  32. langchain_core/language_models/_utils.py +270 -84
  33. langchain_core/language_models/base.py +55 -162
  34. langchain_core/language_models/chat_models.py +442 -402
  35. langchain_core/language_models/fake.py +11 -11
  36. langchain_core/language_models/fake_chat_models.py +61 -39
  37. langchain_core/language_models/llms.py +123 -231
  38. langchain_core/load/dump.py +4 -5
  39. langchain_core/load/load.py +18 -28
  40. langchain_core/load/mapping.py +2 -4
  41. langchain_core/load/serializable.py +39 -40
  42. langchain_core/messages/__init__.py +61 -22
  43. langchain_core/messages/ai.py +368 -163
  44. langchain_core/messages/base.py +214 -43
  45. langchain_core/messages/block_translators/__init__.py +111 -0
  46. langchain_core/messages/block_translators/anthropic.py +470 -0
  47. langchain_core/messages/block_translators/bedrock.py +94 -0
  48. langchain_core/messages/block_translators/bedrock_converse.py +297 -0
  49. langchain_core/messages/block_translators/google_genai.py +530 -0
  50. langchain_core/messages/block_translators/google_vertexai.py +21 -0
  51. langchain_core/messages/block_translators/groq.py +143 -0
  52. langchain_core/messages/block_translators/langchain_v0.py +301 -0
  53. langchain_core/messages/block_translators/openai.py +1010 -0
  54. langchain_core/messages/chat.py +2 -6
  55. langchain_core/messages/content.py +1423 -0
  56. langchain_core/messages/function.py +6 -10
  57. langchain_core/messages/human.py +41 -38
  58. langchain_core/messages/modifier.py +2 -2
  59. langchain_core/messages/system.py +38 -28
  60. langchain_core/messages/tool.py +96 -103
  61. langchain_core/messages/utils.py +478 -504
  62. langchain_core/output_parsers/__init__.py +1 -14
  63. langchain_core/output_parsers/base.py +58 -61
  64. langchain_core/output_parsers/json.py +7 -8
  65. langchain_core/output_parsers/list.py +5 -7
  66. langchain_core/output_parsers/openai_functions.py +49 -47
  67. langchain_core/output_parsers/openai_tools.py +14 -19
  68. langchain_core/output_parsers/pydantic.py +12 -13
  69. langchain_core/output_parsers/string.py +2 -2
  70. langchain_core/output_parsers/transform.py +15 -17
  71. langchain_core/output_parsers/xml.py +8 -10
  72. langchain_core/outputs/__init__.py +1 -1
  73. langchain_core/outputs/chat_generation.py +18 -18
  74. langchain_core/outputs/chat_result.py +1 -3
  75. langchain_core/outputs/generation.py +8 -8
  76. langchain_core/outputs/llm_result.py +10 -10
  77. langchain_core/prompt_values.py +12 -12
  78. langchain_core/prompts/__init__.py +3 -27
  79. langchain_core/prompts/base.py +45 -55
  80. langchain_core/prompts/chat.py +254 -313
  81. langchain_core/prompts/dict.py +5 -5
  82. langchain_core/prompts/few_shot.py +81 -88
  83. langchain_core/prompts/few_shot_with_templates.py +11 -13
  84. langchain_core/prompts/image.py +12 -14
  85. langchain_core/prompts/loading.py +6 -8
  86. langchain_core/prompts/message.py +3 -3
  87. langchain_core/prompts/prompt.py +24 -39
  88. langchain_core/prompts/string.py +4 -4
  89. langchain_core/prompts/structured.py +42 -50
  90. langchain_core/rate_limiters.py +51 -60
  91. langchain_core/retrievers.py +49 -190
  92. langchain_core/runnables/base.py +1484 -1709
  93. langchain_core/runnables/branch.py +45 -61
  94. langchain_core/runnables/config.py +80 -88
  95. langchain_core/runnables/configurable.py +117 -134
  96. langchain_core/runnables/fallbacks.py +83 -79
  97. langchain_core/runnables/graph.py +85 -95
  98. langchain_core/runnables/graph_ascii.py +27 -28
  99. langchain_core/runnables/graph_mermaid.py +38 -50
  100. langchain_core/runnables/graph_png.py +15 -16
  101. langchain_core/runnables/history.py +135 -148
  102. langchain_core/runnables/passthrough.py +124 -150
  103. langchain_core/runnables/retry.py +46 -51
  104. langchain_core/runnables/router.py +25 -30
  105. langchain_core/runnables/schema.py +79 -74
  106. langchain_core/runnables/utils.py +62 -68
  107. langchain_core/stores.py +81 -115
  108. langchain_core/structured_query.py +8 -8
  109. langchain_core/sys_info.py +27 -29
  110. langchain_core/tools/__init__.py +1 -14
  111. langchain_core/tools/base.py +179 -187
  112. langchain_core/tools/convert.py +131 -139
  113. langchain_core/tools/render.py +10 -10
  114. langchain_core/tools/retriever.py +11 -11
  115. langchain_core/tools/simple.py +19 -24
  116. langchain_core/tools/structured.py +30 -39
  117. langchain_core/tracers/__init__.py +1 -9
  118. langchain_core/tracers/base.py +97 -99
  119. langchain_core/tracers/context.py +29 -52
  120. langchain_core/tracers/core.py +50 -60
  121. langchain_core/tracers/evaluation.py +11 -11
  122. langchain_core/tracers/event_stream.py +115 -70
  123. langchain_core/tracers/langchain.py +21 -21
  124. langchain_core/tracers/log_stream.py +43 -43
  125. langchain_core/tracers/memory_stream.py +3 -3
  126. langchain_core/tracers/root_listeners.py +16 -16
  127. langchain_core/tracers/run_collector.py +2 -4
  128. langchain_core/tracers/schemas.py +0 -129
  129. langchain_core/tracers/stdout.py +3 -3
  130. langchain_core/utils/__init__.py +1 -4
  131. langchain_core/utils/_merge.py +46 -8
  132. langchain_core/utils/aiter.py +57 -61
  133. langchain_core/utils/env.py +9 -9
  134. langchain_core/utils/function_calling.py +89 -191
  135. langchain_core/utils/html.py +7 -8
  136. langchain_core/utils/input.py +6 -6
  137. langchain_core/utils/interactive_env.py +1 -1
  138. langchain_core/utils/iter.py +37 -42
  139. langchain_core/utils/json.py +4 -3
  140. langchain_core/utils/json_schema.py +8 -8
  141. langchain_core/utils/mustache.py +9 -11
  142. langchain_core/utils/pydantic.py +33 -35
  143. langchain_core/utils/strings.py +5 -5
  144. langchain_core/utils/usage.py +1 -1
  145. langchain_core/utils/utils.py +80 -54
  146. langchain_core/vectorstores/base.py +129 -164
  147. langchain_core/vectorstores/in_memory.py +99 -174
  148. langchain_core/vectorstores/utils.py +5 -5
  149. langchain_core/version.py +1 -1
  150. {langchain_core-0.3.79.dist-info → langchain_core-1.0.0.dist-info}/METADATA +28 -27
  151. langchain_core-1.0.0.dist-info/RECORD +172 -0
  152. {langchain_core-0.3.79.dist-info → langchain_core-1.0.0.dist-info}/WHEEL +1 -1
  153. langchain_core/beta/__init__.py +0 -1
  154. langchain_core/beta/runnables/__init__.py +0 -1
  155. langchain_core/beta/runnables/context.py +0 -447
  156. langchain_core/memory.py +0 -120
  157. langchain_core/messages/content_blocks.py +0 -176
  158. langchain_core/prompts/pipeline.py +0 -138
  159. langchain_core/pydantic_v1/__init__.py +0 -30
  160. langchain_core/pydantic_v1/dataclasses.py +0 -23
  161. langchain_core/pydantic_v1/main.py +0 -23
  162. langchain_core/tracers/langchain_v1.py +0 -31
  163. langchain_core/utils/loading.py +0 -35
  164. langchain_core-0.3.79.dist-info/RECORD +0 -174
  165. langchain_core-0.3.79.dist-info/entry_points.txt +0 -4
@@ -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,17 @@ 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. If `"content"` then the output of
155
+ the tool is interpreted as the contents of a `ToolMessage`. If
156
+ `"content_and_artifact"` then the output is expected to be a two-tuple
157
+ corresponding to the `(content, artifact)` of a `ToolMessage`.
158
+ parse_docstring: if `infer_schema` and `parse_docstring`, will attempt
165
159
  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
160
+ error_on_invalid_docstring: if `parse_docstring` is provided, configure
161
+ whether to raise `ValueError` on invalid Google Style docstrings.
162
+ **kwargs: Additional arguments to pass to the tool
171
163
 
172
164
  Returns:
173
165
  The tool.
@@ -176,18 +168,17 @@ class StructuredTool(BaseTool):
176
168
  ValueError: If the function is not provided.
177
169
  ValueError: If the function does not have a docstring and description
178
170
  is not provided.
179
- TypeError: If the ``args_schema`` is not a ``BaseModel`` or dict.
171
+ TypeError: If the `args_schema` is not a `BaseModel` or dict.
180
172
 
181
173
  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
-
174
+ ```python
175
+ def add(a: int, b: int) -> int:
176
+ \"\"\"Add two numbers\"\"\"
177
+ return a + b
178
+ tool = StructuredTool.from_function(add)
179
+ tool.run(1, 2) # 3
180
+
181
+ ```
191
182
  """
192
183
  if func is not None:
193
184
  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
 
@@ -8,8 +8,6 @@ from abc import ABC, abstractmethod
8
8
  from typing import (
9
9
  TYPE_CHECKING,
10
10
  Any,
11
- Optional,
12
- Union,
13
11
  )
14
12
 
15
13
  from typing_extensions import override
@@ -57,10 +55,10 @@ class BaseTracer(_TracerCore, BaseCallbackHandler, ABC):
57
55
  messages: list[list[BaseMessage]],
58
56
  *,
59
57
  run_id: UUID,
60
- tags: Optional[list[str]] = None,
61
- parent_run_id: Optional[UUID] = None,
62
- metadata: Optional[dict[str, Any]] = None,
63
- name: Optional[str] = None,
58
+ tags: list[str] | None = None,
59
+ parent_run_id: UUID | None = None,
60
+ metadata: dict[str, Any] | None = None,
61
+ name: str | None = None,
64
62
  **kwargs: Any,
65
63
  ) -> Run:
66
64
  """Start a trace for an LLM run.
@@ -69,11 +67,11 @@ class BaseTracer(_TracerCore, BaseCallbackHandler, ABC):
69
67
  serialized: The serialized model.
70
68
  messages: The messages to start the chat with.
71
69
  run_id: The run ID.
72
- tags: The tags for the run. Defaults to None.
73
- parent_run_id: The parent run ID. Defaults to None.
74
- metadata: The metadata for the run. Defaults to None.
70
+ tags: The tags for the run.
71
+ parent_run_id: The parent run ID.
72
+ metadata: The metadata for the run.
75
73
  name: The name of the run.
76
- kwargs: Additional arguments.
74
+ **kwargs: Additional arguments.
77
75
 
78
76
  Returns:
79
77
  The run.
@@ -98,10 +96,10 @@ class BaseTracer(_TracerCore, BaseCallbackHandler, ABC):
98
96
  prompts: list[str],
99
97
  *,
100
98
  run_id: UUID,
101
- tags: Optional[list[str]] = None,
102
- parent_run_id: Optional[UUID] = None,
103
- metadata: Optional[dict[str, Any]] = None,
104
- name: Optional[str] = None,
99
+ tags: list[str] | None = None,
100
+ parent_run_id: UUID | None = None,
101
+ metadata: dict[str, Any] | None = None,
102
+ name: str | None = None,
105
103
  **kwargs: Any,
106
104
  ) -> Run:
107
105
  """Start a trace for an LLM run.
@@ -110,11 +108,11 @@ class BaseTracer(_TracerCore, BaseCallbackHandler, ABC):
110
108
  serialized: The serialized model.
111
109
  prompts: The prompts to start the LLM with.
112
110
  run_id: The run ID.
113
- tags: The tags for the run. Defaults to None.
114
- parent_run_id: The parent run ID. Defaults to None.
115
- metadata: The metadata for the run. Defaults to None.
111
+ tags: The tags for the run.
112
+ parent_run_id: The parent run ID.
113
+ metadata: The metadata for the run.
116
114
  name: The name of the run.
117
- kwargs: Additional arguments.
115
+ **kwargs: Additional arguments.
118
116
 
119
117
  Returns:
120
118
  The run.
@@ -138,19 +136,19 @@ class BaseTracer(_TracerCore, BaseCallbackHandler, ABC):
138
136
  self,
139
137
  token: str,
140
138
  *,
141
- chunk: Optional[Union[GenerationChunk, ChatGenerationChunk]] = None,
139
+ chunk: GenerationChunk | ChatGenerationChunk | None = None,
142
140
  run_id: UUID,
143
- parent_run_id: Optional[UUID] = None,
141
+ parent_run_id: UUID | None = None,
144
142
  **kwargs: Any,
145
143
  ) -> Run:
146
144
  """Run on new LLM token. Only available when streaming is enabled.
147
145
 
148
146
  Args:
149
147
  token: The token.
150
- chunk: The chunk. Defaults to None.
148
+ chunk: The chunk.
151
149
  run_id: The run ID.
152
- parent_run_id: The parent run ID. Defaults to None.
153
- kwargs: Additional arguments.
150
+ parent_run_id: The parent run ID.
151
+ **kwargs: Additional arguments.
154
152
 
155
153
  Returns:
156
154
  The run.
@@ -179,7 +177,7 @@ class BaseTracer(_TracerCore, BaseCallbackHandler, ABC):
179
177
  Args:
180
178
  retry_state: The retry state.
181
179
  run_id: The run ID.
182
- kwargs: Additional arguments.
180
+ **kwargs: Additional arguments.
183
181
 
184
182
  Returns:
185
183
  The run.
@@ -196,7 +194,7 @@ class BaseTracer(_TracerCore, BaseCallbackHandler, ABC):
196
194
  Args:
197
195
  response: The response.
198
196
  run_id: The run ID.
199
- kwargs: Additional arguments.
197
+ **kwargs: Additional arguments.
200
198
 
201
199
  Returns:
202
200
  The run.
@@ -223,7 +221,7 @@ class BaseTracer(_TracerCore, BaseCallbackHandler, ABC):
223
221
  Args:
224
222
  error: The error.
225
223
  run_id: The run ID.
226
- kwargs: Additional arguments.
224
+ **kwargs: Additional arguments.
227
225
 
228
226
  Returns:
229
227
  The run.
@@ -244,11 +242,11 @@ class BaseTracer(_TracerCore, BaseCallbackHandler, ABC):
244
242
  inputs: dict[str, Any],
245
243
  *,
246
244
  run_id: UUID,
247
- tags: Optional[list[str]] = None,
248
- parent_run_id: Optional[UUID] = None,
249
- metadata: Optional[dict[str, Any]] = None,
250
- run_type: Optional[str] = None,
251
- name: Optional[str] = None,
245
+ tags: list[str] | None = None,
246
+ parent_run_id: UUID | None = None,
247
+ metadata: dict[str, Any] | None = None,
248
+ run_type: str | None = None,
249
+ name: str | None = None,
252
250
  **kwargs: Any,
253
251
  ) -> Run:
254
252
  """Start a trace for a chain run.
@@ -257,12 +255,12 @@ class BaseTracer(_TracerCore, BaseCallbackHandler, ABC):
257
255
  serialized: The serialized chain.
258
256
  inputs: The inputs for the chain.
259
257
  run_id: The run ID.
260
- tags: The tags for the run. Defaults to None.
261
- parent_run_id: The parent run ID. Defaults to None.
262
- metadata: The metadata for the run. Defaults to None.
263
- run_type: The type of the run. Defaults to None.
258
+ tags: The tags for the run.
259
+ parent_run_id: The parent run ID.
260
+ metadata: The metadata for the run.
261
+ run_type: The type of the run.
264
262
  name: The name of the run.
265
- kwargs: Additional arguments.
263
+ **kwargs: Additional arguments.
266
264
 
267
265
  Returns:
268
266
  The run.
@@ -288,7 +286,7 @@ class BaseTracer(_TracerCore, BaseCallbackHandler, ABC):
288
286
  outputs: dict[str, Any],
289
287
  *,
290
288
  run_id: UUID,
291
- inputs: Optional[dict[str, Any]] = None,
289
+ inputs: dict[str, Any] | None = None,
292
290
  **kwargs: Any,
293
291
  ) -> Run:
294
292
  """End a trace for a chain run.
@@ -296,8 +294,8 @@ class BaseTracer(_TracerCore, BaseCallbackHandler, ABC):
296
294
  Args:
297
295
  outputs: The outputs for the chain.
298
296
  run_id: The run ID.
299
- inputs: The inputs for the chain. Defaults to None.
300
- kwargs: Additional arguments.
297
+ inputs: The inputs for the chain.
298
+ **kwargs: Additional arguments.
301
299
 
302
300
  Returns:
303
301
  The run.
@@ -316,7 +314,7 @@ class BaseTracer(_TracerCore, BaseCallbackHandler, ABC):
316
314
  self,
317
315
  error: BaseException,
318
316
  *,
319
- inputs: Optional[dict[str, Any]] = None,
317
+ inputs: dict[str, Any] | None = None,
320
318
  run_id: UUID,
321
319
  **kwargs: Any,
322
320
  ) -> Run:
@@ -324,9 +322,9 @@ class BaseTracer(_TracerCore, BaseCallbackHandler, ABC):
324
322
 
325
323
  Args:
326
324
  error: The error.
327
- inputs: The inputs for the chain. Defaults to None.
325
+ inputs: The inputs for the chain.
328
326
  run_id: The run ID.
329
- kwargs: Additional arguments.
327
+ **kwargs: Additional arguments.
330
328
 
331
329
  Returns:
332
330
  The run.
@@ -346,11 +344,11 @@ class BaseTracer(_TracerCore, BaseCallbackHandler, ABC):
346
344
  input_str: str,
347
345
  *,
348
346
  run_id: UUID,
349
- tags: Optional[list[str]] = None,
350
- parent_run_id: Optional[UUID] = None,
351
- metadata: Optional[dict[str, Any]] = None,
352
- name: Optional[str] = None,
353
- inputs: Optional[dict[str, Any]] = None,
347
+ tags: list[str] | None = None,
348
+ parent_run_id: UUID | None = None,
349
+ metadata: dict[str, Any] | None = None,
350
+ name: str | None = None,
351
+ inputs: dict[str, Any] | None = None,
354
352
  **kwargs: Any,
355
353
  ) -> Run:
356
354
  """Start a trace for a tool run.
@@ -359,12 +357,12 @@ class BaseTracer(_TracerCore, BaseCallbackHandler, ABC):
359
357
  serialized: The serialized tool.
360
358
  input_str: The input string.
361
359
  run_id: The run ID.
362
- tags: The tags for the run. Defaults to None.
363
- parent_run_id: The parent run ID. Defaults to None.
364
- metadata: The metadata for the run. Defaults to None.
360
+ tags: The tags for the run.
361
+ parent_run_id: The parent run ID.
362
+ metadata: The metadata for the run.
365
363
  name: The name of the run.
366
364
  inputs: The inputs for the tool.
367
- kwargs: Additional arguments.
365
+ **kwargs: Additional arguments.
368
366
 
369
367
  Returns:
370
368
  The run.
@@ -391,7 +389,7 @@ class BaseTracer(_TracerCore, BaseCallbackHandler, ABC):
391
389
  Args:
392
390
  output: The output for the tool.
393
391
  run_id: The run ID.
394
- kwargs: Additional arguments.
392
+ **kwargs: Additional arguments.
395
393
 
396
394
  Returns:
397
395
  The run.
@@ -417,7 +415,7 @@ class BaseTracer(_TracerCore, BaseCallbackHandler, ABC):
417
415
  Args:
418
416
  error: The error.
419
417
  run_id: The run ID.
420
- kwargs: Additional arguments.
418
+ **kwargs: Additional arguments.
421
419
 
422
420
  Returns:
423
421
  The run.
@@ -436,10 +434,10 @@ class BaseTracer(_TracerCore, BaseCallbackHandler, ABC):
436
434
  query: str,
437
435
  *,
438
436
  run_id: UUID,
439
- parent_run_id: Optional[UUID] = None,
440
- tags: Optional[list[str]] = None,
441
- metadata: Optional[dict[str, Any]] = None,
442
- name: Optional[str] = None,
437
+ parent_run_id: UUID | None = None,
438
+ tags: list[str] | None = None,
439
+ metadata: dict[str, Any] | None = None,
440
+ name: str | None = None,
443
441
  **kwargs: Any,
444
442
  ) -> Run:
445
443
  """Run when the Retriever starts running.
@@ -448,11 +446,11 @@ class BaseTracer(_TracerCore, BaseCallbackHandler, ABC):
448
446
  serialized: The serialized retriever.
449
447
  query: The query.
450
448
  run_id: The run ID.
451
- parent_run_id: The parent run ID. Defaults to None.
452
- tags: The tags for the run. Defaults to None.
453
- metadata: The metadata for the run. Defaults to None.
449
+ parent_run_id: The parent run ID.
450
+ tags: The tags for the run.
451
+ metadata: The metadata for the run.
454
452
  name: The name of the run.
455
- kwargs: Additional arguments.
453
+ **kwargs: Additional arguments.
456
454
 
457
455
  Returns:
458
456
  The run.
@@ -484,7 +482,7 @@ class BaseTracer(_TracerCore, BaseCallbackHandler, ABC):
484
482
  Args:
485
483
  error: The error.
486
484
  run_id: The run ID.
487
- kwargs: Additional arguments.
485
+ **kwargs: Additional arguments.
488
486
 
489
487
  Returns:
490
488
  The run.
@@ -506,7 +504,7 @@ class BaseTracer(_TracerCore, BaseCallbackHandler, ABC):
506
504
  Args:
507
505
  documents: The documents.
508
506
  run_id: The run ID.
509
- kwargs: Additional arguments.
507
+ **kwargs: Additional arguments.
510
508
 
511
509
  Returns:
512
510
  The run.
@@ -565,10 +563,10 @@ class AsyncBaseTracer(_TracerCore, AsyncCallbackHandler, ABC):
565
563
  messages: list[list[BaseMessage]],
566
564
  *,
567
565
  run_id: UUID,
568
- parent_run_id: Optional[UUID] = None,
569
- tags: Optional[list[str]] = None,
570
- metadata: Optional[dict[str, Any]] = None,
571
- name: Optional[str] = None,
566
+ parent_run_id: UUID | None = None,
567
+ tags: list[str] | None = None,
568
+ metadata: dict[str, Any] | None = None,
569
+ name: str | None = None,
572
570
  **kwargs: Any,
573
571
  ) -> Any:
574
572
  chat_model_run = self._create_chat_model_run(
@@ -595,9 +593,9 @@ class AsyncBaseTracer(_TracerCore, AsyncCallbackHandler, ABC):
595
593
  prompts: list[str],
596
594
  *,
597
595
  run_id: UUID,
598
- parent_run_id: Optional[UUID] = None,
599
- tags: Optional[list[str]] = None,
600
- metadata: Optional[dict[str, Any]] = None,
596
+ parent_run_id: UUID | None = None,
597
+ tags: list[str] | None = None,
598
+ metadata: dict[str, Any] | None = None,
601
599
  **kwargs: Any,
602
600
  ) -> None:
603
601
  llm_run = self._create_llm_run(
@@ -617,9 +615,9 @@ class AsyncBaseTracer(_TracerCore, AsyncCallbackHandler, ABC):
617
615
  self,
618
616
  token: str,
619
617
  *,
620
- chunk: Optional[Union[GenerationChunk, ChatGenerationChunk]] = None,
618
+ chunk: GenerationChunk | ChatGenerationChunk | None = None,
621
619
  run_id: UUID,
622
- parent_run_id: Optional[UUID] = None,
620
+ parent_run_id: UUID | None = None,
623
621
  **kwargs: Any,
624
622
  ) -> None:
625
623
  llm_run = self._llm_run_with_token_event(
@@ -649,8 +647,8 @@ class AsyncBaseTracer(_TracerCore, AsyncCallbackHandler, ABC):
649
647
  response: LLMResult,
650
648
  *,
651
649
  run_id: UUID,
652
- parent_run_id: Optional[UUID] = None,
653
- tags: Optional[list[str]] = None,
650
+ parent_run_id: UUID | None = None,
651
+ tags: list[str] | None = None,
654
652
  **kwargs: Any,
655
653
  ) -> None:
656
654
  llm_run = self._complete_llm_run(
@@ -666,8 +664,8 @@ class AsyncBaseTracer(_TracerCore, AsyncCallbackHandler, ABC):
666
664
  error: BaseException,
667
665
  *,
668
666
  run_id: UUID,
669
- parent_run_id: Optional[UUID] = None,
670
- tags: Optional[list[str]] = None,
667
+ parent_run_id: UUID | None = None,
668
+ tags: list[str] | None = None,
671
669
  **kwargs: Any,
672
670
  ) -> None:
673
671
  llm_run = self._errored_llm_run(
@@ -684,11 +682,11 @@ class AsyncBaseTracer(_TracerCore, AsyncCallbackHandler, ABC):
684
682
  inputs: dict[str, Any],
685
683
  *,
686
684
  run_id: UUID,
687
- tags: Optional[list[str]] = None,
688
- parent_run_id: Optional[UUID] = None,
689
- metadata: Optional[dict[str, Any]] = None,
690
- run_type: Optional[str] = None,
691
- name: Optional[str] = None,
685
+ tags: list[str] | None = None,
686
+ parent_run_id: UUID | None = None,
687
+ metadata: dict[str, Any] | None = None,
688
+ run_type: str | None = None,
689
+ name: str | None = None,
692
690
  **kwargs: Any,
693
691
  ) -> None:
694
692
  chain_run = self._create_chain_run(
@@ -711,7 +709,7 @@ class AsyncBaseTracer(_TracerCore, AsyncCallbackHandler, ABC):
711
709
  outputs: dict[str, Any],
712
710
  *,
713
711
  run_id: UUID,
714
- inputs: Optional[dict[str, Any]] = None,
712
+ inputs: dict[str, Any] | None = None,
715
713
  **kwargs: Any,
716
714
  ) -> None:
717
715
  chain_run = self._complete_chain_run(
@@ -727,7 +725,7 @@ class AsyncBaseTracer(_TracerCore, AsyncCallbackHandler, ABC):
727
725
  self,
728
726
  error: BaseException,
729
727
  *,
730
- inputs: Optional[dict[str, Any]] = None,
728
+ inputs: dict[str, Any] | None = None,
731
729
  run_id: UUID,
732
730
  **kwargs: Any,
733
731
  ) -> None:
@@ -746,11 +744,11 @@ class AsyncBaseTracer(_TracerCore, AsyncCallbackHandler, ABC):
746
744
  input_str: str,
747
745
  *,
748
746
  run_id: UUID,
749
- tags: Optional[list[str]] = None,
750
- parent_run_id: Optional[UUID] = None,
751
- metadata: Optional[dict[str, Any]] = None,
752
- name: Optional[str] = None,
753
- inputs: Optional[dict[str, Any]] = None,
747
+ tags: list[str] | None = None,
748
+ parent_run_id: UUID | None = None,
749
+ metadata: dict[str, Any] | None = None,
750
+ name: str | None = None,
751
+ inputs: dict[str, Any] | None = None,
754
752
  **kwargs: Any,
755
753
  ) -> None:
756
754
  tool_run = self._create_tool_run(
@@ -787,8 +785,8 @@ class AsyncBaseTracer(_TracerCore, AsyncCallbackHandler, ABC):
787
785
  error: BaseException,
788
786
  *,
789
787
  run_id: UUID,
790
- parent_run_id: Optional[UUID] = None,
791
- tags: Optional[list[str]] = None,
788
+ parent_run_id: UUID | None = None,
789
+ tags: list[str] | None = None,
792
790
  **kwargs: Any,
793
791
  ) -> None:
794
792
  tool_run = self._errored_tool_run(
@@ -805,10 +803,10 @@ class AsyncBaseTracer(_TracerCore, AsyncCallbackHandler, ABC):
805
803
  query: str,
806
804
  *,
807
805
  run_id: UUID,
808
- parent_run_id: Optional[UUID] = None,
809
- tags: Optional[list[str]] = None,
810
- metadata: Optional[dict[str, Any]] = None,
811
- name: Optional[str] = None,
806
+ parent_run_id: UUID | None = None,
807
+ tags: list[str] | None = None,
808
+ metadata: dict[str, Any] | None = None,
809
+ name: str | None = None,
812
810
  **kwargs: Any,
813
811
  ) -> None:
814
812
  retriever_run = self._create_retrieval_run(
@@ -832,8 +830,8 @@ class AsyncBaseTracer(_TracerCore, AsyncCallbackHandler, ABC):
832
830
  error: BaseException,
833
831
  *,
834
832
  run_id: UUID,
835
- parent_run_id: Optional[UUID] = None,
836
- tags: Optional[list[str]] = None,
833
+ parent_run_id: UUID | None = None,
834
+ tags: list[str] | None = None,
837
835
  **kwargs: Any,
838
836
  ) -> None:
839
837
  retrieval_run = self._errored_retrieval_run(
@@ -852,8 +850,8 @@ class AsyncBaseTracer(_TracerCore, AsyncCallbackHandler, ABC):
852
850
  documents: Sequence[Document],
853
851
  *,
854
852
  run_id: UUID,
855
- parent_run_id: Optional[UUID] = None,
856
- tags: Optional[list[str]] = None,
853
+ parent_run_id: UUID | None = None,
854
+ tags: list[str] | None = None,
857
855
  **kwargs: Any,
858
856
  ) -> None:
859
857
  retrieval_run = self._complete_retrieval_run(
@@ -882,7 +880,7 @@ class AsyncBaseTracer(_TracerCore, AsyncCallbackHandler, ABC):
882
880
  self,
883
881
  run: Run,
884
882
  token: str,
885
- chunk: Optional[Union[GenerationChunk, ChatGenerationChunk]],
883
+ chunk: GenerationChunk | ChatGenerationChunk | None,
886
884
  ) -> None:
887
885
  """Process new LLM token."""
888
886