langchain-core 0.3.75__py3-none-any.whl → 0.3.76__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/_api/beta_decorator.py +17 -40
- langchain_core/_api/deprecation.py +19 -6
- langchain_core/_api/path.py +19 -2
- langchain_core/_import_utils.py +7 -0
- langchain_core/agents.py +10 -6
- langchain_core/beta/runnables/context.py +1 -2
- langchain_core/callbacks/base.py +11 -4
- langchain_core/callbacks/manager.py +81 -69
- langchain_core/callbacks/usage.py +4 -2
- langchain_core/chat_history.py +4 -6
- langchain_core/document_loaders/base.py +34 -9
- langchain_core/document_loaders/langsmith.py +3 -0
- langchain_core/documents/base.py +35 -10
- langchain_core/documents/transformers.py +4 -2
- langchain_core/embeddings/fake.py +8 -5
- langchain_core/env.py +2 -3
- langchain_core/example_selectors/base.py +12 -0
- langchain_core/exceptions.py +7 -0
- langchain_core/globals.py +17 -28
- langchain_core/indexing/api.py +56 -44
- langchain_core/indexing/base.py +5 -8
- langchain_core/indexing/in_memory.py +23 -3
- langchain_core/language_models/__init__.py +3 -2
- langchain_core/language_models/base.py +31 -20
- langchain_core/language_models/chat_models.py +94 -25
- langchain_core/language_models/fake_chat_models.py +5 -7
- langchain_core/language_models/llms.py +49 -17
- langchain_core/load/dump.py +2 -3
- langchain_core/load/load.py +15 -1
- langchain_core/load/serializable.py +38 -43
- langchain_core/memory.py +7 -3
- langchain_core/messages/ai.py +36 -19
- langchain_core/messages/base.py +13 -6
- langchain_core/messages/content_blocks.py +23 -2
- langchain_core/messages/human.py +2 -6
- langchain_core/messages/system.py +2 -6
- langchain_core/messages/tool.py +33 -13
- langchain_core/messages/utils.py +182 -72
- langchain_core/output_parsers/base.py +5 -2
- langchain_core/output_parsers/json.py +4 -4
- langchain_core/output_parsers/list.py +7 -22
- langchain_core/output_parsers/openai_functions.py +3 -0
- langchain_core/output_parsers/openai_tools.py +6 -1
- langchain_core/output_parsers/pydantic.py +4 -0
- langchain_core/output_parsers/string.py +5 -1
- langchain_core/output_parsers/xml.py +19 -19
- langchain_core/outputs/chat_generation.py +18 -7
- langchain_core/outputs/generation.py +14 -3
- langchain_core/outputs/llm_result.py +8 -1
- langchain_core/prompt_values.py +10 -4
- langchain_core/prompts/base.py +4 -9
- langchain_core/prompts/chat.py +87 -58
- langchain_core/prompts/dict.py +16 -8
- langchain_core/prompts/few_shot.py +9 -11
- langchain_core/prompts/few_shot_with_templates.py +5 -1
- langchain_core/prompts/image.py +12 -5
- langchain_core/prompts/message.py +5 -6
- langchain_core/prompts/pipeline.py +13 -8
- langchain_core/prompts/prompt.py +22 -8
- langchain_core/prompts/string.py +18 -10
- langchain_core/prompts/structured.py +7 -2
- langchain_core/rate_limiters.py +2 -2
- langchain_core/retrievers.py +7 -6
- langchain_core/runnables/base.py +402 -183
- langchain_core/runnables/branch.py +14 -19
- langchain_core/runnables/config.py +9 -15
- langchain_core/runnables/configurable.py +34 -19
- langchain_core/runnables/fallbacks.py +20 -13
- langchain_core/runnables/graph.py +44 -37
- langchain_core/runnables/graph_ascii.py +40 -17
- langchain_core/runnables/graph_mermaid.py +27 -15
- langchain_core/runnables/graph_png.py +27 -31
- langchain_core/runnables/history.py +55 -58
- langchain_core/runnables/passthrough.py +44 -21
- langchain_core/runnables/retry.py +9 -5
- langchain_core/runnables/router.py +9 -8
- langchain_core/runnables/schema.py +2 -0
- langchain_core/runnables/utils.py +51 -89
- langchain_core/stores.py +13 -25
- langchain_core/sys_info.py +9 -8
- langchain_core/tools/base.py +30 -23
- langchain_core/tools/convert.py +24 -13
- langchain_core/tools/simple.py +35 -3
- langchain_core/tools/structured.py +25 -2
- langchain_core/tracers/base.py +2 -2
- langchain_core/tracers/context.py +5 -1
- langchain_core/tracers/core.py +109 -39
- langchain_core/tracers/evaluation.py +22 -26
- langchain_core/tracers/event_stream.py +40 -27
- langchain_core/tracers/langchain.py +12 -3
- langchain_core/tracers/langchain_v1.py +10 -2
- langchain_core/tracers/log_stream.py +56 -17
- langchain_core/tracers/root_listeners.py +4 -20
- langchain_core/tracers/run_collector.py +6 -16
- langchain_core/tracers/schemas.py +5 -1
- langchain_core/utils/aiter.py +14 -6
- langchain_core/utils/env.py +3 -0
- langchain_core/utils/function_calling.py +37 -20
- langchain_core/utils/interactive_env.py +6 -2
- langchain_core/utils/iter.py +11 -3
- langchain_core/utils/json.py +5 -2
- langchain_core/utils/json_schema.py +15 -5
- langchain_core/utils/loading.py +5 -1
- langchain_core/utils/mustache.py +24 -15
- langchain_core/utils/pydantic.py +32 -4
- langchain_core/utils/utils.py +24 -8
- langchain_core/vectorstores/base.py +7 -20
- langchain_core/vectorstores/in_memory.py +18 -12
- langchain_core/vectorstores/utils.py +18 -12
- langchain_core/version.py +1 -1
- langchain_core-0.3.76.dist-info/METADATA +77 -0
- langchain_core-0.3.76.dist-info/RECORD +174 -0
- langchain_core-0.3.75.dist-info/METADATA +0 -106
- langchain_core-0.3.75.dist-info/RECORD +0 -174
- {langchain_core-0.3.75.dist-info → langchain_core-0.3.76.dist-info}/WHEEL +0 -0
- {langchain_core-0.3.75.dist-info → langchain_core-0.3.76.dist-info}/entry_points.txt +0 -0
langchain_core/sys_info.py
CHANGED
|
@@ -1,12 +1,18 @@
|
|
|
1
|
-
"""**sys_info**
|
|
1
|
+
"""**sys_info** implementation.
|
|
2
2
|
|
|
3
|
+
sys_info prints information about the system and langchain packages for
|
|
4
|
+
debugging purposes.
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
import pkgutil
|
|
8
|
+
import platform
|
|
9
|
+
import sys
|
|
3
10
|
from collections.abc import Sequence
|
|
11
|
+
from importlib import metadata, util
|
|
4
12
|
|
|
5
13
|
|
|
6
14
|
def _get_sub_deps(packages: Sequence[str]) -> list[str]:
|
|
7
15
|
"""Get any specified sub-dependencies."""
|
|
8
|
-
from importlib import metadata
|
|
9
|
-
|
|
10
16
|
sub_deps = set()
|
|
11
17
|
underscored_packages = {pkg.replace("-", "_") for pkg in packages}
|
|
12
18
|
|
|
@@ -33,11 +39,6 @@ def print_sys_info(*, additional_pkgs: Sequence[str] = ()) -> None:
|
|
|
33
39
|
Args:
|
|
34
40
|
additional_pkgs: Additional packages to include in the output.
|
|
35
41
|
"""
|
|
36
|
-
import pkgutil
|
|
37
|
-
import platform
|
|
38
|
-
import sys
|
|
39
|
-
from importlib import metadata, util
|
|
40
|
-
|
|
41
42
|
# Packages that do not start with "langchain" prefix.
|
|
42
43
|
other_langchain_packages = [
|
|
43
44
|
"langserve",
|
langchain_core/tools/base.py
CHANGED
|
@@ -81,6 +81,7 @@ TOOL_MESSAGE_BLOCK_TYPES = (
|
|
|
81
81
|
"json",
|
|
82
82
|
"search_result",
|
|
83
83
|
"custom_tool_call_output",
|
|
84
|
+
"document",
|
|
84
85
|
)
|
|
85
86
|
|
|
86
87
|
|
|
@@ -271,15 +272,12 @@ def _function_annotations_are_pydantic_v1(
|
|
|
271
272
|
|
|
272
273
|
|
|
273
274
|
class _SchemaConfig:
|
|
274
|
-
"""Configuration for Pydantic models generated from function signatures.
|
|
275
|
-
|
|
276
|
-
Attributes:
|
|
277
|
-
extra: Whether to allow extra fields in the model.
|
|
278
|
-
arbitrary_types_allowed: Whether to allow arbitrary types in the model.
|
|
279
|
-
"""
|
|
275
|
+
"""Configuration for Pydantic models generated from function signatures."""
|
|
280
276
|
|
|
281
277
|
extra: str = "forbid"
|
|
278
|
+
"""Whether to allow extra fields in the model."""
|
|
282
279
|
arbitrary_types_allowed: bool = True
|
|
280
|
+
"""Whether to allow arbitrary types in the model."""
|
|
283
281
|
|
|
284
282
|
|
|
285
283
|
def create_schema_from_function(
|
|
@@ -506,7 +504,12 @@ class ChildTool(BaseTool):
|
|
|
506
504
|
"""
|
|
507
505
|
|
|
508
506
|
def __init__(self, **kwargs: Any) -> None:
|
|
509
|
-
"""Initialize the tool.
|
|
507
|
+
"""Initialize the tool.
|
|
508
|
+
|
|
509
|
+
Raises:
|
|
510
|
+
TypeError: If ``args_schema`` is not a subclass of pydantic ``BaseModel`` or
|
|
511
|
+
dict.
|
|
512
|
+
"""
|
|
510
513
|
if (
|
|
511
514
|
"args_schema" in kwargs
|
|
512
515
|
and kwargs["args_schema"] is not None
|
|
@@ -628,9 +631,10 @@ class ChildTool(BaseTool):
|
|
|
628
631
|
The parsed and validated input.
|
|
629
632
|
|
|
630
633
|
Raises:
|
|
631
|
-
ValueError: If string input is provided with JSON schema
|
|
632
|
-
|
|
633
|
-
|
|
634
|
+
ValueError: If string input is provided with JSON schema ``args_schema``.
|
|
635
|
+
ValueError: If InjectedToolCallId is required but ``tool_call_id`` is not
|
|
636
|
+
provided.
|
|
637
|
+
TypeError: If args_schema is not a Pydantic ``BaseModel`` or dict.
|
|
634
638
|
"""
|
|
635
639
|
input_args = self.args_schema
|
|
636
640
|
if isinstance(tool_input, str):
|
|
@@ -655,10 +659,7 @@ class ChildTool(BaseTool):
|
|
|
655
659
|
return tool_input
|
|
656
660
|
if issubclass(input_args, BaseModel):
|
|
657
661
|
for k, v in get_all_basemodel_annotations(input_args).items():
|
|
658
|
-
if (
|
|
659
|
-
_is_injected_arg_type(v, injected_type=InjectedToolCallId)
|
|
660
|
-
and k not in tool_input
|
|
661
|
-
):
|
|
662
|
+
if _is_injected_arg_type(v, injected_type=InjectedToolCallId):
|
|
662
663
|
if tool_call_id is None:
|
|
663
664
|
msg = (
|
|
664
665
|
"When tool includes an InjectedToolCallId "
|
|
@@ -673,10 +674,7 @@ class ChildTool(BaseTool):
|
|
|
673
674
|
result_dict = result.model_dump()
|
|
674
675
|
elif issubclass(input_args, BaseModelV1):
|
|
675
676
|
for k, v in get_all_basemodel_annotations(input_args).items():
|
|
676
|
-
if (
|
|
677
|
-
_is_injected_arg_type(v, injected_type=InjectedToolCallId)
|
|
678
|
-
and k not in tool_input
|
|
679
|
-
):
|
|
677
|
+
if _is_injected_arg_type(v, injected_type=InjectedToolCallId):
|
|
680
678
|
if tool_call_id is None:
|
|
681
679
|
msg = (
|
|
682
680
|
"When tool includes an InjectedToolCallId "
|
|
@@ -725,6 +723,9 @@ class ChildTool(BaseTool):
|
|
|
725
723
|
|
|
726
724
|
Add run_manager: Optional[CallbackManagerForToolRun] = None
|
|
727
725
|
to child implementations to enable tracing.
|
|
726
|
+
|
|
727
|
+
Returns:
|
|
728
|
+
The result of the tool execution.
|
|
728
729
|
"""
|
|
729
730
|
|
|
730
731
|
async def _arun(self, *args: Any, **kwargs: Any) -> Any:
|
|
@@ -732,6 +733,9 @@ class ChildTool(BaseTool):
|
|
|
732
733
|
|
|
733
734
|
Add run_manager: Optional[AsyncCallbackManagerForToolRun] = None
|
|
734
735
|
to child implementations to enable tracing.
|
|
736
|
+
|
|
737
|
+
Returns:
|
|
738
|
+
The result of the tool execution.
|
|
735
739
|
"""
|
|
736
740
|
if kwargs.get("run_manager") and signature(self._run).parameters.get(
|
|
737
741
|
"run_manager"
|
|
@@ -1285,7 +1289,7 @@ class InjectedToolCallId(InjectedToolArg):
|
|
|
1285
1289
|
|
|
1286
1290
|
|
|
1287
1291
|
def _is_injected_arg_type(
|
|
1288
|
-
type_: type, injected_type: Optional[type[InjectedToolArg]] = None
|
|
1292
|
+
type_: Union[type, TypeVar], injected_type: Optional[type[InjectedToolArg]] = None
|
|
1289
1293
|
) -> bool:
|
|
1290
1294
|
"""Check if a type annotation indicates an injected argument.
|
|
1291
1295
|
|
|
@@ -1306,12 +1310,15 @@ def _is_injected_arg_type(
|
|
|
1306
1310
|
|
|
1307
1311
|
def get_all_basemodel_annotations(
|
|
1308
1312
|
cls: Union[TypeBaseModel, Any], *, default_to_bound: bool = True
|
|
1309
|
-
) -> dict[str, type]:
|
|
1313
|
+
) -> dict[str, Union[type, TypeVar]]:
|
|
1310
1314
|
"""Get all annotations from a Pydantic BaseModel and its parents.
|
|
1311
1315
|
|
|
1312
1316
|
Args:
|
|
1313
1317
|
cls: The Pydantic BaseModel class.
|
|
1314
1318
|
default_to_bound: Whether to default to the bound of a TypeVar if it exists.
|
|
1319
|
+
|
|
1320
|
+
Returns:
|
|
1321
|
+
A dictionary of field names to their type annotations.
|
|
1315
1322
|
"""
|
|
1316
1323
|
# cls has no subscript: cls = FooBar
|
|
1317
1324
|
if isinstance(cls, type):
|
|
@@ -1319,7 +1326,7 @@ def get_all_basemodel_annotations(
|
|
|
1319
1326
|
fields = getattr(cls, "model_fields", {}) or getattr(cls, "__fields__", {})
|
|
1320
1327
|
alias_map = {field.alias: name for name, field in fields.items() if field.alias}
|
|
1321
1328
|
|
|
1322
|
-
annotations: dict[str, type] = {}
|
|
1329
|
+
annotations: dict[str, Union[type, TypeVar]] = {}
|
|
1323
1330
|
for name, param in inspect.signature(cls).parameters.items():
|
|
1324
1331
|
# Exclude hidden init args added by pydantic Config. For example if
|
|
1325
1332
|
# BaseModel(extra="allow") then "extra_data" will part of init sig.
|
|
@@ -1373,11 +1380,11 @@ def get_all_basemodel_annotations(
|
|
|
1373
1380
|
|
|
1374
1381
|
|
|
1375
1382
|
def _replace_type_vars(
|
|
1376
|
-
type_: type,
|
|
1383
|
+
type_: Union[type, TypeVar],
|
|
1377
1384
|
generic_map: Optional[dict[TypeVar, type]] = None,
|
|
1378
1385
|
*,
|
|
1379
1386
|
default_to_bound: bool = True,
|
|
1380
|
-
) -> type:
|
|
1387
|
+
) -> Union[type, TypeVar]:
|
|
1381
1388
|
"""Replace TypeVars in a type annotation with concrete types.
|
|
1382
1389
|
|
|
1383
1390
|
Args:
|
langchain_core/tools/convert.py
CHANGED
|
@@ -92,12 +92,13 @@ def tool(
|
|
|
92
92
|
positional argument.
|
|
93
93
|
description: Optional description for the tool.
|
|
94
94
|
Precedence for the tool description value is as follows:
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
95
|
+
|
|
96
|
+
- ``description`` argument
|
|
97
|
+
(used even if docstring and/or ``args_schema`` are provided)
|
|
98
|
+
- tool function docstring
|
|
99
|
+
(used even if ``args_schema`` is provided)
|
|
100
|
+
- ``args_schema`` description
|
|
101
|
+
(used only if `description` / docstring are not provided)
|
|
101
102
|
*args: Extra positional arguments. Must be empty.
|
|
102
103
|
return_direct: Whether to return directly from the tool rather
|
|
103
104
|
than continuing the agent loop. Defaults to False.
|
|
@@ -119,6 +120,17 @@ def tool(
|
|
|
119
120
|
whether to raise ValueError on invalid Google Style docstrings.
|
|
120
121
|
Defaults to True.
|
|
121
122
|
|
|
123
|
+
Raises:
|
|
124
|
+
ValueError: If too many positional arguments are provided.
|
|
125
|
+
ValueError: If a runnable is provided without a string name.
|
|
126
|
+
ValueError: If the first argument is not a string or callable with
|
|
127
|
+
a ``__name__`` attribute.
|
|
128
|
+
ValueError: If the function does not have a docstring and description
|
|
129
|
+
is not provided and ``infer_schema`` is False.
|
|
130
|
+
ValueError: If ``parse_docstring`` is True and the function has an invalid
|
|
131
|
+
Google-style docstring and ``error_on_invalid_docstring`` is True.
|
|
132
|
+
ValueError: If a Runnable is provided that does not have an object schema.
|
|
133
|
+
|
|
122
134
|
Returns:
|
|
123
135
|
The tool.
|
|
124
136
|
|
|
@@ -134,11 +146,13 @@ def tool(
|
|
|
134
146
|
# Searches the API for the query.
|
|
135
147
|
return
|
|
136
148
|
|
|
149
|
+
|
|
137
150
|
@tool("search", return_direct=True)
|
|
138
151
|
def search_api(query: str) -> str:
|
|
139
152
|
# Searches the API for the query.
|
|
140
153
|
return
|
|
141
154
|
|
|
155
|
+
|
|
142
156
|
@tool(response_format="content_and_artifact")
|
|
143
157
|
def search_api(query: str) -> tuple[str, dict]:
|
|
144
158
|
return "partial json of results", {"full": "object of results"}
|
|
@@ -171,18 +185,15 @@ def tool(
|
|
|
171
185
|
"bar": {
|
|
172
186
|
"title": "Bar",
|
|
173
187
|
"description": "The bar.",
|
|
174
|
-
"type": "string"
|
|
188
|
+
"type": "string",
|
|
175
189
|
},
|
|
176
190
|
"baz": {
|
|
177
191
|
"title": "Baz",
|
|
178
192
|
"description": "The baz.",
|
|
179
|
-
"type": "integer"
|
|
180
|
-
}
|
|
193
|
+
"type": "integer",
|
|
194
|
+
},
|
|
181
195
|
},
|
|
182
|
-
"required": [
|
|
183
|
-
"bar",
|
|
184
|
-
"baz"
|
|
185
|
-
]
|
|
196
|
+
"required": ["bar", "baz"],
|
|
186
197
|
}
|
|
187
198
|
|
|
188
199
|
Note that parsing by default will raise ``ValueError`` if the docstring
|
langchain_core/tools/simple.py
CHANGED
|
@@ -76,7 +76,19 @@ class Tool(BaseTool):
|
|
|
76
76
|
def _to_args_and_kwargs(
|
|
77
77
|
self, tool_input: Union[str, dict], tool_call_id: Optional[str]
|
|
78
78
|
) -> tuple[tuple, dict]:
|
|
79
|
-
"""Convert tool input to pydantic model.
|
|
79
|
+
"""Convert tool input to pydantic model.
|
|
80
|
+
|
|
81
|
+
Args:
|
|
82
|
+
tool_input: The input to the tool.
|
|
83
|
+
tool_call_id: The ID of the tool call.
|
|
84
|
+
|
|
85
|
+
Raises:
|
|
86
|
+
ToolException: If the tool input is invalid.
|
|
87
|
+
|
|
88
|
+
Returns:
|
|
89
|
+
the pydantic model args and kwargs.
|
|
90
|
+
|
|
91
|
+
"""
|
|
80
92
|
args, kwargs = super()._to_args_and_kwargs(tool_input, tool_call_id)
|
|
81
93
|
# For backwards compatibility. The tool must be run with a single input
|
|
82
94
|
all_args = list(args) + list(kwargs.values())
|
|
@@ -96,7 +108,17 @@ class Tool(BaseTool):
|
|
|
96
108
|
run_manager: Optional[CallbackManagerForToolRun] = None,
|
|
97
109
|
**kwargs: Any,
|
|
98
110
|
) -> Any:
|
|
99
|
-
"""Use the tool.
|
|
111
|
+
"""Use the tool.
|
|
112
|
+
|
|
113
|
+
Args:
|
|
114
|
+
*args: Positional arguments to pass to the tool
|
|
115
|
+
config: Configuration for the run
|
|
116
|
+
run_manager: Optional callback manager to use for the run
|
|
117
|
+
**kwargs: Keyword arguments to pass to the tool
|
|
118
|
+
|
|
119
|
+
Returns:
|
|
120
|
+
The result of the tool execution
|
|
121
|
+
"""
|
|
100
122
|
if self.func:
|
|
101
123
|
if run_manager and signature(self.func).parameters.get("callbacks"):
|
|
102
124
|
kwargs["callbacks"] = run_manager.get_child()
|
|
@@ -113,7 +135,17 @@ class Tool(BaseTool):
|
|
|
113
135
|
run_manager: Optional[AsyncCallbackManagerForToolRun] = None,
|
|
114
136
|
**kwargs: Any,
|
|
115
137
|
) -> Any:
|
|
116
|
-
"""Use the tool asynchronously.
|
|
138
|
+
"""Use the tool asynchronously.
|
|
139
|
+
|
|
140
|
+
Args:
|
|
141
|
+
*args: Positional arguments to pass to the tool
|
|
142
|
+
config: Configuration for the run
|
|
143
|
+
run_manager: Optional callback manager to use for the run
|
|
144
|
+
**kwargs: Keyword arguments to pass to the tool
|
|
145
|
+
|
|
146
|
+
Returns:
|
|
147
|
+
The result of the tool execution
|
|
148
|
+
"""
|
|
117
149
|
if self.coroutine:
|
|
118
150
|
if run_manager and signature(self.coroutine).parameters.get("callbacks"):
|
|
119
151
|
kwargs["callbacks"] = run_manager.get_child()
|
|
@@ -84,7 +84,17 @@ class StructuredTool(BaseTool):
|
|
|
84
84
|
run_manager: Optional[CallbackManagerForToolRun] = None,
|
|
85
85
|
**kwargs: Any,
|
|
86
86
|
) -> Any:
|
|
87
|
-
"""Use the tool.
|
|
87
|
+
"""Use the tool.
|
|
88
|
+
|
|
89
|
+
Args:
|
|
90
|
+
*args: Positional arguments to pass to the tool
|
|
91
|
+
config: Configuration for the run
|
|
92
|
+
run_manager: Optional callback manager to use for the run
|
|
93
|
+
**kwargs: Keyword arguments to pass to the tool
|
|
94
|
+
|
|
95
|
+
Returns:
|
|
96
|
+
The result of the tool execution
|
|
97
|
+
"""
|
|
88
98
|
if self.func:
|
|
89
99
|
if run_manager and signature(self.func).parameters.get("callbacks"):
|
|
90
100
|
kwargs["callbacks"] = run_manager.get_child()
|
|
@@ -101,7 +111,17 @@ class StructuredTool(BaseTool):
|
|
|
101
111
|
run_manager: Optional[AsyncCallbackManagerForToolRun] = None,
|
|
102
112
|
**kwargs: Any,
|
|
103
113
|
) -> Any:
|
|
104
|
-
"""Use the tool asynchronously.
|
|
114
|
+
"""Use the tool asynchronously.
|
|
115
|
+
|
|
116
|
+
Args:
|
|
117
|
+
*args: Positional arguments to pass to the tool
|
|
118
|
+
config: Configuration for the run
|
|
119
|
+
run_manager: Optional callback manager to use for the run
|
|
120
|
+
**kwargs: Keyword arguments to pass to the tool
|
|
121
|
+
|
|
122
|
+
Returns:
|
|
123
|
+
The result of the tool execution
|
|
124
|
+
"""
|
|
105
125
|
if self.coroutine:
|
|
106
126
|
if run_manager and signature(self.coroutine).parameters.get("callbacks"):
|
|
107
127
|
kwargs["callbacks"] = run_manager.get_child()
|
|
@@ -164,6 +184,9 @@ class StructuredTool(BaseTool):
|
|
|
164
184
|
|
|
165
185
|
Raises:
|
|
166
186
|
ValueError: If the function is not provided.
|
|
187
|
+
ValueError: If the function does not have a docstring and description
|
|
188
|
+
is not provided.
|
|
189
|
+
TypeError: If the ``args_schema`` is not a ``BaseModel`` or dict.
|
|
167
190
|
|
|
168
191
|
Examples:
|
|
169
192
|
|
langchain_core/tracers/base.py
CHANGED
|
@@ -520,11 +520,11 @@ class BaseTracer(_TracerCore, BaseCallbackHandler, ABC):
|
|
|
520
520
|
return retrieval_run
|
|
521
521
|
|
|
522
522
|
def __deepcopy__(self, memo: dict) -> BaseTracer:
|
|
523
|
-
"""
|
|
523
|
+
"""Return self."""
|
|
524
524
|
return self
|
|
525
525
|
|
|
526
526
|
def __copy__(self) -> BaseTracer:
|
|
527
|
-
"""
|
|
527
|
+
"""Return self."""
|
|
528
528
|
return self
|
|
529
529
|
|
|
530
530
|
|
|
@@ -43,7 +43,11 @@ run_collector_var: ContextVar[Optional[RunCollectorCallbackHandler]] = ContextVa
|
|
|
43
43
|
def tracing_enabled(
|
|
44
44
|
session_name: str = "default", # noqa: ARG001
|
|
45
45
|
) -> Generator[TracerSessionV1, None, None]:
|
|
46
|
-
"""Throw an error because this has been replaced by tracing_v2_enabled
|
|
46
|
+
"""Throw an error because this has been replaced by ``tracing_v2_enabled``.
|
|
47
|
+
|
|
48
|
+
Raises:
|
|
49
|
+
RuntimeError: Always, because this function is deprecated.
|
|
50
|
+
"""
|
|
47
51
|
msg = (
|
|
48
52
|
"tracing_enabled is no longer supported. Please use tracing_enabled_v2 instead."
|
|
49
53
|
)
|
langchain_core/tracers/core.py
CHANGED
|
@@ -71,7 +71,7 @@ class _TracerCore(ABC):
|
|
|
71
71
|
for streaming events.
|
|
72
72
|
- 'original+chat' is a format that is the same as 'original'
|
|
73
73
|
except it does NOT raise an attribute error on_chat_model_start
|
|
74
|
-
kwargs: Additional keyword arguments that will be passed to
|
|
74
|
+
**kwargs: Additional keyword arguments that will be passed to
|
|
75
75
|
the superclass.
|
|
76
76
|
"""
|
|
77
77
|
super().__init__(**kwargs)
|
|
@@ -82,7 +82,7 @@ class _TracerCore(ABC):
|
|
|
82
82
|
"""Map of run ID to (trace_id, dotted_order). Cleared when tracer GCed."""
|
|
83
83
|
|
|
84
84
|
@abstractmethod
|
|
85
|
-
def _persist_run(self, run: Run) -> Union[
|
|
85
|
+
def _persist_run(self, run: Run) -> Union[Coroutine[Any, Any, None], None]:
|
|
86
86
|
"""Persist a run."""
|
|
87
87
|
|
|
88
88
|
@staticmethod
|
|
@@ -108,7 +108,7 @@ class _TracerCore(ABC):
|
|
|
108
108
|
except: # noqa: E722
|
|
109
109
|
return msg
|
|
110
110
|
|
|
111
|
-
def _start_trace(self, run: Run) -> Union[
|
|
111
|
+
def _start_trace(self, run: Run) -> Union[Coroutine[Any, Any, None], None]: # type: ignore[return]
|
|
112
112
|
current_dotted_order = run.start_time.strftime("%Y%m%dT%H%M%S%fZ") + str(run.id)
|
|
113
113
|
if run.parent_run_id:
|
|
114
114
|
if parent := self.order_map.get(run.parent_run_id):
|
|
@@ -531,27 +531,43 @@ class _TracerCore(ABC):
|
|
|
531
531
|
return retrieval_run
|
|
532
532
|
|
|
533
533
|
def __deepcopy__(self, memo: dict) -> _TracerCore:
|
|
534
|
-
"""
|
|
534
|
+
"""Return self deepcopied."""
|
|
535
535
|
return self
|
|
536
536
|
|
|
537
537
|
def __copy__(self) -> _TracerCore:
|
|
538
|
-
"""
|
|
538
|
+
"""Return self copied."""
|
|
539
539
|
return self
|
|
540
540
|
|
|
541
|
-
def _end_trace(self, run: Run) -> Union[
|
|
542
|
-
"""End a trace for a run.
|
|
541
|
+
def _end_trace(self, run: Run) -> Union[Coroutine[Any, Any, None], None]: # noqa: ARG002
|
|
542
|
+
"""End a trace for a run.
|
|
543
|
+
|
|
544
|
+
Args:
|
|
545
|
+
run: The run.
|
|
546
|
+
"""
|
|
543
547
|
return None
|
|
544
548
|
|
|
545
|
-
def _on_run_create(self, run: Run) -> Union[
|
|
546
|
-
"""Process a run upon creation.
|
|
549
|
+
def _on_run_create(self, run: Run) -> Union[Coroutine[Any, Any, None], None]: # noqa: ARG002
|
|
550
|
+
"""Process a run upon creation.
|
|
551
|
+
|
|
552
|
+
Args:
|
|
553
|
+
run: The created run.
|
|
554
|
+
"""
|
|
547
555
|
return None
|
|
548
556
|
|
|
549
|
-
def _on_run_update(self, run: Run) -> Union[
|
|
550
|
-
"""Process a run upon update.
|
|
557
|
+
def _on_run_update(self, run: Run) -> Union[Coroutine[Any, Any, None], None]: # noqa: ARG002
|
|
558
|
+
"""Process a run upon update.
|
|
559
|
+
|
|
560
|
+
Args:
|
|
561
|
+
run: The updated run.
|
|
562
|
+
"""
|
|
551
563
|
return None
|
|
552
564
|
|
|
553
|
-
def _on_llm_start(self, run: Run) -> Union[
|
|
554
|
-
"""Process the LLM Run upon start.
|
|
565
|
+
def _on_llm_start(self, run: Run) -> Union[Coroutine[Any, Any, None], None]: # noqa: ARG002
|
|
566
|
+
"""Process the LLM Run upon start.
|
|
567
|
+
|
|
568
|
+
Args:
|
|
569
|
+
run: The LLM run.
|
|
570
|
+
"""
|
|
555
571
|
return None
|
|
556
572
|
|
|
557
573
|
def _on_llm_new_token(
|
|
@@ -559,54 +575,108 @@ class _TracerCore(ABC):
|
|
|
559
575
|
run: Run, # noqa: ARG002
|
|
560
576
|
token: str, # noqa: ARG002
|
|
561
577
|
chunk: Optional[Union[GenerationChunk, ChatGenerationChunk]], # noqa: ARG002
|
|
562
|
-
) -> Union[
|
|
563
|
-
"""Process new LLM token.
|
|
578
|
+
) -> Union[Coroutine[Any, Any, None], None]:
|
|
579
|
+
"""Process new LLM token.
|
|
580
|
+
|
|
581
|
+
Args:
|
|
582
|
+
run: The LLM run.
|
|
583
|
+
token: The new token.
|
|
584
|
+
chunk: Optional chunk.
|
|
585
|
+
"""
|
|
564
586
|
return None
|
|
565
587
|
|
|
566
|
-
def _on_llm_end(self, run: Run) -> Union[
|
|
567
|
-
"""Process the LLM Run.
|
|
588
|
+
def _on_llm_end(self, run: Run) -> Union[Coroutine[Any, Any, None], None]: # noqa: ARG002
|
|
589
|
+
"""Process the LLM Run.
|
|
590
|
+
|
|
591
|
+
Args:
|
|
592
|
+
run: The LLM run.
|
|
593
|
+
"""
|
|
568
594
|
return None
|
|
569
595
|
|
|
570
|
-
def _on_llm_error(self, run: Run) -> Union[
|
|
571
|
-
"""Process the LLM Run upon error.
|
|
596
|
+
def _on_llm_error(self, run: Run) -> Union[Coroutine[Any, Any, None], None]: # noqa: ARG002
|
|
597
|
+
"""Process the LLM Run upon error.
|
|
598
|
+
|
|
599
|
+
Args:
|
|
600
|
+
run: The LLM run.
|
|
601
|
+
"""
|
|
572
602
|
return None
|
|
573
603
|
|
|
574
|
-
def _on_chain_start(self, run: Run) -> Union[
|
|
575
|
-
"""Process the Chain Run upon start.
|
|
604
|
+
def _on_chain_start(self, run: Run) -> Union[Coroutine[Any, Any, None], None]: # noqa: ARG002
|
|
605
|
+
"""Process the Chain Run upon start.
|
|
606
|
+
|
|
607
|
+
Args:
|
|
608
|
+
run: The chain run.
|
|
609
|
+
"""
|
|
576
610
|
return None
|
|
577
611
|
|
|
578
|
-
def _on_chain_end(self, run: Run) -> Union[
|
|
579
|
-
"""Process the Chain Run.
|
|
612
|
+
def _on_chain_end(self, run: Run) -> Union[Coroutine[Any, Any, None], None]: # noqa: ARG002
|
|
613
|
+
"""Process the Chain Run.
|
|
614
|
+
|
|
615
|
+
Args:
|
|
616
|
+
run: The chain run.
|
|
617
|
+
"""
|
|
580
618
|
return None
|
|
581
619
|
|
|
582
|
-
def _on_chain_error(self, run: Run) -> Union[
|
|
583
|
-
"""Process the Chain Run upon error.
|
|
620
|
+
def _on_chain_error(self, run: Run) -> Union[Coroutine[Any, Any, None], None]: # noqa: ARG002
|
|
621
|
+
"""Process the Chain Run upon error.
|
|
622
|
+
|
|
623
|
+
Args:
|
|
624
|
+
run: The chain run.
|
|
625
|
+
"""
|
|
584
626
|
return None
|
|
585
627
|
|
|
586
|
-
def _on_tool_start(self, run: Run) -> Union[
|
|
587
|
-
"""Process the Tool Run upon start.
|
|
628
|
+
def _on_tool_start(self, run: Run) -> Union[Coroutine[Any, Any, None], None]: # noqa: ARG002
|
|
629
|
+
"""Process the Tool Run upon start.
|
|
630
|
+
|
|
631
|
+
Args:
|
|
632
|
+
run: The tool run.
|
|
633
|
+
"""
|
|
588
634
|
return None
|
|
589
635
|
|
|
590
|
-
def _on_tool_end(self, run: Run) -> Union[
|
|
591
|
-
"""Process the Tool Run.
|
|
636
|
+
def _on_tool_end(self, run: Run) -> Union[Coroutine[Any, Any, None], None]: # noqa: ARG002
|
|
637
|
+
"""Process the Tool Run.
|
|
638
|
+
|
|
639
|
+
Args:
|
|
640
|
+
run: The tool run.
|
|
641
|
+
"""
|
|
592
642
|
return None
|
|
593
643
|
|
|
594
|
-
def _on_tool_error(self, run: Run) -> Union[
|
|
595
|
-
"""Process the Tool Run upon error.
|
|
644
|
+
def _on_tool_error(self, run: Run) -> Union[Coroutine[Any, Any, None], None]: # noqa: ARG002
|
|
645
|
+
"""Process the Tool Run upon error.
|
|
646
|
+
|
|
647
|
+
Args:
|
|
648
|
+
run: The tool run.
|
|
649
|
+
"""
|
|
596
650
|
return None
|
|
597
651
|
|
|
598
|
-
def _on_chat_model_start(self, run: Run) -> Union[
|
|
599
|
-
"""Process the Chat Model Run upon start.
|
|
652
|
+
def _on_chat_model_start(self, run: Run) -> Union[Coroutine[Any, Any, None], None]: # noqa: ARG002
|
|
653
|
+
"""Process the Chat Model Run upon start.
|
|
654
|
+
|
|
655
|
+
Args:
|
|
656
|
+
run: The chat model run.
|
|
657
|
+
"""
|
|
600
658
|
return None
|
|
601
659
|
|
|
602
|
-
def _on_retriever_start(self, run: Run) -> Union[
|
|
603
|
-
"""Process the Retriever Run upon start.
|
|
660
|
+
def _on_retriever_start(self, run: Run) -> Union[Coroutine[Any, Any, None], None]: # noqa: ARG002
|
|
661
|
+
"""Process the Retriever Run upon start.
|
|
662
|
+
|
|
663
|
+
Args:
|
|
664
|
+
run: The retriever run.
|
|
665
|
+
"""
|
|
604
666
|
return None
|
|
605
667
|
|
|
606
|
-
def _on_retriever_end(self, run: Run) -> Union[
|
|
607
|
-
"""Process the Retriever Run.
|
|
668
|
+
def _on_retriever_end(self, run: Run) -> Union[Coroutine[Any, Any, None], None]: # noqa: ARG002
|
|
669
|
+
"""Process the Retriever Run.
|
|
670
|
+
|
|
671
|
+
Args:
|
|
672
|
+
run: The retriever run.
|
|
673
|
+
"""
|
|
608
674
|
return None
|
|
609
675
|
|
|
610
|
-
def _on_retriever_error(self, run: Run) -> Union[
|
|
611
|
-
"""Process the Retriever Run upon error.
|
|
676
|
+
def _on_retriever_error(self, run: Run) -> Union[Coroutine[Any, Any, None], None]: # noqa: ARG002
|
|
677
|
+
"""Process the Retriever Run upon error.
|
|
678
|
+
|
|
679
|
+
Args:
|
|
680
|
+
run: The retriever run.
|
|
681
|
+
"""
|
|
612
682
|
return None
|