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.
- langchain_core/__init__.py +1 -1
- langchain_core/_api/__init__.py +0 -1
- langchain_core/_api/beta_decorator.py +17 -20
- langchain_core/_api/deprecation.py +30 -35
- langchain_core/_import_utils.py +1 -1
- langchain_core/agents.py +7 -6
- langchain_core/caches.py +4 -10
- langchain_core/callbacks/__init__.py +1 -8
- langchain_core/callbacks/base.py +232 -243
- langchain_core/callbacks/file.py +33 -33
- langchain_core/callbacks/manager.py +353 -416
- langchain_core/callbacks/stdout.py +21 -22
- langchain_core/callbacks/streaming_stdout.py +32 -32
- langchain_core/callbacks/usage.py +54 -51
- langchain_core/chat_history.py +76 -55
- langchain_core/document_loaders/langsmith.py +21 -21
- langchain_core/documents/__init__.py +0 -1
- langchain_core/documents/base.py +37 -40
- langchain_core/documents/transformers.py +28 -29
- langchain_core/embeddings/fake.py +46 -52
- langchain_core/exceptions.py +5 -5
- langchain_core/indexing/api.py +11 -11
- langchain_core/indexing/base.py +24 -24
- langchain_core/language_models/__init__.py +0 -2
- langchain_core/language_models/_utils.py +51 -53
- langchain_core/language_models/base.py +23 -24
- langchain_core/language_models/chat_models.py +121 -144
- langchain_core/language_models/fake_chat_models.py +5 -5
- langchain_core/language_models/llms.py +10 -12
- langchain_core/load/dump.py +1 -1
- langchain_core/load/load.py +16 -16
- langchain_core/load/serializable.py +35 -34
- langchain_core/messages/__init__.py +1 -16
- langchain_core/messages/ai.py +105 -104
- langchain_core/messages/base.py +26 -26
- langchain_core/messages/block_translators/__init__.py +17 -17
- langchain_core/messages/block_translators/anthropic.py +2 -2
- langchain_core/messages/block_translators/bedrock_converse.py +2 -2
- langchain_core/messages/block_translators/google_genai.py +2 -2
- langchain_core/messages/block_translators/groq.py +117 -21
- langchain_core/messages/block_translators/langchain_v0.py +2 -2
- langchain_core/messages/block_translators/openai.py +4 -4
- langchain_core/messages/chat.py +1 -1
- langchain_core/messages/content.py +189 -193
- langchain_core/messages/function.py +5 -5
- langchain_core/messages/human.py +15 -17
- langchain_core/messages/modifier.py +1 -1
- langchain_core/messages/system.py +12 -14
- langchain_core/messages/tool.py +45 -49
- langchain_core/messages/utils.py +384 -396
- langchain_core/output_parsers/__init__.py +1 -14
- langchain_core/output_parsers/base.py +22 -23
- langchain_core/output_parsers/json.py +3 -3
- langchain_core/output_parsers/list.py +1 -1
- langchain_core/output_parsers/openai_functions.py +46 -44
- langchain_core/output_parsers/openai_tools.py +7 -7
- langchain_core/output_parsers/pydantic.py +10 -11
- langchain_core/output_parsers/string.py +1 -1
- langchain_core/output_parsers/transform.py +2 -2
- langchain_core/output_parsers/xml.py +1 -1
- langchain_core/outputs/__init__.py +1 -1
- langchain_core/outputs/chat_generation.py +14 -14
- langchain_core/outputs/generation.py +5 -5
- langchain_core/outputs/llm_result.py +5 -5
- langchain_core/prompt_values.py +5 -5
- langchain_core/prompts/__init__.py +3 -23
- langchain_core/prompts/base.py +32 -37
- langchain_core/prompts/chat.py +216 -222
- langchain_core/prompts/dict.py +2 -2
- langchain_core/prompts/few_shot.py +76 -83
- langchain_core/prompts/few_shot_with_templates.py +6 -8
- langchain_core/prompts/image.py +11 -13
- langchain_core/prompts/loading.py +1 -1
- langchain_core/prompts/message.py +2 -2
- langchain_core/prompts/prompt.py +14 -16
- langchain_core/prompts/string.py +19 -7
- langchain_core/prompts/structured.py +24 -25
- langchain_core/rate_limiters.py +36 -38
- langchain_core/retrievers.py +41 -182
- langchain_core/runnables/base.py +565 -590
- langchain_core/runnables/branch.py +7 -7
- langchain_core/runnables/config.py +37 -44
- langchain_core/runnables/configurable.py +8 -9
- langchain_core/runnables/fallbacks.py +8 -8
- langchain_core/runnables/graph.py +28 -27
- langchain_core/runnables/graph_ascii.py +19 -18
- langchain_core/runnables/graph_mermaid.py +20 -31
- langchain_core/runnables/graph_png.py +7 -7
- langchain_core/runnables/history.py +20 -20
- langchain_core/runnables/passthrough.py +8 -8
- langchain_core/runnables/retry.py +3 -3
- langchain_core/runnables/router.py +1 -1
- langchain_core/runnables/schema.py +33 -33
- langchain_core/runnables/utils.py +30 -34
- langchain_core/stores.py +72 -102
- langchain_core/sys_info.py +27 -29
- langchain_core/tools/__init__.py +1 -14
- langchain_core/tools/base.py +63 -63
- langchain_core/tools/convert.py +92 -92
- langchain_core/tools/render.py +9 -9
- langchain_core/tools/retriever.py +1 -1
- langchain_core/tools/simple.py +6 -7
- langchain_core/tools/structured.py +17 -18
- langchain_core/tracers/__init__.py +1 -9
- langchain_core/tracers/base.py +35 -35
- langchain_core/tracers/context.py +12 -17
- langchain_core/tracers/event_stream.py +3 -3
- langchain_core/tracers/langchain.py +8 -8
- langchain_core/tracers/log_stream.py +17 -18
- langchain_core/tracers/memory_stream.py +2 -2
- langchain_core/tracers/schemas.py +0 -129
- langchain_core/utils/aiter.py +31 -31
- langchain_core/utils/env.py +5 -5
- langchain_core/utils/function_calling.py +48 -120
- langchain_core/utils/html.py +4 -4
- langchain_core/utils/input.py +2 -2
- langchain_core/utils/interactive_env.py +1 -1
- langchain_core/utils/iter.py +19 -19
- langchain_core/utils/json.py +1 -1
- langchain_core/utils/json_schema.py +2 -2
- langchain_core/utils/mustache.py +5 -5
- langchain_core/utils/pydantic.py +17 -17
- langchain_core/utils/strings.py +4 -4
- langchain_core/utils/utils.py +25 -28
- langchain_core/vectorstores/base.py +43 -64
- langchain_core/vectorstores/in_memory.py +83 -85
- langchain_core/version.py +1 -1
- {langchain_core-1.0.0a7.dist-info → langchain_core-1.0.0rc1.dist-info}/METADATA +23 -11
- langchain_core-1.0.0rc1.dist-info/RECORD +172 -0
- langchain_core/memory.py +0 -120
- langchain_core/pydantic_v1/__init__.py +0 -30
- langchain_core/pydantic_v1/dataclasses.py +0 -23
- langchain_core/pydantic_v1/main.py +0 -23
- langchain_core-1.0.0a7.dist-info/RECORD +0 -176
- {langchain_core-1.0.0a7.dist-info → langchain_core-1.0.0rc1.dist-info}/WHEEL +0 -0
langchain_core/callbacks/base.py
CHANGED
|
@@ -35,10 +35,10 @@ class RetrieverManagerMixin:
|
|
|
35
35
|
"""Run when Retriever errors.
|
|
36
36
|
|
|
37
37
|
Args:
|
|
38
|
-
error
|
|
39
|
-
run_id
|
|
40
|
-
parent_run_id
|
|
41
|
-
kwargs
|
|
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
|
|
56
|
-
run_id
|
|
57
|
-
parent_run_id
|
|
58
|
-
kwargs
|
|
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
|
|
80
|
-
chunk
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
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
|
|
99
|
-
run_id
|
|
100
|
-
parent_run_id
|
|
101
|
-
kwargs
|
|
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
|
|
116
|
-
run_id
|
|
117
|
-
parent_run_id
|
|
118
|
-
kwargs
|
|
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
|
|
137
|
-
run_id
|
|
138
|
-
parent_run_id
|
|
139
|
-
kwargs
|
|
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
|
|
154
|
-
run_id
|
|
155
|
-
parent_run_id
|
|
156
|
-
kwargs
|
|
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
|
|
171
|
-
run_id
|
|
172
|
-
parent_run_id
|
|
173
|
-
kwargs
|
|
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
|
|
188
|
-
run_id
|
|
189
|
-
parent_run_id
|
|
190
|
-
kwargs
|
|
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
|
|
209
|
-
run_id
|
|
210
|
-
parent_run_id
|
|
211
|
-
kwargs
|
|
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
|
|
226
|
-
run_id
|
|
227
|
-
parent_run_id
|
|
228
|
-
kwargs
|
|
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
|
-
|
|
250
|
+
`on_chat_model_start` instead.
|
|
252
251
|
|
|
253
252
|
Args:
|
|
254
|
-
serialized
|
|
255
|
-
prompts
|
|
256
|
-
run_id
|
|
257
|
-
parent_run_id
|
|
258
|
-
tags
|
|
259
|
-
metadata
|
|
260
|
-
kwargs
|
|
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
|
|
277
|
+
a non-chat model, you should use `on_llm_start` instead.
|
|
279
278
|
|
|
280
279
|
Args:
|
|
281
|
-
serialized
|
|
282
|
-
messages
|
|
283
|
-
run_id
|
|
284
|
-
parent_run_id
|
|
285
|
-
tags
|
|
286
|
-
metadata
|
|
287
|
-
kwargs
|
|
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
|
|
309
|
-
query
|
|
310
|
-
run_id
|
|
311
|
-
parent_run_id
|
|
312
|
-
tags
|
|
313
|
-
metadata
|
|
314
|
-
kwargs
|
|
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
|
|
332
|
-
inputs
|
|
333
|
-
run_id
|
|
334
|
-
parent_run_id
|
|
335
|
-
tags
|
|
336
|
-
metadata
|
|
337
|
-
kwargs
|
|
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
|
|
356
|
-
input_str
|
|
357
|
-
run_id
|
|
358
|
-
parent_run_id
|
|
359
|
-
tags
|
|
360
|
-
metadata
|
|
361
|
-
inputs
|
|
362
|
-
kwargs
|
|
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
|
|
381
|
-
run_id
|
|
382
|
-
parent_run_id
|
|
383
|
-
kwargs
|
|
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
|
|
398
|
-
run_id
|
|
399
|
-
parent_run_id
|
|
400
|
-
kwargs
|
|
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
|
-
|
|
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
|
-
|
|
499
|
+
`on_chat_model_start` instead.
|
|
501
500
|
|
|
502
501
|
Args:
|
|
503
|
-
serialized
|
|
504
|
-
prompts
|
|
505
|
-
run_id
|
|
506
|
-
parent_run_id
|
|
507
|
-
tags
|
|
508
|
-
metadata
|
|
509
|
-
kwargs
|
|
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
|
|
526
|
+
a non-chat model, you should use `on_llm_start` instead.
|
|
528
527
|
|
|
529
528
|
Args:
|
|
530
|
-
serialized
|
|
531
|
-
messages
|
|
532
|
-
run_id
|
|
533
|
-
parent_run_id
|
|
534
|
-
tags
|
|
535
|
-
metadata
|
|
536
|
-
kwargs
|
|
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
|
|
559
|
-
chunk
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
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
|
|
580
|
-
run_id
|
|
581
|
-
parent_run_id
|
|
582
|
-
tags
|
|
583
|
-
kwargs
|
|
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
|
|
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
|
|
622
|
-
inputs
|
|
623
|
-
run_id
|
|
624
|
-
parent_run_id
|
|
625
|
-
tags
|
|
626
|
-
metadata
|
|
627
|
-
kwargs
|
|
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
|
|
643
|
-
run_id
|
|
644
|
-
parent_run_id
|
|
645
|
-
tags
|
|
646
|
-
kwargs
|
|
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
|
|
662
|
-
run_id
|
|
663
|
-
parent_run_id
|
|
664
|
-
tags
|
|
665
|
-
kwargs
|
|
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
|
|
684
|
-
input_str
|
|
685
|
-
run_id
|
|
686
|
-
parent_run_id
|
|
687
|
-
tags
|
|
688
|
-
metadata
|
|
689
|
-
inputs
|
|
690
|
-
kwargs
|
|
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
|
|
706
|
-
run_id
|
|
707
|
-
parent_run_id
|
|
708
|
-
tags
|
|
709
|
-
kwargs
|
|
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
|
|
725
|
-
run_id
|
|
726
|
-
parent_run_id
|
|
727
|
-
tags
|
|
728
|
-
kwargs
|
|
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
|
|
744
|
-
run_id
|
|
745
|
-
parent_run_id
|
|
746
|
-
tags
|
|
747
|
-
kwargs
|
|
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
|
|
762
|
-
run_id
|
|
763
|
-
parent_run_id
|
|
764
|
-
kwargs
|
|
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
|
|
780
|
-
run_id
|
|
781
|
-
parent_run_id
|
|
782
|
-
tags
|
|
783
|
-
kwargs
|
|
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
|
|
799
|
-
run_id
|
|
800
|
-
parent_run_id
|
|
801
|
-
tags
|
|
802
|
-
kwargs
|
|
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
|
|
820
|
-
query
|
|
821
|
-
run_id
|
|
822
|
-
parent_run_id
|
|
823
|
-
tags
|
|
824
|
-
metadata
|
|
825
|
-
kwargs
|
|
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
|
|
841
|
-
run_id
|
|
842
|
-
parent_run_id
|
|
843
|
-
tags
|
|
844
|
-
kwargs
|
|
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
|
|
860
|
-
run_id
|
|
861
|
-
parent_run_id
|
|
862
|
-
tags
|
|
863
|
-
kwargs
|
|
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
|
-
|
|
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
|
|
910
|
-
inheritable_handlers
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
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
|
-
|
|
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
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
)
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
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
|
|
1015
|
-
inherit
|
|
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
|
|
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
|
|
1042
|
-
inherit
|
|
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
|
|
1058
|
-
inherit
|
|
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
|
|
1071
|
-
inherit
|
|
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
|
|
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
|
|
1101
|
-
inherit
|
|
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
|
|
1100
|
+
keys: The keys to remove.
|
|
1112
1101
|
"""
|
|
1113
1102
|
for key in keys:
|
|
1114
1103
|
self.metadata.pop(key, None)
|