langchain-core 1.0.0a8__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 +42 -57
- 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.0a8.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.0a8.dist-info/RECORD +0 -176
- {langchain_core-1.0.0a8.dist-info → langchain_core-1.0.0rc1.dist-info}/WHEEL +0 -0
|
@@ -15,10 +15,10 @@ from langchain_core.utils._merge import merge_dicts
|
|
|
15
15
|
class FunctionMessage(BaseMessage):
|
|
16
16
|
"""Message for passing the result of executing a tool back to a model.
|
|
17
17
|
|
|
18
|
-
|
|
19
|
-
do not contain the
|
|
18
|
+
`FunctionMessage` are an older version of the `ToolMessage` schema, and
|
|
19
|
+
do not contain the `tool_call_id` field.
|
|
20
20
|
|
|
21
|
-
The
|
|
21
|
+
The `tool_call_id` field is used to associate the tool call request with the
|
|
22
22
|
tool call response. This is useful in situations where a chat model is able
|
|
23
23
|
to request multiple tool calls in parallel.
|
|
24
24
|
|
|
@@ -28,7 +28,7 @@ class FunctionMessage(BaseMessage):
|
|
|
28
28
|
"""The name of the function that was executed."""
|
|
29
29
|
|
|
30
30
|
type: Literal["function"] = "function"
|
|
31
|
-
"""The type of the message (used for serialization). Defaults to
|
|
31
|
+
"""The type of the message (used for serialization). Defaults to `'function'`."""
|
|
32
32
|
|
|
33
33
|
|
|
34
34
|
class FunctionMessageChunk(FunctionMessage, BaseMessageChunk):
|
|
@@ -40,7 +40,7 @@ class FunctionMessageChunk(FunctionMessage, BaseMessageChunk):
|
|
|
40
40
|
type: Literal["FunctionMessageChunk"] = "FunctionMessageChunk" # type: ignore[assignment]
|
|
41
41
|
"""The type of the message (used for serialization).
|
|
42
42
|
|
|
43
|
-
Defaults to
|
|
43
|
+
Defaults to `'FunctionMessageChunk'`.
|
|
44
44
|
|
|
45
45
|
"""
|
|
46
46
|
|
langchain_core/messages/human.py
CHANGED
|
@@ -9,29 +9,27 @@ from langchain_core.messages.base import BaseMessage, BaseMessageChunk
|
|
|
9
9
|
class HumanMessage(BaseMessage):
|
|
10
10
|
"""Message from a human.
|
|
11
11
|
|
|
12
|
-
|
|
12
|
+
`HumanMessage`s are messages that are passed in from a human to the model.
|
|
13
13
|
|
|
14
14
|
Example:
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
print(model.invoke(messages))
|
|
28
|
-
|
|
15
|
+
```python
|
|
16
|
+
from langchain_core.messages import HumanMessage, SystemMessage
|
|
17
|
+
|
|
18
|
+
messages = [
|
|
19
|
+
SystemMessage(content="You are a helpful assistant! Your name is Bob."),
|
|
20
|
+
HumanMessage(content="What is your name?"),
|
|
21
|
+
]
|
|
22
|
+
|
|
23
|
+
# Instantiate a chat model and invoke it with the messages
|
|
24
|
+
model = ...
|
|
25
|
+
print(model.invoke(messages))
|
|
26
|
+
```
|
|
29
27
|
"""
|
|
30
28
|
|
|
31
29
|
type: Literal["human"] = "human"
|
|
32
30
|
"""The type of the message (used for serialization).
|
|
33
31
|
|
|
34
|
-
Defaults to
|
|
32
|
+
Defaults to `'human'`.
|
|
35
33
|
|
|
36
34
|
"""
|
|
37
35
|
|
|
@@ -56,7 +54,7 @@ class HumanMessage(BaseMessage):
|
|
|
56
54
|
content_blocks: list[types.ContentBlock] | None = None,
|
|
57
55
|
**kwargs: Any,
|
|
58
56
|
) -> None:
|
|
59
|
-
"""Specify
|
|
57
|
+
"""Specify `content` as positional arg or `content_blocks` for typing."""
|
|
60
58
|
if content_blocks is not None:
|
|
61
59
|
super().__init__(
|
|
62
60
|
content=cast("str | list[str | dict]", content_blocks),
|
|
@@ -20,7 +20,7 @@ class RemoveMessage(BaseMessage):
|
|
|
20
20
|
|
|
21
21
|
Args:
|
|
22
22
|
id: The ID of the message to remove.
|
|
23
|
-
kwargs: Additional fields to pass to the message.
|
|
23
|
+
**kwargs: Additional fields to pass to the message.
|
|
24
24
|
|
|
25
25
|
Raises:
|
|
26
26
|
ValueError: If the 'content' field is passed in kwargs.
|
|
@@ -13,25 +13,23 @@ class SystemMessage(BaseMessage):
|
|
|
13
13
|
of input messages.
|
|
14
14
|
|
|
15
15
|
Example:
|
|
16
|
+
```python
|
|
17
|
+
from langchain_core.messages import HumanMessage, SystemMessage
|
|
16
18
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
messages = [
|
|
22
|
-
SystemMessage(content="You are a helpful assistant! Your name is Bob."),
|
|
23
|
-
HumanMessage(content="What is your name?"),
|
|
24
|
-
]
|
|
25
|
-
|
|
26
|
-
# Define a chat model and invoke it with the messages
|
|
27
|
-
print(model.invoke(messages))
|
|
19
|
+
messages = [
|
|
20
|
+
SystemMessage(content="You are a helpful assistant! Your name is Bob."),
|
|
21
|
+
HumanMessage(content="What is your name?"),
|
|
22
|
+
]
|
|
28
23
|
|
|
24
|
+
# Define a chat model and invoke it with the messages
|
|
25
|
+
print(model.invoke(messages))
|
|
26
|
+
```
|
|
29
27
|
"""
|
|
30
28
|
|
|
31
29
|
type: Literal["system"] = "system"
|
|
32
30
|
"""The type of the message (used for serialization).
|
|
33
31
|
|
|
34
|
-
Defaults to
|
|
32
|
+
Defaults to `'system'`.
|
|
35
33
|
|
|
36
34
|
"""
|
|
37
35
|
|
|
@@ -56,7 +54,7 @@ class SystemMessage(BaseMessage):
|
|
|
56
54
|
content_blocks: list[types.ContentBlock] | None = None,
|
|
57
55
|
**kwargs: Any,
|
|
58
56
|
) -> None:
|
|
59
|
-
"""Specify
|
|
57
|
+
"""Specify `content` as positional arg or `content_blocks` for typing."""
|
|
60
58
|
if content_blocks is not None:
|
|
61
59
|
super().__init__(
|
|
62
60
|
content=cast("str | list[str | dict]", content_blocks),
|
|
@@ -75,6 +73,6 @@ class SystemMessageChunk(SystemMessage, BaseMessageChunk):
|
|
|
75
73
|
type: Literal["SystemMessageChunk"] = "SystemMessageChunk" # type: ignore[assignment]
|
|
76
74
|
"""The type of the message (used for serialization).
|
|
77
75
|
|
|
78
|
-
Defaults to
|
|
76
|
+
Defaults to `'SystemMessageChunk'`.
|
|
79
77
|
|
|
80
78
|
"""
|
langchain_core/messages/tool.py
CHANGED
|
@@ -16,9 +16,9 @@ from langchain_core.utils._merge import merge_dicts, merge_obj
|
|
|
16
16
|
class ToolOutputMixin:
|
|
17
17
|
"""Mixin for objects that tools can return directly.
|
|
18
18
|
|
|
19
|
-
If a custom BaseTool is invoked with a
|
|
20
|
-
not an instance of
|
|
21
|
-
a string and wrapped in a
|
|
19
|
+
If a custom BaseTool is invoked with a `ToolCall` and the output of custom code is
|
|
20
|
+
not an instance of `ToolOutputMixin`, the output will automatically be coerced to
|
|
21
|
+
a string and wrapped in a `ToolMessage`.
|
|
22
22
|
|
|
23
23
|
"""
|
|
24
24
|
|
|
@@ -26,41 +26,40 @@ class ToolOutputMixin:
|
|
|
26
26
|
class ToolMessage(BaseMessage, ToolOutputMixin):
|
|
27
27
|
"""Message for passing the result of executing a tool back to a model.
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
is encoded inside the
|
|
29
|
+
`ToolMessage` objects contain the result of a tool invocation. Typically, the result
|
|
30
|
+
is encoded inside the `content` field.
|
|
31
31
|
|
|
32
|
-
Example: A
|
|
32
|
+
Example: A `ToolMessage` representing a result of `42` from a tool call with id
|
|
33
33
|
|
|
34
|
-
|
|
34
|
+
```python
|
|
35
|
+
from langchain_core.messages import ToolMessage
|
|
35
36
|
|
|
36
|
-
|
|
37
|
+
ToolMessage(content="42", tool_call_id="call_Jja7J89XsjrOLA5r!MEOW!SL")
|
|
38
|
+
```
|
|
37
39
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
Example: A ``ToolMessage`` where only part of the tool output is sent to the model
|
|
40
|
+
Example: A `ToolMessage` where only part of the tool output is sent to the model
|
|
42
41
|
and the full output is passed in to artifact.
|
|
43
42
|
|
|
44
43
|
!!! version-added "Added in version 0.2.17"
|
|
45
44
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
from langchain_core.messages import ToolMessage
|
|
45
|
+
```python
|
|
46
|
+
from langchain_core.messages import ToolMessage
|
|
49
47
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
48
|
+
tool_output = {
|
|
49
|
+
"stdout": "From the graph we can see that the correlation between "
|
|
50
|
+
"x and y is ...",
|
|
51
|
+
"stderr": None,
|
|
52
|
+
"artifacts": {"type": "image", "base64_data": "/9j/4gIcSU..."},
|
|
53
|
+
}
|
|
56
54
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
55
|
+
ToolMessage(
|
|
56
|
+
content=tool_output["stdout"],
|
|
57
|
+
artifact=tool_output,
|
|
58
|
+
tool_call_id="call_Jja7J89XsjrOLA5r!MEOW!SL",
|
|
59
|
+
)
|
|
60
|
+
```
|
|
62
61
|
|
|
63
|
-
The
|
|
62
|
+
The `tool_call_id` field is used to associate the tool call request with the
|
|
64
63
|
tool call response. This is useful in situations where a chat model is able
|
|
65
64
|
to request multiple tool calls in parallel.
|
|
66
65
|
|
|
@@ -72,7 +71,7 @@ class ToolMessage(BaseMessage, ToolOutputMixin):
|
|
|
72
71
|
type: Literal["tool"] = "tool"
|
|
73
72
|
"""The type of the message (used for serialization).
|
|
74
73
|
|
|
75
|
-
Defaults to
|
|
74
|
+
Defaults to `'tool'`.
|
|
76
75
|
|
|
77
76
|
"""
|
|
78
77
|
|
|
@@ -165,9 +164,9 @@ class ToolMessage(BaseMessage, ToolOutputMixin):
|
|
|
165
164
|
content_blocks: list[types.ContentBlock] | None = None,
|
|
166
165
|
**kwargs: Any,
|
|
167
166
|
) -> None:
|
|
168
|
-
"""Initialize
|
|
167
|
+
"""Initialize `ToolMessage`.
|
|
169
168
|
|
|
170
|
-
Specify
|
|
169
|
+
Specify `content` as positional arg or `content_blocks` for typing.
|
|
171
170
|
|
|
172
171
|
Args:
|
|
173
172
|
content: The string contents of the message.
|
|
@@ -219,13 +218,12 @@ class ToolCall(TypedDict):
|
|
|
219
218
|
"""Represents a request to call a tool.
|
|
220
219
|
|
|
221
220
|
Example:
|
|
221
|
+
```python
|
|
222
|
+
{"name": "foo", "args": {"a": 1}, "id": "123"}
|
|
223
|
+
```
|
|
222
224
|
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
{"name": "foo", "args": {"a": 1}, "id": "123"}
|
|
226
|
-
|
|
227
|
-
This represents a request to call the tool named ``'foo'`` with arguments
|
|
228
|
-
``{"a": 1}`` and an identifier of ``'123'``.
|
|
225
|
+
This represents a request to call the tool named `'foo'` with arguments
|
|
226
|
+
`{"a": 1}` and an identifier of `'123'`.
|
|
229
227
|
|
|
230
228
|
"""
|
|
231
229
|
|
|
@@ -265,22 +263,20 @@ def tool_call(
|
|
|
265
263
|
class ToolCallChunk(TypedDict):
|
|
266
264
|
"""A chunk of a tool call (e.g., as part of a stream).
|
|
267
265
|
|
|
268
|
-
When merging
|
|
266
|
+
When merging `ToolCallChunk`s (e.g., via `AIMessageChunk.__add__`),
|
|
269
267
|
all string attributes are concatenated. Chunks are only merged if their
|
|
270
|
-
values of
|
|
268
|
+
values of `index` are equal and not None.
|
|
271
269
|
|
|
272
270
|
Example:
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
(
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
).tool_call_chunks == [ToolCallChunk(name="foo", args='{"a":1}', index=0)]
|
|
283
|
-
|
|
271
|
+
```python
|
|
272
|
+
left_chunks = [ToolCallChunk(name="foo", args='{"a":', index=0)]
|
|
273
|
+
right_chunks = [ToolCallChunk(name=None, args="1}", index=0)]
|
|
274
|
+
|
|
275
|
+
(
|
|
276
|
+
AIMessageChunk(content="", tool_call_chunks=left_chunks)
|
|
277
|
+
+ AIMessageChunk(content="", tool_call_chunks=right_chunks)
|
|
278
|
+
).tool_call_chunks == [ToolCallChunk(name="foo", args='{"a":1}', index=0)]
|
|
279
|
+
```
|
|
284
280
|
"""
|
|
285
281
|
|
|
286
282
|
name: str | None
|