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.

Files changed (172) hide show
  1. langchain_core/__init__.py +1 -1
  2. langchain_core/_api/__init__.py +3 -4
  3. langchain_core/_api/beta_decorator.py +45 -70
  4. langchain_core/_api/deprecation.py +80 -80
  5. langchain_core/_api/path.py +22 -8
  6. langchain_core/_import_utils.py +10 -4
  7. langchain_core/agents.py +25 -21
  8. langchain_core/caches.py +53 -63
  9. langchain_core/callbacks/__init__.py +1 -8
  10. langchain_core/callbacks/base.py +341 -348
  11. langchain_core/callbacks/file.py +55 -44
  12. langchain_core/callbacks/manager.py +546 -683
  13. langchain_core/callbacks/stdout.py +29 -30
  14. langchain_core/callbacks/streaming_stdout.py +35 -36
  15. langchain_core/callbacks/usage.py +65 -70
  16. langchain_core/chat_history.py +48 -55
  17. langchain_core/document_loaders/base.py +46 -21
  18. langchain_core/document_loaders/langsmith.py +39 -36
  19. langchain_core/documents/__init__.py +0 -1
  20. langchain_core/documents/base.py +96 -74
  21. langchain_core/documents/compressor.py +12 -9
  22. langchain_core/documents/transformers.py +29 -28
  23. langchain_core/embeddings/fake.py +56 -57
  24. langchain_core/env.py +2 -3
  25. langchain_core/example_selectors/base.py +12 -0
  26. langchain_core/example_selectors/length_based.py +1 -1
  27. langchain_core/example_selectors/semantic_similarity.py +21 -25
  28. langchain_core/exceptions.py +15 -9
  29. langchain_core/globals.py +4 -163
  30. langchain_core/indexing/api.py +132 -125
  31. langchain_core/indexing/base.py +64 -67
  32. langchain_core/indexing/in_memory.py +26 -6
  33. langchain_core/language_models/__init__.py +15 -27
  34. langchain_core/language_models/_utils.py +267 -117
  35. langchain_core/language_models/base.py +92 -177
  36. langchain_core/language_models/chat_models.py +547 -407
  37. langchain_core/language_models/fake.py +11 -11
  38. langchain_core/language_models/fake_chat_models.py +72 -118
  39. langchain_core/language_models/llms.py +168 -242
  40. langchain_core/load/dump.py +8 -11
  41. langchain_core/load/load.py +32 -28
  42. langchain_core/load/mapping.py +2 -4
  43. langchain_core/load/serializable.py +50 -56
  44. langchain_core/messages/__init__.py +36 -51
  45. langchain_core/messages/ai.py +377 -150
  46. langchain_core/messages/base.py +239 -47
  47. langchain_core/messages/block_translators/__init__.py +111 -0
  48. langchain_core/messages/block_translators/anthropic.py +470 -0
  49. langchain_core/messages/block_translators/bedrock.py +94 -0
  50. langchain_core/messages/block_translators/bedrock_converse.py +297 -0
  51. langchain_core/messages/block_translators/google_genai.py +530 -0
  52. langchain_core/messages/block_translators/google_vertexai.py +21 -0
  53. langchain_core/messages/block_translators/groq.py +143 -0
  54. langchain_core/messages/block_translators/langchain_v0.py +301 -0
  55. langchain_core/messages/block_translators/openai.py +1010 -0
  56. langchain_core/messages/chat.py +2 -3
  57. langchain_core/messages/content.py +1423 -0
  58. langchain_core/messages/function.py +7 -7
  59. langchain_core/messages/human.py +44 -38
  60. langchain_core/messages/modifier.py +3 -2
  61. langchain_core/messages/system.py +40 -27
  62. langchain_core/messages/tool.py +160 -58
  63. langchain_core/messages/utils.py +527 -638
  64. langchain_core/output_parsers/__init__.py +1 -14
  65. langchain_core/output_parsers/base.py +68 -104
  66. langchain_core/output_parsers/json.py +13 -17
  67. langchain_core/output_parsers/list.py +11 -33
  68. langchain_core/output_parsers/openai_functions.py +56 -74
  69. langchain_core/output_parsers/openai_tools.py +68 -109
  70. langchain_core/output_parsers/pydantic.py +15 -13
  71. langchain_core/output_parsers/string.py +6 -2
  72. langchain_core/output_parsers/transform.py +17 -60
  73. langchain_core/output_parsers/xml.py +34 -44
  74. langchain_core/outputs/__init__.py +1 -1
  75. langchain_core/outputs/chat_generation.py +26 -11
  76. langchain_core/outputs/chat_result.py +1 -3
  77. langchain_core/outputs/generation.py +17 -6
  78. langchain_core/outputs/llm_result.py +15 -8
  79. langchain_core/prompt_values.py +29 -123
  80. langchain_core/prompts/__init__.py +3 -27
  81. langchain_core/prompts/base.py +48 -63
  82. langchain_core/prompts/chat.py +259 -288
  83. langchain_core/prompts/dict.py +19 -11
  84. langchain_core/prompts/few_shot.py +84 -90
  85. langchain_core/prompts/few_shot_with_templates.py +14 -12
  86. langchain_core/prompts/image.py +19 -14
  87. langchain_core/prompts/loading.py +6 -8
  88. langchain_core/prompts/message.py +7 -8
  89. langchain_core/prompts/prompt.py +42 -43
  90. langchain_core/prompts/string.py +37 -16
  91. langchain_core/prompts/structured.py +43 -46
  92. langchain_core/rate_limiters.py +51 -60
  93. langchain_core/retrievers.py +52 -192
  94. langchain_core/runnables/base.py +1727 -1683
  95. langchain_core/runnables/branch.py +52 -73
  96. langchain_core/runnables/config.py +89 -103
  97. langchain_core/runnables/configurable.py +128 -130
  98. langchain_core/runnables/fallbacks.py +93 -82
  99. langchain_core/runnables/graph.py +127 -127
  100. langchain_core/runnables/graph_ascii.py +63 -41
  101. langchain_core/runnables/graph_mermaid.py +87 -70
  102. langchain_core/runnables/graph_png.py +31 -36
  103. langchain_core/runnables/history.py +145 -161
  104. langchain_core/runnables/passthrough.py +141 -144
  105. langchain_core/runnables/retry.py +84 -68
  106. langchain_core/runnables/router.py +33 -37
  107. langchain_core/runnables/schema.py +79 -72
  108. langchain_core/runnables/utils.py +95 -139
  109. langchain_core/stores.py +85 -131
  110. langchain_core/structured_query.py +11 -15
  111. langchain_core/sys_info.py +31 -32
  112. langchain_core/tools/__init__.py +1 -14
  113. langchain_core/tools/base.py +221 -247
  114. langchain_core/tools/convert.py +144 -161
  115. langchain_core/tools/render.py +10 -10
  116. langchain_core/tools/retriever.py +12 -19
  117. langchain_core/tools/simple.py +52 -29
  118. langchain_core/tools/structured.py +56 -60
  119. langchain_core/tracers/__init__.py +1 -9
  120. langchain_core/tracers/_streaming.py +6 -7
  121. langchain_core/tracers/base.py +103 -112
  122. langchain_core/tracers/context.py +29 -48
  123. langchain_core/tracers/core.py +142 -105
  124. langchain_core/tracers/evaluation.py +30 -34
  125. langchain_core/tracers/event_stream.py +162 -117
  126. langchain_core/tracers/langchain.py +34 -36
  127. langchain_core/tracers/log_stream.py +87 -49
  128. langchain_core/tracers/memory_stream.py +3 -3
  129. langchain_core/tracers/root_listeners.py +18 -34
  130. langchain_core/tracers/run_collector.py +8 -20
  131. langchain_core/tracers/schemas.py +0 -125
  132. langchain_core/tracers/stdout.py +3 -3
  133. langchain_core/utils/__init__.py +1 -4
  134. langchain_core/utils/_merge.py +47 -9
  135. langchain_core/utils/aiter.py +70 -66
  136. langchain_core/utils/env.py +12 -9
  137. langchain_core/utils/function_calling.py +139 -206
  138. langchain_core/utils/html.py +7 -8
  139. langchain_core/utils/input.py +6 -6
  140. langchain_core/utils/interactive_env.py +6 -2
  141. langchain_core/utils/iter.py +48 -45
  142. langchain_core/utils/json.py +14 -4
  143. langchain_core/utils/json_schema.py +159 -43
  144. langchain_core/utils/mustache.py +32 -25
  145. langchain_core/utils/pydantic.py +67 -40
  146. langchain_core/utils/strings.py +5 -5
  147. langchain_core/utils/usage.py +1 -1
  148. langchain_core/utils/utils.py +104 -62
  149. langchain_core/vectorstores/base.py +131 -179
  150. langchain_core/vectorstores/in_memory.py +113 -182
  151. langchain_core/vectorstores/utils.py +23 -17
  152. langchain_core/version.py +1 -1
  153. langchain_core-1.0.0.dist-info/METADATA +68 -0
  154. langchain_core-1.0.0.dist-info/RECORD +172 -0
  155. {langchain_core-0.4.0.dev0.dist-info → langchain_core-1.0.0.dist-info}/WHEEL +1 -1
  156. langchain_core/beta/__init__.py +0 -1
  157. langchain_core/beta/runnables/__init__.py +0 -1
  158. langchain_core/beta/runnables/context.py +0 -448
  159. langchain_core/memory.py +0 -116
  160. langchain_core/messages/content_blocks.py +0 -1435
  161. langchain_core/prompts/pipeline.py +0 -133
  162. langchain_core/pydantic_v1/__init__.py +0 -30
  163. langchain_core/pydantic_v1/dataclasses.py +0 -23
  164. langchain_core/pydantic_v1/main.py +0 -23
  165. langchain_core/tracers/langchain_v1.py +0 -23
  166. langchain_core/utils/loading.py +0 -31
  167. langchain_core/v1/__init__.py +0 -1
  168. langchain_core/v1/chat_models.py +0 -1047
  169. langchain_core/v1/messages.py +0 -755
  170. langchain_core-0.4.0.dev0.dist-info/METADATA +0 -108
  171. langchain_core-0.4.0.dev0.dist-info/RECORD +0 -177
  172. langchain_core-0.4.0.dev0.dist-info/entry_points.txt +0 -4
@@ -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: Optional[Callable[..., str]]
34
+ func: Callable[..., str] | None
38
35
  """The function to run when the tool is called."""
39
- coroutine: Optional[Callable[..., Awaitable[str]]] = None
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: Union[str, dict, ToolCall],
48
- config: Optional[RunnableConfig] = None,
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
- if isinstance(self.args_schema, dict):
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: Union[str, dict], tool_call_id: Optional[str]
70
+ self, tool_input: str | dict, tool_call_id: str | None
78
71
  ) -> tuple[tuple, dict]:
79
- """Convert tool input to pydantic model."""
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: Optional[CallbackManagerForToolRun] = None,
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: Optional[AsyncCallbackManagerForToolRun] = None,
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: Optional[Callable], description: str, **kwargs: Any
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: Optional[Callable],
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: Optional[ArgsSchema] = None,
145
- coroutine: Optional[
146
- Callable[..., Awaitable[Any]]
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. Defaults to False.
157
- args_schema: The schema of the tool's input arguments. Defaults to None.
158
- coroutine: The asynchronous version of the function. Defaults to None.
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: Optional[Callable[..., Any]] = None
44
+ func: Callable[..., Any] | None = None
48
45
  """The function to run when the tool is called."""
49
- coroutine: Optional[Callable[..., Awaitable[Any]]] = None
46
+ coroutine: Callable[..., Awaitable[Any]] | None = None
50
47
  """The asynchronous version of the function."""
51
48
 
52
49
  # --- Runnable ---
@@ -55,8 +52,8 @@ class StructuredTool(BaseTool):
55
52
  @override
56
53
  async def ainvoke(
57
54
  self,
58
- input: Union[str, dict, ToolCall],
59
- config: Optional[RunnableConfig] = None,
55
+ input: str | dict | ToolCall,
56
+ config: RunnableConfig | None = None,
60
57
  **kwargs: Any,
61
58
  ) -> Any:
62
59
  if not self.coroutine:
@@ -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: Optional[CallbackManagerForToolRun] = None,
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: Optional[AsyncCallbackManagerForToolRun] = None,
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: Optional[Callable] = None,
122
- coroutine: Optional[Callable[..., Awaitable[Any]]] = None,
123
- name: Optional[str] = None,
124
- description: Optional[str] = None,
128
+ func: Callable | None = None,
129
+ coroutine: Callable[..., Awaitable[Any]] | None = None,
130
+ name: str | None = None,
131
+ description: str | None = None,
125
132
  return_direct: bool = False, # noqa: FBT001,FBT002
126
- args_schema: Optional[ArgsSchema] = None,
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
- Defaults to False.
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
- Defaults to True.
150
- response_format: The tool response format. If "content" then the output of
151
- the tool is interpreted as the contents of a ToolMessage. If
152
- "content_and_artifact" then the output is expected to be a two-tuple
153
- corresponding to the (content, artifact) of a ToolMessage.
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
- Defaults to False.
158
- error_on_invalid_docstring: if ``parse_docstring`` is provided, configure
159
- whether to raise ValueError on invalid Google Style docstrings.
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
- .. code-block:: python
178
-
179
- def add(a: int, b: int) -> int:
180
- \"\"\"Add two numbers\"\"\"
181
- return a + b
182
- tool = StructuredTool.from_function(add)
183
- tool.run(1, 2) # 3
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, # type: ignore[arg-type]
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 abc
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
- class _StreamingCallbackHandler(abc.ABC):
12
- """For internal use.
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