langchain-core 1.0.0a7__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 +76 -55
  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.0a7.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.0a7.dist-info/RECORD +0 -176
  135. {langchain_core-1.0.0a7.dist-info → langchain_core-1.0.0rc1.dist-info}/WHEEL +0 -0
@@ -35,10 +35,10 @@ class RetrieverManagerMixin:
35
35
  """Run when Retriever errors.
36
36
 
37
37
  Args:
38
- error (BaseException): The error that occurred.
39
- run_id (UUID): The run ID. This is the ID of the current run.
40
- parent_run_id (UUID): The parent run ID. This is the ID of the parent run.
41
- kwargs (Any): Additional keyword arguments.
38
+ error: The error that occurred.
39
+ run_id: The run ID. This is the ID of the current run.
40
+ parent_run_id: The parent run ID. This is the ID of the parent run.
41
+ **kwargs: Additional keyword arguments.
42
42
  """
43
43
 
44
44
  def on_retriever_end(
@@ -52,10 +52,10 @@ class RetrieverManagerMixin:
52
52
  """Run when Retriever ends running.
53
53
 
54
54
  Args:
55
- documents (Sequence[Document]): The documents retrieved.
56
- run_id (UUID): The run ID. This is the ID of the current run.
57
- parent_run_id (UUID): The parent run ID. This is the ID of the parent run.
58
- kwargs (Any): Additional keyword arguments.
55
+ documents: The documents retrieved.
56
+ run_id: The run ID. This is the ID of the current run.
57
+ parent_run_id: The parent run ID. This is the ID of the parent run.
58
+ **kwargs: Additional keyword arguments.
59
59
  """
60
60
 
61
61
 
@@ -76,12 +76,11 @@ class LLMManagerMixin:
76
76
  For both chat models and non-chat models (legacy LLMs).
77
77
 
78
78
  Args:
79
- token (str): The new token.
80
- chunk (GenerationChunk | ChatGenerationChunk): The new generated chunk,
81
- containing content and other information.
82
- run_id (UUID): The run ID. This is the ID of the current run.
83
- parent_run_id (UUID): The parent run ID. This is the ID of the parent run.
84
- kwargs (Any): Additional keyword arguments.
79
+ token: The new token.
80
+ chunk: The new generated chunk, containing content and other information.
81
+ run_id: The run ID. This is the ID of the current run.
82
+ parent_run_id: The parent run ID. This is the ID of the parent run.
83
+ **kwargs: Additional keyword arguments.
85
84
  """
86
85
 
87
86
  def on_llm_end(
@@ -95,10 +94,10 @@ class LLMManagerMixin:
95
94
  """Run when LLM ends running.
96
95
 
97
96
  Args:
98
- response (LLMResult): The response which was generated.
99
- run_id (UUID): The run ID. This is the ID of the current run.
100
- parent_run_id (UUID): The parent run ID. This is the ID of the parent run.
101
- kwargs (Any): Additional keyword arguments.
97
+ response: The response which was generated.
98
+ run_id: The run ID. This is the ID of the current run.
99
+ parent_run_id: The parent run ID. This is the ID of the parent run.
100
+ **kwargs: Additional keyword arguments.
102
101
  """
103
102
 
104
103
  def on_llm_error(
@@ -112,10 +111,10 @@ class LLMManagerMixin:
112
111
  """Run when LLM errors.
113
112
 
114
113
  Args:
115
- error (BaseException): The error that occurred.
116
- run_id (UUID): The run ID. This is the ID of the current run.
117
- parent_run_id (UUID): The parent run ID. This is the ID of the parent run.
118
- kwargs (Any): Additional keyword arguments.
114
+ error: The error that occurred.
115
+ run_id: The run ID. This is the ID of the current run.
116
+ parent_run_id: The parent run ID. This is the ID of the parent run.
117
+ **kwargs: Additional keyword arguments.
119
118
  """
120
119
 
121
120
 
@@ -133,10 +132,10 @@ class ChainManagerMixin:
133
132
  """Run when chain ends running.
134
133
 
135
134
  Args:
136
- outputs (dict[str, Any]): The outputs of the chain.
137
- run_id (UUID): The run ID. This is the ID of the current run.
138
- parent_run_id (UUID): The parent run ID. This is the ID of the parent run.
139
- kwargs (Any): Additional keyword arguments.
135
+ outputs: The outputs of the chain.
136
+ run_id: The run ID. This is the ID of the current run.
137
+ parent_run_id: The parent run ID. This is the ID of the parent run.
138
+ **kwargs: Additional keyword arguments.
140
139
  """
141
140
 
142
141
  def on_chain_error(
@@ -150,10 +149,10 @@ class ChainManagerMixin:
150
149
  """Run when chain errors.
151
150
 
152
151
  Args:
153
- error (BaseException): The error that occurred.
154
- run_id (UUID): The run ID. This is the ID of the current run.
155
- parent_run_id (UUID): The parent run ID. This is the ID of the parent run.
156
- kwargs (Any): Additional keyword arguments.
152
+ error: The error that occurred.
153
+ run_id: The run ID. This is the ID of the current run.
154
+ parent_run_id: The parent run ID. This is the ID of the parent run.
155
+ **kwargs: Additional keyword arguments.
157
156
  """
158
157
 
159
158
  def on_agent_action(
@@ -167,10 +166,10 @@ class ChainManagerMixin:
167
166
  """Run on agent action.
168
167
 
169
168
  Args:
170
- action (AgentAction): The agent action.
171
- run_id (UUID): The run ID. This is the ID of the current run.
172
- parent_run_id (UUID): The parent run ID. This is the ID of the parent run.
173
- kwargs (Any): Additional keyword arguments.
169
+ action: The agent action.
170
+ run_id: The run ID. This is the ID of the current run.
171
+ parent_run_id: The parent run ID. This is the ID of the parent run.
172
+ **kwargs: Additional keyword arguments.
174
173
  """
175
174
 
176
175
  def on_agent_finish(
@@ -184,10 +183,10 @@ class ChainManagerMixin:
184
183
  """Run on the agent end.
185
184
 
186
185
  Args:
187
- finish (AgentFinish): The agent finish.
188
- run_id (UUID): The run ID. This is the ID of the current run.
189
- parent_run_id (UUID): The parent run ID. This is the ID of the parent run.
190
- kwargs (Any): Additional keyword arguments.
186
+ finish: The agent finish.
187
+ run_id: The run ID. This is the ID of the current run.
188
+ parent_run_id: The parent run ID. This is the ID of the parent run.
189
+ **kwargs: Additional keyword arguments.
191
190
  """
192
191
 
193
192
 
@@ -205,10 +204,10 @@ class ToolManagerMixin:
205
204
  """Run when the tool ends running.
206
205
 
207
206
  Args:
208
- output (Any): The output of the tool.
209
- run_id (UUID): The run ID. This is the ID of the current run.
210
- parent_run_id (UUID): The parent run ID. This is the ID of the parent run.
211
- kwargs (Any): Additional keyword arguments.
207
+ output: The output of the tool.
208
+ run_id: The run ID. This is the ID of the current run.
209
+ parent_run_id: The parent run ID. This is the ID of the parent run.
210
+ **kwargs: Additional keyword arguments.
212
211
  """
213
212
 
214
213
  def on_tool_error(
@@ -222,10 +221,10 @@ class ToolManagerMixin:
222
221
  """Run when tool errors.
223
222
 
224
223
  Args:
225
- error (BaseException): The error that occurred.
226
- run_id (UUID): The run ID. This is the ID of the current run.
227
- parent_run_id (UUID): The parent run ID. This is the ID of the parent run.
228
- kwargs (Any): Additional keyword arguments.
224
+ error: The error that occurred.
225
+ run_id: The run ID. This is the ID of the current run.
226
+ parent_run_id: The parent run ID. This is the ID of the parent run.
227
+ **kwargs: Additional keyword arguments.
229
228
  """
230
229
 
231
230
 
@@ -248,16 +247,16 @@ class CallbackManagerMixin:
248
247
  !!! warning
249
248
  This method is called for non-chat models (regular LLMs). If you're
250
249
  implementing a handler for a chat model, you should use
251
- ``on_chat_model_start`` instead.
250
+ `on_chat_model_start` instead.
252
251
 
253
252
  Args:
254
- serialized (dict[str, Any]): The serialized LLM.
255
- prompts (list[str]): The prompts.
256
- run_id (UUID): The run ID. This is the ID of the current run.
257
- parent_run_id (UUID): The parent run ID. This is the ID of the parent run.
258
- tags (Optional[list[str]]): The tags.
259
- metadata (Optional[dict[str, Any]]): The metadata.
260
- kwargs (Any): Additional keyword arguments.
253
+ serialized: The serialized LLM.
254
+ prompts: The prompts.
255
+ run_id: The run ID. This is the ID of the current run.
256
+ parent_run_id: The parent run ID. This is the ID of the parent run.
257
+ tags: The tags.
258
+ metadata: The metadata.
259
+ **kwargs: Additional keyword arguments.
261
260
  """
262
261
 
263
262
  def on_chat_model_start(
@@ -275,16 +274,16 @@ class CallbackManagerMixin:
275
274
 
276
275
  !!! warning
277
276
  This method is called for chat models. If you're implementing a handler for
278
- a non-chat model, you should use ``on_llm_start`` instead.
277
+ a non-chat model, you should use `on_llm_start` instead.
279
278
 
280
279
  Args:
281
- serialized (dict[str, Any]): The serialized chat model.
282
- messages (list[list[BaseMessage]]): The messages.
283
- run_id (UUID): The run ID. This is the ID of the current run.
284
- parent_run_id (UUID): The parent run ID. This is the ID of the parent run.
285
- tags (Optional[list[str]]): The tags.
286
- metadata (Optional[dict[str, Any]]): The metadata.
287
- kwargs (Any): Additional keyword arguments.
280
+ serialized: The serialized chat model.
281
+ messages: The messages.
282
+ run_id: The run ID. This is the ID of the current run.
283
+ parent_run_id: The parent run ID. This is the ID of the parent run.
284
+ tags: The tags.
285
+ metadata: The metadata.
286
+ **kwargs: Additional keyword arguments.
288
287
  """
289
288
  # NotImplementedError is thrown intentionally
290
289
  # Callback handler will fall back to on_llm_start if this is exception is thrown
@@ -305,13 +304,13 @@ class CallbackManagerMixin:
305
304
  """Run when the Retriever starts running.
306
305
 
307
306
  Args:
308
- serialized (dict[str, Any]): The serialized Retriever.
309
- query (str): The query.
310
- run_id (UUID): The run ID. This is the ID of the current run.
311
- parent_run_id (UUID): The parent run ID. This is the ID of the parent run.
312
- tags (Optional[list[str]]): The tags.
313
- metadata (Optional[dict[str, Any]]): The metadata.
314
- kwargs (Any): Additional keyword arguments.
307
+ serialized: The serialized Retriever.
308
+ query: The query.
309
+ run_id: The run ID. This is the ID of the current run.
310
+ parent_run_id: The parent run ID. This is the ID of the parent run.
311
+ tags: The tags.
312
+ metadata: The metadata.
313
+ **kwargs: Additional keyword arguments.
315
314
  """
316
315
 
317
316
  def on_chain_start(
@@ -328,13 +327,13 @@ class CallbackManagerMixin:
328
327
  """Run when a chain starts running.
329
328
 
330
329
  Args:
331
- serialized (dict[str, Any]): The serialized chain.
332
- inputs (dict[str, Any]): The inputs.
333
- run_id (UUID): The run ID. This is the ID of the current run.
334
- parent_run_id (UUID): The parent run ID. This is the ID of the parent run.
335
- tags (Optional[list[str]]): The tags.
336
- metadata (Optional[dict[str, Any]]): The metadata.
337
- kwargs (Any): Additional keyword arguments.
330
+ serialized: The serialized chain.
331
+ inputs: The inputs.
332
+ run_id: The run ID. This is the ID of the current run.
333
+ parent_run_id: The parent run ID. This is the ID of the parent run.
334
+ tags: The tags.
335
+ metadata: The metadata.
336
+ **kwargs: Additional keyword arguments.
338
337
  """
339
338
 
340
339
  def on_tool_start(
@@ -352,14 +351,14 @@ class CallbackManagerMixin:
352
351
  """Run when the tool starts running.
353
352
 
354
353
  Args:
355
- serialized (dict[str, Any]): The serialized tool.
356
- input_str (str): The input string.
357
- run_id (UUID): The run ID. This is the ID of the current run.
358
- parent_run_id (UUID): The parent run ID. This is the ID of the parent run.
359
- tags (Optional[list[str]]): The tags.
360
- metadata (Optional[dict[str, Any]]): The metadata.
361
- inputs (Optional[dict[str, Any]]): The inputs.
362
- kwargs (Any): Additional keyword arguments.
354
+ serialized: The serialized chain.
355
+ input_str: The input string.
356
+ run_id: The run ID. This is the ID of the current run.
357
+ parent_run_id: The parent run ID. This is the ID of the parent run.
358
+ tags: The tags.
359
+ metadata: The metadata.
360
+ inputs: The inputs.
361
+ **kwargs: Additional keyword arguments.
363
362
  """
364
363
 
365
364
 
@@ -377,10 +376,10 @@ class RunManagerMixin:
377
376
  """Run on an arbitrary text.
378
377
 
379
378
  Args:
380
- text (str): The text.
381
- run_id (UUID): The run ID. This is the ID of the current run.
382
- parent_run_id (UUID): The parent run ID. This is the ID of the parent run.
383
- kwargs (Any): Additional keyword arguments.
379
+ text: The text.
380
+ run_id: The run ID. This is the ID of the current run.
381
+ parent_run_id: The parent run ID. This is the ID of the parent run.
382
+ **kwargs: Additional keyword arguments.
384
383
  """
385
384
 
386
385
  def on_retry(
@@ -394,10 +393,10 @@ class RunManagerMixin:
394
393
  """Run on a retry event.
395
394
 
396
395
  Args:
397
- retry_state (RetryCallState): The retry state.
398
- run_id (UUID): The run ID. This is the ID of the current run.
399
- parent_run_id (UUID): The parent run ID. This is the ID of the parent run.
400
- kwargs (Any): Additional keyword arguments.
396
+ retry_state: The retry state.
397
+ run_id: The run ID. This is the ID of the current run.
398
+ parent_run_id: The parent run ID. This is the ID of the parent run.
399
+ **kwargs: Additional keyword arguments.
401
400
  """
402
401
 
403
402
  def on_custom_event(
@@ -415,7 +414,7 @@ class RunManagerMixin:
415
414
  Args:
416
415
  name: The name of the custom event.
417
416
  data: The data for the custom event. Format will match
418
- the format specified by the user.
417
+ the format specified by the user.
419
418
  run_id: The ID of the run.
420
419
  tags: The tags associated with the custom event
421
420
  (includes inherited tags).
@@ -497,16 +496,16 @@ class AsyncCallbackHandler(BaseCallbackHandler):
497
496
  !!! warning
498
497
  This method is called for non-chat models (regular LLMs). If you're
499
498
  implementing a handler for a chat model, you should use
500
- ``on_chat_model_start`` instead.
499
+ `on_chat_model_start` instead.
501
500
 
502
501
  Args:
503
- serialized (dict[str, Any]): The serialized LLM.
504
- prompts (list[str]): The prompts.
505
- run_id (UUID): The run ID. This is the ID of the current run.
506
- parent_run_id (UUID): The parent run ID. This is the ID of the parent run.
507
- tags (Optional[list[str]]): The tags.
508
- metadata (Optional[dict[str, Any]]): The metadata.
509
- kwargs (Any): Additional keyword arguments.
502
+ serialized: The serialized LLM.
503
+ prompts: The prompts.
504
+ run_id: The run ID. This is the ID of the current run.
505
+ parent_run_id: The parent run ID. This is the ID of the parent run.
506
+ tags: The tags.
507
+ metadata: The metadata.
508
+ **kwargs: Additional keyword arguments.
510
509
  """
511
510
 
512
511
  async def on_chat_model_start(
@@ -524,16 +523,16 @@ class AsyncCallbackHandler(BaseCallbackHandler):
524
523
 
525
524
  !!! warning
526
525
  This method is called for chat models. If you're implementing a handler for
527
- a non-chat model, you should use ``on_llm_start`` instead.
526
+ a non-chat model, you should use `on_llm_start` instead.
528
527
 
529
528
  Args:
530
- serialized (dict[str, Any]): The serialized chat model.
531
- messages (list[list[BaseMessage]]): The messages.
532
- run_id (UUID): The run ID. This is the ID of the current run.
533
- parent_run_id (UUID): The parent run ID. This is the ID of the parent run.
534
- tags (Optional[list[str]]): The tags.
535
- metadata (Optional[dict[str, Any]]): The metadata.
536
- kwargs (Any): Additional keyword arguments.
529
+ serialized: The serialized chat model.
530
+ messages: The messages.
531
+ run_id: The run ID. This is the ID of the current run.
532
+ parent_run_id: The parent run ID. This is the ID of the parent run.
533
+ tags: The tags.
534
+ metadata: The metadata.
535
+ **kwargs: Additional keyword arguments.
537
536
  """
538
537
  # NotImplementedError is thrown intentionally
539
538
  # Callback handler will fall back to on_llm_start if this is exception is thrown
@@ -555,13 +554,12 @@ class AsyncCallbackHandler(BaseCallbackHandler):
555
554
  For both chat models and non-chat models (legacy LLMs).
556
555
 
557
556
  Args:
558
- token (str): The new token.
559
- chunk (GenerationChunk | ChatGenerationChunk): The new generated chunk,
560
- containing content and other information.
561
- run_id (UUID): The run ID. This is the ID of the current run.
562
- parent_run_id (UUID): The parent run ID. This is the ID of the parent run.
563
- tags (Optional[list[str]]): The tags.
564
- kwargs (Any): Additional keyword arguments.
557
+ token: The new token.
558
+ chunk: The new generated chunk, containing content and other information.
559
+ run_id: The run ID. This is the ID of the current run.
560
+ parent_run_id: The parent run ID. This is the ID of the parent run.
561
+ tags: The tags.
562
+ **kwargs: Additional keyword arguments.
565
563
  """
566
564
 
567
565
  async def on_llm_end(
@@ -576,11 +574,11 @@ class AsyncCallbackHandler(BaseCallbackHandler):
576
574
  """Run when the model ends running.
577
575
 
578
576
  Args:
579
- response (LLMResult): The response which was generated.
580
- run_id (UUID): The run ID. This is the ID of the current run.
581
- parent_run_id (UUID): The parent run ID. This is the ID of the parent run.
582
- tags (Optional[list[str]]): The tags.
583
- kwargs (Any): Additional keyword arguments.
577
+ response: The response which was generated.
578
+ run_id: The run ID. This is the ID of the current run.
579
+ parent_run_id: The parent run ID. This is the ID of the parent run.
580
+ tags: The tags.
581
+ **kwargs: Additional keyword arguments.
584
582
  """
585
583
 
586
584
  async def on_llm_error(
@@ -599,7 +597,7 @@ class AsyncCallbackHandler(BaseCallbackHandler):
599
597
  run_id: The run ID. This is the ID of the current run.
600
598
  parent_run_id: The parent run ID. This is the ID of the parent run.
601
599
  tags: The tags.
602
- kwargs (Any): Additional keyword arguments.
600
+ **kwargs: Additional keyword arguments.
603
601
  - response (LLMResult): The response which was generated before
604
602
  the error occurred.
605
603
  """
@@ -618,13 +616,13 @@ class AsyncCallbackHandler(BaseCallbackHandler):
618
616
  """Run when a chain starts running.
619
617
 
620
618
  Args:
621
- serialized (dict[str, Any]): The serialized chain.
622
- inputs (dict[str, Any]): The inputs.
623
- run_id (UUID): The run ID. This is the ID of the current run.
624
- parent_run_id (UUID): The parent run ID. This is the ID of the parent run.
625
- tags (Optional[list[str]]): The tags.
626
- metadata (Optional[dict[str, Any]]): The metadata.
627
- kwargs (Any): Additional keyword arguments.
619
+ serialized: The serialized chain.
620
+ inputs: The inputs.
621
+ run_id: The run ID. This is the ID of the current run.
622
+ parent_run_id: The parent run ID. This is the ID of the parent run.
623
+ tags: The tags.
624
+ metadata: The metadata.
625
+ **kwargs: Additional keyword arguments.
628
626
  """
629
627
 
630
628
  async def on_chain_end(
@@ -639,11 +637,11 @@ class AsyncCallbackHandler(BaseCallbackHandler):
639
637
  """Run when a chain ends running.
640
638
 
641
639
  Args:
642
- outputs (dict[str, Any]): The outputs of the chain.
643
- run_id (UUID): The run ID. This is the ID of the current run.
644
- parent_run_id (UUID): The parent run ID. This is the ID of the parent run.
645
- tags (Optional[list[str]]): The tags.
646
- kwargs (Any): Additional keyword arguments.
640
+ outputs: The outputs of the chain.
641
+ run_id: The run ID. This is the ID of the current run.
642
+ parent_run_id: The parent run ID. This is the ID of the parent run.
643
+ tags: The tags.
644
+ **kwargs: Additional keyword arguments.
647
645
  """
648
646
 
649
647
  async def on_chain_error(
@@ -658,11 +656,11 @@ class AsyncCallbackHandler(BaseCallbackHandler):
658
656
  """Run when chain errors.
659
657
 
660
658
  Args:
661
- error (BaseException): The error that occurred.
662
- run_id (UUID): The run ID. This is the ID of the current run.
663
- parent_run_id (UUID): The parent run ID. This is the ID of the parent run.
664
- tags (Optional[list[str]]): The tags.
665
- kwargs (Any): Additional keyword arguments.
659
+ error: The error that occurred.
660
+ run_id: The run ID. This is the ID of the current run.
661
+ parent_run_id: The parent run ID. This is the ID of the parent run.
662
+ tags: The tags.
663
+ **kwargs: Additional keyword arguments.
666
664
  """
667
665
 
668
666
  async def on_tool_start(
@@ -680,14 +678,14 @@ class AsyncCallbackHandler(BaseCallbackHandler):
680
678
  """Run when the tool starts running.
681
679
 
682
680
  Args:
683
- serialized (dict[str, Any]): The serialized tool.
684
- input_str (str): The input string.
685
- run_id (UUID): The run ID. This is the ID of the current run.
686
- parent_run_id (UUID): The parent run ID. This is the ID of the parent run.
687
- tags (Optional[list[str]]): The tags.
688
- metadata (Optional[dict[str, Any]]): The metadata.
689
- inputs (Optional[dict[str, Any]]): The inputs.
690
- kwargs (Any): Additional keyword arguments.
681
+ serialized: The serialized tool.
682
+ input_str: The input string.
683
+ run_id: The run ID. This is the ID of the current run.
684
+ parent_run_id: The parent run ID. This is the ID of the parent run.
685
+ tags: The tags.
686
+ metadata: The metadata.
687
+ inputs: The inputs.
688
+ **kwargs: Additional keyword arguments.
691
689
  """
692
690
 
693
691
  async def on_tool_end(
@@ -702,11 +700,11 @@ class AsyncCallbackHandler(BaseCallbackHandler):
702
700
  """Run when the tool ends running.
703
701
 
704
702
  Args:
705
- output (Any): The output of the tool.
706
- run_id (UUID): The run ID. This is the ID of the current run.
707
- parent_run_id (UUID): The parent run ID. This is the ID of the parent run.
708
- tags (Optional[list[str]]): The tags.
709
- kwargs (Any): Additional keyword arguments.
703
+ output: The output of the tool.
704
+ run_id: The run ID. This is the ID of the current run.
705
+ parent_run_id: The parent run ID. This is the ID of the parent run.
706
+ tags: The tags.
707
+ **kwargs: Additional keyword arguments.
710
708
  """
711
709
 
712
710
  async def on_tool_error(
@@ -721,11 +719,11 @@ class AsyncCallbackHandler(BaseCallbackHandler):
721
719
  """Run when tool errors.
722
720
 
723
721
  Args:
724
- error (BaseException): The error that occurred.
725
- run_id (UUID): The run ID. This is the ID of the current run.
726
- parent_run_id (UUID): The parent run ID. This is the ID of the parent run.
727
- tags (Optional[list[str]]): The tags.
728
- kwargs (Any): Additional keyword arguments.
722
+ error: The error that occurred.
723
+ run_id: The run ID. This is the ID of the current run.
724
+ parent_run_id: The parent run ID. This is the ID of the parent run.
725
+ tags: The tags.
726
+ **kwargs: Additional keyword arguments.
729
727
  """
730
728
 
731
729
  async def on_text(
@@ -740,11 +738,11 @@ class AsyncCallbackHandler(BaseCallbackHandler):
740
738
  """Run on an arbitrary text.
741
739
 
742
740
  Args:
743
- text (str): The text.
744
- run_id (UUID): The run ID. This is the ID of the current run.
745
- parent_run_id (UUID): The parent run ID. This is the ID of the parent run.
746
- tags (Optional[list[str]]): The tags.
747
- kwargs (Any): Additional keyword arguments.
741
+ text: The text.
742
+ run_id: The run ID. This is the ID of the current run.
743
+ parent_run_id: The parent run ID. This is the ID of the parent run.
744
+ tags: The tags.
745
+ **kwargs: Additional keyword arguments.
748
746
  """
749
747
 
750
748
  async def on_retry(
@@ -758,10 +756,10 @@ class AsyncCallbackHandler(BaseCallbackHandler):
758
756
  """Run on a retry event.
759
757
 
760
758
  Args:
761
- retry_state (RetryCallState): The retry state.
762
- run_id (UUID): The run ID. This is the ID of the current run.
763
- parent_run_id (UUID): The parent run ID. This is the ID of the parent run.
764
- kwargs (Any): Additional keyword arguments.
759
+ retry_state: The retry state.
760
+ run_id: The run ID. This is the ID of the current run.
761
+ parent_run_id: The parent run ID. This is the ID of the parent run.
762
+ **kwargs: Additional keyword arguments.
765
763
  """
766
764
 
767
765
  async def on_agent_action(
@@ -776,11 +774,11 @@ class AsyncCallbackHandler(BaseCallbackHandler):
776
774
  """Run on agent action.
777
775
 
778
776
  Args:
779
- action (AgentAction): The agent action.
780
- run_id (UUID): The run ID. This is the ID of the current run.
781
- parent_run_id (UUID): The parent run ID. This is the ID of the parent run.
782
- tags (Optional[list[str]]): The tags.
783
- kwargs (Any): Additional keyword arguments.
777
+ action: The agent action.
778
+ run_id: The run ID. This is the ID of the current run.
779
+ parent_run_id: The parent run ID. This is the ID of the parent run.
780
+ tags: The tags.
781
+ **kwargs: Additional keyword arguments.
784
782
  """
785
783
 
786
784
  async def on_agent_finish(
@@ -795,11 +793,11 @@ class AsyncCallbackHandler(BaseCallbackHandler):
795
793
  """Run on the agent end.
796
794
 
797
795
  Args:
798
- finish (AgentFinish): The agent finish.
799
- run_id (UUID): The run ID. This is the ID of the current run.
800
- parent_run_id (UUID): The parent run ID. This is the ID of the parent run.
801
- tags (Optional[list[str]]): The tags.
802
- kwargs (Any): Additional keyword arguments.
796
+ finish: The agent finish.
797
+ run_id: The run ID. This is the ID of the current run.
798
+ parent_run_id: The parent run ID. This is the ID of the parent run.
799
+ tags: The tags.
800
+ **kwargs: Additional keyword arguments.
803
801
  """
804
802
 
805
803
  async def on_retriever_start(
@@ -816,13 +814,13 @@ class AsyncCallbackHandler(BaseCallbackHandler):
816
814
  """Run on the retriever start.
817
815
 
818
816
  Args:
819
- serialized (dict[str, Any]): The serialized retriever.
820
- query (str): The query.
821
- run_id (UUID): The run ID. This is the ID of the current run.
822
- parent_run_id (UUID): The parent run ID. This is the ID of the parent run.
823
- tags (Optional[list[str]]): The tags.
824
- metadata (Optional[dict[str, Any]]): The metadata.
825
- kwargs (Any): Additional keyword arguments.
817
+ serialized: The serialized retriever.
818
+ query: The query.
819
+ run_id: The run ID. This is the ID of the current run.
820
+ parent_run_id: The parent run ID. This is the ID of the parent run.
821
+ tags: The tags.
822
+ metadata: The metadata.
823
+ **kwargs: Additional keyword arguments.
826
824
  """
827
825
 
828
826
  async def on_retriever_end(
@@ -837,11 +835,11 @@ class AsyncCallbackHandler(BaseCallbackHandler):
837
835
  """Run on the retriever end.
838
836
 
839
837
  Args:
840
- documents (Sequence[Document]): The documents retrieved.
841
- run_id (UUID): The run ID. This is the ID of the current run.
842
- parent_run_id (UUID): The parent run ID. This is the ID of the parent run.
843
- tags (Optional[list[str]]): The tags.
844
- kwargs (Any): Additional keyword arguments.
838
+ documents: The documents retrieved.
839
+ run_id: The run ID. This is the ID of the current run.
840
+ parent_run_id: The parent run ID. This is the ID of the parent run.
841
+ tags: The tags.
842
+ **kwargs: Additional keyword arguments.
845
843
  """
846
844
 
847
845
  async def on_retriever_error(
@@ -856,11 +854,11 @@ class AsyncCallbackHandler(BaseCallbackHandler):
856
854
  """Run on retriever error.
857
855
 
858
856
  Args:
859
- error (BaseException): The error that occurred.
860
- run_id (UUID): The run ID. This is the ID of the current run.
861
- parent_run_id (UUID): The parent run ID. This is the ID of the parent run.
862
- tags (Optional[list[str]]): The tags.
863
- kwargs (Any): Additional keyword arguments.
857
+ error: The error that occurred.
858
+ run_id: The run ID. This is the ID of the current run.
859
+ parent_run_id: The parent run ID. This is the ID of the parent run.
860
+ tags: The tags.
861
+ **kwargs: Additional keyword arguments.
864
862
  """
865
863
 
866
864
  async def on_custom_event(
@@ -878,7 +876,7 @@ class AsyncCallbackHandler(BaseCallbackHandler):
878
876
  Args:
879
877
  name: The name of the custom event.
880
878
  data: The data for the custom event. Format will match
881
- the format specified by the user.
879
+ the format specified by the user.
882
880
  run_id: The ID of the run.
883
881
  tags: The tags associated with the custom event
884
882
  (includes inherited tags).
@@ -906,16 +904,13 @@ class BaseCallbackManager(CallbackManagerMixin):
906
904
  """Initialize callback manager.
907
905
 
908
906
  Args:
909
- handlers (list[BaseCallbackHandler]): The handlers.
910
- inheritable_handlers (Optional[list[BaseCallbackHandler]]):
911
- The inheritable handlers. Default is None.
912
- parent_run_id (Optional[UUID]): The parent run ID. Default is None.
913
- tags (Optional[list[str]]): The tags. Default is None.
914
- inheritable_tags (Optional[list[str]]): The inheritable tags.
915
- Default is None.
916
- metadata (Optional[dict[str, Any]]): The metadata. Default is None.
917
- inheritable_metadata (Optional[dict[str, Any]]): The inheritable metadata.
918
- Default is None.
907
+ handlers: The handlers.
908
+ inheritable_handlers: The inheritable handlers.
909
+ parent_run_id: The parent run ID.
910
+ tags: The tags.
911
+ inheritable_tags: The inheritable tags.
912
+ metadata: The metadata.
913
+ inheritable_metadata: The inheritable metadata.
919
914
  """
920
915
  self.handlers: list[BaseCallbackHandler] = handlers
921
916
  self.inheritable_handlers: list[BaseCallbackHandler] = (
@@ -946,35 +941,29 @@ class BaseCallbackManager(CallbackManagerMixin):
946
941
  within merge_configs.
947
942
 
948
943
  Returns:
949
- BaseCallbackManager: The merged callback manager of the same type
950
- as the current object.
944
+ The merged callback manager of the same type as the current object.
951
945
 
952
946
  Example: Merging two callback managers.
953
947
 
954
- .. code-block:: python
955
-
956
- from langchain_core.callbacks.manager import (
957
- CallbackManager,
958
- trace_as_chain_group,
959
- )
960
- from langchain_core.callbacks.stdout import StdOutCallbackHandler
961
-
962
- manager = CallbackManager(
963
- handlers=[StdOutCallbackHandler()], tags=["tag2"]
964
- )
965
- with trace_as_chain_group(
966
- "My Group Name", tags=["tag1"]
967
- ) as group_manager:
968
- merged_manager = group_manager.merge(manager)
969
- print(merged_manager.handlers)
970
- # [
971
- # <langchain_core.callbacks.stdout.StdOutCallbackHandler object at ...>,
972
- # <langchain_core.callbacks.streaming_stdout.StreamingStdOutCallbackHandler object at ...>,
973
- # ]
974
-
975
- print(merged_manager.tags)
976
- # ['tag2', 'tag1']
977
-
948
+ ```python
949
+ from langchain_core.callbacks.manager import (
950
+ CallbackManager,
951
+ trace_as_chain_group,
952
+ )
953
+ from langchain_core.callbacks.stdout import StdOutCallbackHandler
954
+
955
+ manager = CallbackManager(handlers=[StdOutCallbackHandler()], tags=["tag2"])
956
+ with trace_as_chain_group("My Group Name", tags=["tag1"]) as group_manager:
957
+ merged_manager = group_manager.merge(manager)
958
+ print(merged_manager.handlers)
959
+ # [
960
+ # <langchain_core.callbacks.stdout.StdOutCallbackHandler object at ...>,
961
+ # <langchain_core.callbacks.streaming_stdout.StreamingStdOutCallbackHandler object at ...>,
962
+ # ]
963
+
964
+ print(merged_manager.tags)
965
+ # ['tag2', 'tag1']
966
+ ```
978
967
  """ # noqa: E501
979
968
  manager = self.__class__(
980
969
  parent_run_id=self.parent_run_id or other.parent_run_id,
@@ -1011,8 +1000,8 @@ class BaseCallbackManager(CallbackManagerMixin):
1011
1000
  """Add a handler to the callback manager.
1012
1001
 
1013
1002
  Args:
1014
- handler (BaseCallbackHandler): The handler to add.
1015
- inherit (bool): Whether to inherit the handler. Default is True.
1003
+ handler: The handler to add.
1004
+ inherit: Whether to inherit the handler. Default is True.
1016
1005
  """
1017
1006
  if handler not in self.handlers:
1018
1007
  self.handlers.append(handler)
@@ -1023,7 +1012,7 @@ class BaseCallbackManager(CallbackManagerMixin):
1023
1012
  """Remove a handler from the callback manager.
1024
1013
 
1025
1014
  Args:
1026
- handler (BaseCallbackHandler): The handler to remove.
1015
+ handler: The handler to remove.
1027
1016
  """
1028
1017
  if handler in self.handlers:
1029
1018
  self.handlers.remove(handler)
@@ -1038,8 +1027,8 @@ class BaseCallbackManager(CallbackManagerMixin):
1038
1027
  """Set handlers as the only handlers on the callback manager.
1039
1028
 
1040
1029
  Args:
1041
- handlers (list[BaseCallbackHandler]): The handlers to set.
1042
- inherit (bool): Whether to inherit the handlers. Default is True.
1030
+ handlers: The handlers to set.
1031
+ inherit: Whether to inherit the handlers. Default is True.
1043
1032
  """
1044
1033
  self.handlers = []
1045
1034
  self.inheritable_handlers = []
@@ -1054,8 +1043,8 @@ class BaseCallbackManager(CallbackManagerMixin):
1054
1043
  """Set handler as the only handler on the callback manager.
1055
1044
 
1056
1045
  Args:
1057
- handler (BaseCallbackHandler): The handler to set.
1058
- inherit (bool): Whether to inherit the handler. Default is True.
1046
+ handler: The handler to set.
1047
+ inherit: Whether to inherit the handler. Default is True.
1059
1048
  """
1060
1049
  self.set_handlers([handler], inherit=inherit)
1061
1050
 
@@ -1067,8 +1056,8 @@ class BaseCallbackManager(CallbackManagerMixin):
1067
1056
  """Add tags to the callback manager.
1068
1057
 
1069
1058
  Args:
1070
- tags (list[str]): The tags to add.
1071
- inherit (bool): Whether to inherit the tags. Default is True.
1059
+ tags: The tags to add.
1060
+ inherit: Whether to inherit the tags. Default is True.
1072
1061
  """
1073
1062
  for tag in tags:
1074
1063
  if tag in self.tags:
@@ -1081,7 +1070,7 @@ class BaseCallbackManager(CallbackManagerMixin):
1081
1070
  """Remove tags from the callback manager.
1082
1071
 
1083
1072
  Args:
1084
- tags (list[str]): The tags to remove.
1073
+ tags: The tags to remove.
1085
1074
  """
1086
1075
  for tag in tags:
1087
1076
  if tag in self.tags:
@@ -1097,8 +1086,8 @@ class BaseCallbackManager(CallbackManagerMixin):
1097
1086
  """Add metadata to the callback manager.
1098
1087
 
1099
1088
  Args:
1100
- metadata (dict[str, Any]): The metadata to add.
1101
- inherit (bool): Whether to inherit the metadata. Default is True.
1089
+ metadata: The metadata to add.
1090
+ inherit: Whether to inherit the metadata. Default is True.
1102
1091
  """
1103
1092
  self.metadata.update(metadata)
1104
1093
  if inherit:
@@ -1108,7 +1097,7 @@ class BaseCallbackManager(CallbackManagerMixin):
1108
1097
  """Remove metadata from the callback manager.
1109
1098
 
1110
1099
  Args:
1111
- keys (list[str]): The keys to remove.
1100
+ keys: The keys to remove.
1112
1101
  """
1113
1102
  for key in keys:
1114
1103
  self.metadata.pop(key, None)