langchain-core 0.4.0.dev0__py3-none-any.whl → 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of langchain-core might be problematic. Click here for more details.
- langchain_core/__init__.py +1 -1
- langchain_core/_api/__init__.py +3 -4
- langchain_core/_api/beta_decorator.py +45 -70
- langchain_core/_api/deprecation.py +80 -80
- langchain_core/_api/path.py +22 -8
- langchain_core/_import_utils.py +10 -4
- langchain_core/agents.py +25 -21
- langchain_core/caches.py +53 -63
- langchain_core/callbacks/__init__.py +1 -8
- langchain_core/callbacks/base.py +341 -348
- langchain_core/callbacks/file.py +55 -44
- langchain_core/callbacks/manager.py +546 -683
- langchain_core/callbacks/stdout.py +29 -30
- langchain_core/callbacks/streaming_stdout.py +35 -36
- langchain_core/callbacks/usage.py +65 -70
- langchain_core/chat_history.py +48 -55
- langchain_core/document_loaders/base.py +46 -21
- langchain_core/document_loaders/langsmith.py +39 -36
- langchain_core/documents/__init__.py +0 -1
- langchain_core/documents/base.py +96 -74
- langchain_core/documents/compressor.py +12 -9
- langchain_core/documents/transformers.py +29 -28
- langchain_core/embeddings/fake.py +56 -57
- langchain_core/env.py +2 -3
- langchain_core/example_selectors/base.py +12 -0
- langchain_core/example_selectors/length_based.py +1 -1
- langchain_core/example_selectors/semantic_similarity.py +21 -25
- langchain_core/exceptions.py +15 -9
- langchain_core/globals.py +4 -163
- langchain_core/indexing/api.py +132 -125
- langchain_core/indexing/base.py +64 -67
- langchain_core/indexing/in_memory.py +26 -6
- langchain_core/language_models/__init__.py +15 -27
- langchain_core/language_models/_utils.py +267 -117
- langchain_core/language_models/base.py +92 -177
- langchain_core/language_models/chat_models.py +547 -407
- langchain_core/language_models/fake.py +11 -11
- langchain_core/language_models/fake_chat_models.py +72 -118
- langchain_core/language_models/llms.py +168 -242
- langchain_core/load/dump.py +8 -11
- langchain_core/load/load.py +32 -28
- langchain_core/load/mapping.py +2 -4
- langchain_core/load/serializable.py +50 -56
- langchain_core/messages/__init__.py +36 -51
- langchain_core/messages/ai.py +377 -150
- langchain_core/messages/base.py +239 -47
- langchain_core/messages/block_translators/__init__.py +111 -0
- langchain_core/messages/block_translators/anthropic.py +470 -0
- langchain_core/messages/block_translators/bedrock.py +94 -0
- langchain_core/messages/block_translators/bedrock_converse.py +297 -0
- langchain_core/messages/block_translators/google_genai.py +530 -0
- langchain_core/messages/block_translators/google_vertexai.py +21 -0
- langchain_core/messages/block_translators/groq.py +143 -0
- langchain_core/messages/block_translators/langchain_v0.py +301 -0
- langchain_core/messages/block_translators/openai.py +1010 -0
- langchain_core/messages/chat.py +2 -3
- langchain_core/messages/content.py +1423 -0
- langchain_core/messages/function.py +7 -7
- langchain_core/messages/human.py +44 -38
- langchain_core/messages/modifier.py +3 -2
- langchain_core/messages/system.py +40 -27
- langchain_core/messages/tool.py +160 -58
- langchain_core/messages/utils.py +527 -638
- langchain_core/output_parsers/__init__.py +1 -14
- langchain_core/output_parsers/base.py +68 -104
- langchain_core/output_parsers/json.py +13 -17
- langchain_core/output_parsers/list.py +11 -33
- langchain_core/output_parsers/openai_functions.py +56 -74
- langchain_core/output_parsers/openai_tools.py +68 -109
- langchain_core/output_parsers/pydantic.py +15 -13
- langchain_core/output_parsers/string.py +6 -2
- langchain_core/output_parsers/transform.py +17 -60
- langchain_core/output_parsers/xml.py +34 -44
- langchain_core/outputs/__init__.py +1 -1
- langchain_core/outputs/chat_generation.py +26 -11
- langchain_core/outputs/chat_result.py +1 -3
- langchain_core/outputs/generation.py +17 -6
- langchain_core/outputs/llm_result.py +15 -8
- langchain_core/prompt_values.py +29 -123
- langchain_core/prompts/__init__.py +3 -27
- langchain_core/prompts/base.py +48 -63
- langchain_core/prompts/chat.py +259 -288
- langchain_core/prompts/dict.py +19 -11
- langchain_core/prompts/few_shot.py +84 -90
- langchain_core/prompts/few_shot_with_templates.py +14 -12
- langchain_core/prompts/image.py +19 -14
- langchain_core/prompts/loading.py +6 -8
- langchain_core/prompts/message.py +7 -8
- langchain_core/prompts/prompt.py +42 -43
- langchain_core/prompts/string.py +37 -16
- langchain_core/prompts/structured.py +43 -46
- langchain_core/rate_limiters.py +51 -60
- langchain_core/retrievers.py +52 -192
- langchain_core/runnables/base.py +1727 -1683
- langchain_core/runnables/branch.py +52 -73
- langchain_core/runnables/config.py +89 -103
- langchain_core/runnables/configurable.py +128 -130
- langchain_core/runnables/fallbacks.py +93 -82
- langchain_core/runnables/graph.py +127 -127
- langchain_core/runnables/graph_ascii.py +63 -41
- langchain_core/runnables/graph_mermaid.py +87 -70
- langchain_core/runnables/graph_png.py +31 -36
- langchain_core/runnables/history.py +145 -161
- langchain_core/runnables/passthrough.py +141 -144
- langchain_core/runnables/retry.py +84 -68
- langchain_core/runnables/router.py +33 -37
- langchain_core/runnables/schema.py +79 -72
- langchain_core/runnables/utils.py +95 -139
- langchain_core/stores.py +85 -131
- langchain_core/structured_query.py +11 -15
- langchain_core/sys_info.py +31 -32
- langchain_core/tools/__init__.py +1 -14
- langchain_core/tools/base.py +221 -247
- langchain_core/tools/convert.py +144 -161
- langchain_core/tools/render.py +10 -10
- langchain_core/tools/retriever.py +12 -19
- langchain_core/tools/simple.py +52 -29
- langchain_core/tools/structured.py +56 -60
- langchain_core/tracers/__init__.py +1 -9
- langchain_core/tracers/_streaming.py +6 -7
- langchain_core/tracers/base.py +103 -112
- langchain_core/tracers/context.py +29 -48
- langchain_core/tracers/core.py +142 -105
- langchain_core/tracers/evaluation.py +30 -34
- langchain_core/tracers/event_stream.py +162 -117
- langchain_core/tracers/langchain.py +34 -36
- langchain_core/tracers/log_stream.py +87 -49
- langchain_core/tracers/memory_stream.py +3 -3
- langchain_core/tracers/root_listeners.py +18 -34
- langchain_core/tracers/run_collector.py +8 -20
- langchain_core/tracers/schemas.py +0 -125
- langchain_core/tracers/stdout.py +3 -3
- langchain_core/utils/__init__.py +1 -4
- langchain_core/utils/_merge.py +47 -9
- langchain_core/utils/aiter.py +70 -66
- langchain_core/utils/env.py +12 -9
- langchain_core/utils/function_calling.py +139 -206
- langchain_core/utils/html.py +7 -8
- langchain_core/utils/input.py +6 -6
- langchain_core/utils/interactive_env.py +6 -2
- langchain_core/utils/iter.py +48 -45
- langchain_core/utils/json.py +14 -4
- langchain_core/utils/json_schema.py +159 -43
- langchain_core/utils/mustache.py +32 -25
- langchain_core/utils/pydantic.py +67 -40
- langchain_core/utils/strings.py +5 -5
- langchain_core/utils/usage.py +1 -1
- langchain_core/utils/utils.py +104 -62
- langchain_core/vectorstores/base.py +131 -179
- langchain_core/vectorstores/in_memory.py +113 -182
- langchain_core/vectorstores/utils.py +23 -17
- langchain_core/version.py +1 -1
- langchain_core-1.0.0.dist-info/METADATA +68 -0
- langchain_core-1.0.0.dist-info/RECORD +172 -0
- {langchain_core-0.4.0.dev0.dist-info → langchain_core-1.0.0.dist-info}/WHEEL +1 -1
- langchain_core/beta/__init__.py +0 -1
- langchain_core/beta/runnables/__init__.py +0 -1
- langchain_core/beta/runnables/context.py +0 -448
- langchain_core/memory.py +0 -116
- langchain_core/messages/content_blocks.py +0 -1435
- langchain_core/prompts/pipeline.py +0 -133
- 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/tracers/langchain_v1.py +0 -23
- langchain_core/utils/loading.py +0 -31
- langchain_core/v1/__init__.py +0 -1
- langchain_core/v1/chat_models.py +0 -1047
- langchain_core/v1/messages.py +0 -755
- langchain_core-0.4.0.dev0.dist-info/METADATA +0 -108
- langchain_core-0.4.0.dev0.dist-info/RECORD +0 -177
- langchain_core-0.4.0.dev0.dist-info/entry_points.txt +0 -4
langchain_core/tools/simple.py
CHANGED
|
@@ -2,14 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
|
-
from collections.abc import Awaitable
|
|
5
|
+
from collections.abc import Awaitable, Callable
|
|
6
6
|
from inspect import signature
|
|
7
7
|
from typing import (
|
|
8
8
|
TYPE_CHECKING,
|
|
9
9
|
Any,
|
|
10
|
-
Callable,
|
|
11
|
-
Optional,
|
|
12
|
-
Union,
|
|
13
10
|
)
|
|
14
11
|
|
|
15
12
|
from typing_extensions import override
|
|
@@ -34,9 +31,9 @@ class Tool(BaseTool):
|
|
|
34
31
|
"""Tool that takes in function or coroutine directly."""
|
|
35
32
|
|
|
36
33
|
description: str = ""
|
|
37
|
-
func:
|
|
34
|
+
func: Callable[..., str] | None
|
|
38
35
|
"""The function to run when the tool is called."""
|
|
39
|
-
coroutine:
|
|
36
|
+
coroutine: Callable[..., Awaitable[str]] | None = None
|
|
40
37
|
"""The asynchronous version of the function."""
|
|
41
38
|
|
|
42
39
|
# --- Runnable ---
|
|
@@ -44,8 +41,8 @@ class Tool(BaseTool):
|
|
|
44
41
|
@override
|
|
45
42
|
async def ainvoke(
|
|
46
43
|
self,
|
|
47
|
-
input:
|
|
48
|
-
config:
|
|
44
|
+
input: str | dict | ToolCall,
|
|
45
|
+
config: RunnableConfig | None = None,
|
|
49
46
|
**kwargs: Any,
|
|
50
47
|
) -> Any:
|
|
51
48
|
if not self.coroutine:
|
|
@@ -64,19 +61,26 @@ class Tool(BaseTool):
|
|
|
64
61
|
The input arguments for the tool.
|
|
65
62
|
"""
|
|
66
63
|
if self.args_schema is not None:
|
|
67
|
-
|
|
68
|
-
json_schema = self.args_schema
|
|
69
|
-
else:
|
|
70
|
-
json_schema = self.args_schema.model_json_schema()
|
|
71
|
-
return json_schema["properties"]
|
|
64
|
+
return super().args
|
|
72
65
|
# For backwards compatibility, if the function signature is ambiguous,
|
|
73
66
|
# assume it takes a single string input.
|
|
74
67
|
return {"tool_input": {"type": "string"}}
|
|
75
68
|
|
|
76
69
|
def _to_args_and_kwargs(
|
|
77
|
-
self, tool_input:
|
|
70
|
+
self, tool_input: str | dict, tool_call_id: str | None
|
|
78
71
|
) -> tuple[tuple, dict]:
|
|
79
|
-
"""Convert tool input to
|
|
72
|
+
"""Convert tool input to Pydantic model.
|
|
73
|
+
|
|
74
|
+
Args:
|
|
75
|
+
tool_input: The input to the tool.
|
|
76
|
+
tool_call_id: The ID of the tool call.
|
|
77
|
+
|
|
78
|
+
Raises:
|
|
79
|
+
ToolException: If the tool input is invalid.
|
|
80
|
+
|
|
81
|
+
Returns:
|
|
82
|
+
The Pydantic model args and kwargs.
|
|
83
|
+
"""
|
|
80
84
|
args, kwargs = super()._to_args_and_kwargs(tool_input, tool_call_id)
|
|
81
85
|
# For backwards compatibility. The tool must be run with a single input
|
|
82
86
|
all_args = list(args) + list(kwargs.values())
|
|
@@ -93,10 +97,20 @@ class Tool(BaseTool):
|
|
|
93
97
|
self,
|
|
94
98
|
*args: Any,
|
|
95
99
|
config: RunnableConfig,
|
|
96
|
-
run_manager:
|
|
100
|
+
run_manager: CallbackManagerForToolRun | None = None,
|
|
97
101
|
**kwargs: Any,
|
|
98
102
|
) -> Any:
|
|
99
|
-
"""Use the tool.
|
|
103
|
+
"""Use the tool.
|
|
104
|
+
|
|
105
|
+
Args:
|
|
106
|
+
*args: Positional arguments to pass to the tool
|
|
107
|
+
config: Configuration for the run
|
|
108
|
+
run_manager: Optional callback manager to use for the run
|
|
109
|
+
**kwargs: Keyword arguments to pass to the tool
|
|
110
|
+
|
|
111
|
+
Returns:
|
|
112
|
+
The result of the tool execution
|
|
113
|
+
"""
|
|
100
114
|
if self.func:
|
|
101
115
|
if run_manager and signature(self.func).parameters.get("callbacks"):
|
|
102
116
|
kwargs["callbacks"] = run_manager.get_child()
|
|
@@ -110,10 +124,20 @@ class Tool(BaseTool):
|
|
|
110
124
|
self,
|
|
111
125
|
*args: Any,
|
|
112
126
|
config: RunnableConfig,
|
|
113
|
-
run_manager:
|
|
127
|
+
run_manager: AsyncCallbackManagerForToolRun | None = None,
|
|
114
128
|
**kwargs: Any,
|
|
115
129
|
) -> Any:
|
|
116
|
-
"""Use the tool asynchronously.
|
|
130
|
+
"""Use the tool asynchronously.
|
|
131
|
+
|
|
132
|
+
Args:
|
|
133
|
+
*args: Positional arguments to pass to the tool
|
|
134
|
+
config: Configuration for the run
|
|
135
|
+
run_manager: Optional callback manager to use for the run
|
|
136
|
+
**kwargs: Keyword arguments to pass to the tool
|
|
137
|
+
|
|
138
|
+
Returns:
|
|
139
|
+
The result of the tool execution
|
|
140
|
+
"""
|
|
117
141
|
if self.coroutine:
|
|
118
142
|
if run_manager and signature(self.coroutine).parameters.get("callbacks"):
|
|
119
143
|
kwargs["callbacks"] = run_manager.get_child()
|
|
@@ -129,7 +153,7 @@ class Tool(BaseTool):
|
|
|
129
153
|
|
|
130
154
|
# TODO: this is for backwards compatibility, remove in future
|
|
131
155
|
def __init__(
|
|
132
|
-
self, name: str, func:
|
|
156
|
+
self, name: str, func: Callable | None, description: str, **kwargs: Any
|
|
133
157
|
) -> None:
|
|
134
158
|
"""Initialize tool."""
|
|
135
159
|
super().__init__(name=name, func=func, description=description, **kwargs)
|
|
@@ -137,14 +161,13 @@ class Tool(BaseTool):
|
|
|
137
161
|
@classmethod
|
|
138
162
|
def from_function(
|
|
139
163
|
cls,
|
|
140
|
-
func:
|
|
164
|
+
func: Callable | None,
|
|
141
165
|
name: str, # We keep these required to support backwards compatibility
|
|
142
166
|
description: str,
|
|
143
167
|
return_direct: bool = False, # noqa: FBT001,FBT002
|
|
144
|
-
args_schema:
|
|
145
|
-
coroutine:
|
|
146
|
-
|
|
147
|
-
] = None, # This is last for compatibility, but should be after func
|
|
168
|
+
args_schema: ArgsSchema | None = None,
|
|
169
|
+
coroutine: Callable[..., Awaitable[Any]]
|
|
170
|
+
| None = None, # This is last for compatibility, but should be after func
|
|
148
171
|
**kwargs: Any,
|
|
149
172
|
) -> Tool:
|
|
150
173
|
"""Initialize tool from a function.
|
|
@@ -153,10 +176,10 @@ class Tool(BaseTool):
|
|
|
153
176
|
func: The function to create the tool from.
|
|
154
177
|
name: The name of the tool.
|
|
155
178
|
description: The description of the tool.
|
|
156
|
-
return_direct: Whether to return the output directly.
|
|
157
|
-
args_schema: The schema of the tool's input arguments.
|
|
158
|
-
coroutine: The asynchronous version of the function.
|
|
159
|
-
kwargs: Additional arguments to pass to the tool.
|
|
179
|
+
return_direct: Whether to return the output directly.
|
|
180
|
+
args_schema: The schema of the tool's input arguments.
|
|
181
|
+
coroutine: The asynchronous version of the function.
|
|
182
|
+
**kwargs: Additional arguments to pass to the tool.
|
|
160
183
|
|
|
161
184
|
Returns:
|
|
162
185
|
The tool.
|
|
@@ -3,16 +3,13 @@
|
|
|
3
3
|
from __future__ import annotations
|
|
4
4
|
|
|
5
5
|
import textwrap
|
|
6
|
-
from collections.abc import Awaitable
|
|
6
|
+
from collections.abc import Awaitable, Callable
|
|
7
7
|
from inspect import signature
|
|
8
8
|
from typing import (
|
|
9
9
|
TYPE_CHECKING,
|
|
10
10
|
Annotated,
|
|
11
11
|
Any,
|
|
12
|
-
Callable,
|
|
13
12
|
Literal,
|
|
14
|
-
Optional,
|
|
15
|
-
Union,
|
|
16
13
|
)
|
|
17
14
|
|
|
18
15
|
from pydantic import Field, SkipValidation
|
|
@@ -44,9 +41,9 @@ class StructuredTool(BaseTool):
|
|
|
44
41
|
..., description="The tool schema."
|
|
45
42
|
)
|
|
46
43
|
"""The input arguments' schema."""
|
|
47
|
-
func:
|
|
44
|
+
func: Callable[..., Any] | None = None
|
|
48
45
|
"""The function to run when the tool is called."""
|
|
49
|
-
coroutine:
|
|
46
|
+
coroutine: Callable[..., Awaitable[Any]] | None = None
|
|
50
47
|
"""The asynchronous version of the function."""
|
|
51
48
|
|
|
52
49
|
# --- Runnable ---
|
|
@@ -55,8 +52,8 @@ class StructuredTool(BaseTool):
|
|
|
55
52
|
@override
|
|
56
53
|
async def ainvoke(
|
|
57
54
|
self,
|
|
58
|
-
input:
|
|
59
|
-
config:
|
|
55
|
+
input: str | dict | ToolCall,
|
|
56
|
+
config: RunnableConfig | None = None,
|
|
60
57
|
**kwargs: Any,
|
|
61
58
|
) -> Any:
|
|
62
59
|
if not self.coroutine:
|
|
@@ -67,24 +64,24 @@ class StructuredTool(BaseTool):
|
|
|
67
64
|
|
|
68
65
|
# --- Tool ---
|
|
69
66
|
|
|
70
|
-
@property
|
|
71
|
-
def args(self) -> dict:
|
|
72
|
-
"""The tool's input arguments."""
|
|
73
|
-
if isinstance(self.args_schema, dict):
|
|
74
|
-
json_schema = self.args_schema
|
|
75
|
-
else:
|
|
76
|
-
input_schema = self.get_input_schema()
|
|
77
|
-
json_schema = input_schema.model_json_schema()
|
|
78
|
-
return json_schema["properties"]
|
|
79
|
-
|
|
80
67
|
def _run(
|
|
81
68
|
self,
|
|
82
69
|
*args: Any,
|
|
83
70
|
config: RunnableConfig,
|
|
84
|
-
run_manager:
|
|
71
|
+
run_manager: CallbackManagerForToolRun | None = None,
|
|
85
72
|
**kwargs: Any,
|
|
86
73
|
) -> Any:
|
|
87
|
-
"""Use the tool.
|
|
74
|
+
"""Use the tool.
|
|
75
|
+
|
|
76
|
+
Args:
|
|
77
|
+
*args: Positional arguments to pass to the tool
|
|
78
|
+
config: Configuration for the run
|
|
79
|
+
run_manager: Optional callback manager to use for the run
|
|
80
|
+
**kwargs: Keyword arguments to pass to the tool
|
|
81
|
+
|
|
82
|
+
Returns:
|
|
83
|
+
The result of the tool execution
|
|
84
|
+
"""
|
|
88
85
|
if self.func:
|
|
89
86
|
if run_manager and signature(self.func).parameters.get("callbacks"):
|
|
90
87
|
kwargs["callbacks"] = run_manager.get_child()
|
|
@@ -98,10 +95,20 @@ class StructuredTool(BaseTool):
|
|
|
98
95
|
self,
|
|
99
96
|
*args: Any,
|
|
100
97
|
config: RunnableConfig,
|
|
101
|
-
run_manager:
|
|
98
|
+
run_manager: AsyncCallbackManagerForToolRun | None = None,
|
|
102
99
|
**kwargs: Any,
|
|
103
100
|
) -> Any:
|
|
104
|
-
"""Use the tool asynchronously.
|
|
101
|
+
"""Use the tool asynchronously.
|
|
102
|
+
|
|
103
|
+
Args:
|
|
104
|
+
*args: Positional arguments to pass to the tool
|
|
105
|
+
config: Configuration for the run
|
|
106
|
+
run_manager: Optional callback manager to use for the run
|
|
107
|
+
**kwargs: Keyword arguments to pass to the tool
|
|
108
|
+
|
|
109
|
+
Returns:
|
|
110
|
+
The result of the tool execution
|
|
111
|
+
"""
|
|
105
112
|
if self.coroutine:
|
|
106
113
|
if run_manager and signature(self.coroutine).parameters.get("callbacks"):
|
|
107
114
|
kwargs["callbacks"] = run_manager.get_child()
|
|
@@ -118,18 +125,17 @@ class StructuredTool(BaseTool):
|
|
|
118
125
|
@classmethod
|
|
119
126
|
def from_function(
|
|
120
127
|
cls,
|
|
121
|
-
func:
|
|
122
|
-
coroutine:
|
|
123
|
-
name:
|
|
124
|
-
description:
|
|
128
|
+
func: Callable | None = None,
|
|
129
|
+
coroutine: Callable[..., Awaitable[Any]] | None = None,
|
|
130
|
+
name: str | None = None,
|
|
131
|
+
description: str | None = None,
|
|
125
132
|
return_direct: bool = False, # noqa: FBT001,FBT002
|
|
126
|
-
args_schema:
|
|
133
|
+
args_schema: ArgsSchema | None = None,
|
|
127
134
|
infer_schema: bool = True, # noqa: FBT001,FBT002
|
|
128
135
|
*,
|
|
129
136
|
response_format: Literal["content", "content_and_artifact"] = "content",
|
|
130
137
|
parse_docstring: bool = False,
|
|
131
138
|
error_on_invalid_docstring: bool = False,
|
|
132
|
-
message_version: Literal["v0", "v1"] = "v0",
|
|
133
139
|
**kwargs: Any,
|
|
134
140
|
) -> StructuredTool:
|
|
135
141
|
"""Create tool from a given function.
|
|
@@ -143,46 +149,37 @@ class StructuredTool(BaseTool):
|
|
|
143
149
|
description: The description of the tool.
|
|
144
150
|
Defaults to the function docstring.
|
|
145
151
|
return_direct: Whether to return the result directly or as a callback.
|
|
146
|
-
|
|
147
|
-
args_schema: The schema of the tool's input arguments. Defaults to None.
|
|
152
|
+
args_schema: The schema of the tool's input arguments.
|
|
148
153
|
infer_schema: Whether to infer the schema from the function's signature.
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
the
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
Defaults to "content".
|
|
155
|
-
parse_docstring: if ``infer_schema`` and ``parse_docstring``, will attempt
|
|
154
|
+
response_format: The tool response format. If `"content"` then the output of
|
|
155
|
+
the tool is interpreted as the contents of a `ToolMessage`. If
|
|
156
|
+
`"content_and_artifact"` then the output is expected to be a two-tuple
|
|
157
|
+
corresponding to the `(content, artifact)` of a `ToolMessage`.
|
|
158
|
+
parse_docstring: if `infer_schema` and `parse_docstring`, will attempt
|
|
156
159
|
to parse parameter descriptions from Google Style function docstrings.
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
Defaults to False.
|
|
161
|
-
message_version: Version of ToolMessage to return given
|
|
162
|
-
:class:`~langchain_core.messages.content_blocks.ToolCall` input.
|
|
163
|
-
|
|
164
|
-
If ``"v0"``, output will be a v0 :class:`~langchain_core.messages.tool.ToolMessage`.
|
|
165
|
-
If ``"v1"``, output will be a v1 :class:`~langchain_core.messages.v1.ToolMessage`.
|
|
166
|
-
|
|
167
|
-
kwargs: Additional arguments to pass to the tool
|
|
160
|
+
error_on_invalid_docstring: if `parse_docstring` is provided, configure
|
|
161
|
+
whether to raise `ValueError` on invalid Google Style docstrings.
|
|
162
|
+
**kwargs: Additional arguments to pass to the tool
|
|
168
163
|
|
|
169
164
|
Returns:
|
|
170
165
|
The tool.
|
|
171
166
|
|
|
172
167
|
Raises:
|
|
173
168
|
ValueError: If the function is not provided.
|
|
169
|
+
ValueError: If the function does not have a docstring and description
|
|
170
|
+
is not provided.
|
|
171
|
+
TypeError: If the `args_schema` is not a `BaseModel` or dict.
|
|
174
172
|
|
|
175
173
|
Examples:
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
""" # noqa: E501
|
|
174
|
+
```python
|
|
175
|
+
def add(a: int, b: int) -> int:
|
|
176
|
+
\"\"\"Add two numbers\"\"\"
|
|
177
|
+
return a + b
|
|
178
|
+
tool = StructuredTool.from_function(add)
|
|
179
|
+
tool.run(1, 2) # 3
|
|
180
|
+
|
|
181
|
+
```
|
|
182
|
+
"""
|
|
186
183
|
if func is not None:
|
|
187
184
|
source_function = func
|
|
188
185
|
elif coroutine is not None:
|
|
@@ -235,11 +232,10 @@ class StructuredTool(BaseTool):
|
|
|
235
232
|
name=name,
|
|
236
233
|
func=func,
|
|
237
234
|
coroutine=coroutine,
|
|
238
|
-
args_schema=args_schema,
|
|
235
|
+
args_schema=args_schema,
|
|
239
236
|
description=description_,
|
|
240
237
|
return_direct=return_direct,
|
|
241
238
|
response_format=response_format,
|
|
242
|
-
message_version=message_version,
|
|
243
239
|
**kwargs,
|
|
244
240
|
)
|
|
245
241
|
|
|
@@ -1,12 +1,4 @@
|
|
|
1
|
-
"""**Tracers** are classes for tracing runs.
|
|
2
|
-
|
|
3
|
-
**Class hierarchy:**
|
|
4
|
-
|
|
5
|
-
.. code-block::
|
|
6
|
-
|
|
7
|
-
BaseCallbackHandler --> BaseTracer --> <name>Tracer # Examples: LangChainTracer, RootListenersTracer
|
|
8
|
-
--> <name> # Examples: LogStreamCallbackHandler
|
|
9
|
-
""" # noqa: E501
|
|
1
|
+
"""**Tracers** are classes for tracing runs."""
|
|
10
2
|
|
|
11
3
|
from typing import TYPE_CHECKING
|
|
12
4
|
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
"""Internal tracers used for stream_log and astream events implementations."""
|
|
2
2
|
|
|
3
|
-
import
|
|
3
|
+
import typing
|
|
4
4
|
from collections.abc import AsyncIterator, Iterator
|
|
5
|
-
from typing import TypeVar
|
|
6
5
|
from uuid import UUID
|
|
7
6
|
|
|
8
|
-
T = TypeVar("T")
|
|
7
|
+
T = typing.TypeVar("T")
|
|
9
8
|
|
|
10
9
|
|
|
11
|
-
|
|
12
|
-
|
|
10
|
+
# THIS IS USED IN LANGGRAPH.
|
|
11
|
+
@typing.runtime_checkable
|
|
12
|
+
class _StreamingCallbackHandler(typing.Protocol[T]):
|
|
13
|
+
"""Types for streaming callback handlers.
|
|
13
14
|
|
|
14
15
|
This is a common mixin that the callback handlers
|
|
15
16
|
for both astream events and astream log inherit from.
|
|
@@ -18,13 +19,11 @@ class _StreamingCallbackHandler(abc.ABC):
|
|
|
18
19
|
to produce callbacks for intermediate results.
|
|
19
20
|
"""
|
|
20
21
|
|
|
21
|
-
@abc.abstractmethod
|
|
22
22
|
def tap_output_aiter(
|
|
23
23
|
self, run_id: UUID, output: AsyncIterator[T]
|
|
24
24
|
) -> AsyncIterator[T]:
|
|
25
25
|
"""Used for internal astream_log and astream events implementations."""
|
|
26
26
|
|
|
27
|
-
@abc.abstractmethod
|
|
28
27
|
def tap_output_iter(self, run_id: UUID, output: Iterator[T]) -> Iterator[T]:
|
|
29
28
|
"""Used for internal astream_log and astream events implementations."""
|
|
30
29
|
|