langchain 1.0.0a12__py3-none-any.whl → 1.0.0a14__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 might be problematic. Click here for more details.

Files changed (40) hide show
  1. langchain/__init__.py +1 -1
  2. langchain/agents/factory.py +597 -171
  3. langchain/agents/middleware/__init__.py +9 -3
  4. langchain/agents/middleware/context_editing.py +15 -14
  5. langchain/agents/middleware/human_in_the_loop.py +213 -170
  6. langchain/agents/middleware/model_call_limit.py +2 -2
  7. langchain/agents/middleware/model_fallback.py +46 -36
  8. langchain/agents/middleware/pii.py +25 -27
  9. langchain/agents/middleware/planning.py +16 -11
  10. langchain/agents/middleware/prompt_caching.py +14 -11
  11. langchain/agents/middleware/summarization.py +1 -1
  12. langchain/agents/middleware/tool_call_limit.py +5 -5
  13. langchain/agents/middleware/tool_emulator.py +200 -0
  14. langchain/agents/middleware/tool_selection.py +25 -21
  15. langchain/agents/middleware/types.py +623 -225
  16. langchain/chat_models/base.py +85 -90
  17. langchain/embeddings/__init__.py +0 -2
  18. langchain/embeddings/base.py +20 -20
  19. langchain/messages/__init__.py +34 -0
  20. langchain/tools/__init__.py +2 -6
  21. langchain/tools/tool_node.py +410 -83
  22. {langchain-1.0.0a12.dist-info → langchain-1.0.0a14.dist-info}/METADATA +8 -5
  23. langchain-1.0.0a14.dist-info/RECORD +30 -0
  24. langchain/_internal/__init__.py +0 -0
  25. langchain/_internal/_documents.py +0 -35
  26. langchain/_internal/_lazy_import.py +0 -35
  27. langchain/_internal/_prompts.py +0 -158
  28. langchain/_internal/_typing.py +0 -70
  29. langchain/_internal/_utils.py +0 -7
  30. langchain/agents/_internal/__init__.py +0 -1
  31. langchain/agents/_internal/_typing.py +0 -13
  32. langchain/documents/__init__.py +0 -7
  33. langchain/embeddings/cache.py +0 -361
  34. langchain/storage/__init__.py +0 -22
  35. langchain/storage/encoder_backed.py +0 -123
  36. langchain/storage/exceptions.py +0 -5
  37. langchain/storage/in_memory.py +0 -13
  38. langchain-1.0.0a12.dist-info/RECORD +0 -43
  39. {langchain-1.0.0a12.dist-info → langchain-1.0.0a14.dist-info}/WHEEL +0 -0
  40. {langchain-1.0.0a12.dist-info → langchain-1.0.0a14.dist-info}/licenses/LICENSE +0 -0
@@ -1,14 +1,17 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: langchain
3
- Version: 1.0.0a12
3
+ Version: 1.0.0a14
4
4
  Summary: Building applications with LLMs through composability
5
- Project-URL: Source Code, https://github.com/langchain-ai/langchain/tree/master/libs/langchain
6
- Project-URL: Release Notes, https://github.com/langchain-ai/langchain/releases?q=tag%3A%22langchain%3D%3D0%22&expanded=true
7
- Project-URL: repository, https://github.com/langchain-ai/langchain
5
+ Project-URL: homepage, https://docs.langchain.com/
6
+ Project-URL: repository, https://github.com/langchain-ai/langchain/tree/master/libs/langchain
7
+ Project-URL: changelog, https://github.com/langchain-ai/langchain/releases?q=tag%3A%22langchain%3D%3D1%22
8
+ Project-URL: twitter, https://x.com/LangChainAI
9
+ Project-URL: slack, https://www.langchain.com/join-community
10
+ Project-URL: reddit, https://www.reddit.com/r/LangChain/
8
11
  License: MIT
9
12
  License-File: LICENSE
10
13
  Requires-Python: <4.0.0,>=3.10.0
11
- Requires-Dist: langchain-core<2.0.0,>=1.0.0a6
14
+ Requires-Dist: langchain-core<2.0.0,>=1.0.0a7
12
15
  Requires-Dist: langgraph<2.0.0,>=1.0.0a4
13
16
  Requires-Dist: pydantic<3.0.0,>=2.7.4
14
17
  Provides-Extra: anthropic
@@ -0,0 +1,30 @@
1
+ langchain/__init__.py,sha256=rED92FbyWFRmks07cFlRTuz5ZtaPKxYq6BcsxW5KhrE,64
2
+ langchain/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
+ langchain/agents/__init__.py,sha256=x85V7MqddVSrraoirGHplPMzEz9Lha-vL9fKjXCS7lA,258
4
+ langchain/agents/factory.py,sha256=e6xjbw_qTFvfP-AHXZtykXGrX-2GoX6hFaW_97WHiEw,61245
5
+ langchain/agents/structured_output.py,sha256=msf-ClqDnMfJ-oGHqjwEyth860tMnx58GLTvqJijqg8,13686
6
+ langchain/agents/middleware/__init__.py,sha256=FDwjEGYtxPgyFa9iiLAWT5M2W8c-NDYfGz6_y8cEqPI,1568
7
+ langchain/agents/middleware/context_editing.py,sha256=6ca6Qed-F59JD1rAlrIuxlrBbDVIKQmCpfvZaIFbBy8,7691
8
+ langchain/agents/middleware/human_in_the_loop.py,sha256=Bs4_Hgjuy9l0-AMUHvU9wlr_rL2Z1rUwL_VcfFLhhUM,12666
9
+ langchain/agents/middleware/model_call_limit.py,sha256=H3lJL2cLv3u0uF0kJsRagFt1rBmHHgn5SFsfnmcyQdA,6703
10
+ langchain/agents/middleware/model_fallback.py,sha256=pdKRSO9JD6MdMYHFl7IK4yj6LEwQfyzfTJiBE8uJ2pE,3118
11
+ langchain/agents/middleware/pii.py,sha256=7hTBxnpcG_hSZd29TCg-4tbiLFO9IJb-wwnujCRMrv4,24780
12
+ langchain/agents/middleware/planning.py,sha256=59Q6-4aALytjssIZ5a4hZkx5THxIG-RTeUHuDP1LGDA,9319
13
+ langchain/agents/middleware/prompt_caching.py,sha256=cMvIJ_dpSsn4_cqCvZBBKjtw5GpcVkc8Lgf_VEPzM1w,3225
14
+ langchain/agents/middleware/summarization.py,sha256=H1VxRkkbauw4p4sMMKyc_uZGbJhtqoVvOF7y_5JBXTc,10329
15
+ langchain/agents/middleware/tool_call_limit.py,sha256=6cWviwPRzaf7UUcp9zlXwk6RJBBoWVaVSBc1NaVT2fI,9729
16
+ langchain/agents/middleware/tool_emulator.py,sha256=5qJFPfTSiVukNclDeUo7_c7-PjGEVWyefbPC-zpYSlI,7115
17
+ langchain/agents/middleware/tool_selection.py,sha256=6RYdgkg6aSNx1w-YxRyL2Hct7UPnMRgGg6YVZVtW5TU,11638
18
+ langchain/agents/middleware/types.py,sha256=JqTdwFru-nqs8RlamYPqEM0cnak9WBPEp__dtsve3g4,53868
19
+ langchain/chat_models/__init__.py,sha256=PTq9qskQEbqXYAcUUxUXDsugOcwISgFhv4w40JgkbgU,181
20
+ langchain/chat_models/base.py,sha256=HPlD0QaLOGXRJAY1Qq6ojr1WcteBlgVO--_GoSqpxXE,34560
21
+ langchain/embeddings/__init__.py,sha256=kfLfu342i9bTrA0WC8yA6IJE2bgY4ZynWBi-_cMUg8E,179
22
+ langchain/embeddings/base.py,sha256=o77Z1TrXoUZN1SdYY9nZCNehm7cZzC-TNqc5NIzWtww,7327
23
+ langchain/messages/__init__.py,sha256=X5-dRewJP-jtehdC6oDbs21j9bxGDUbI5WlcNrO_bHk,1309
24
+ langchain/rate_limiters/__init__.py,sha256=5490xUNhet37N2nX6kbJlDgf8u1DX-C1Cs_r7etXn8A,351
25
+ langchain/tools/__init__.py,sha256=C0GW8HPluAgnVmGneHXY-ibwbl3kXixBtZS88PtnXSI,410
26
+ langchain/tools/tool_node.py,sha256=p9NO3R8dgA9QhjCuGb-INebjizjzKj21tIsnoKSBkA8,57917
27
+ langchain-1.0.0a14.dist-info/METADATA,sha256=5-_c3FrZ93AM_AtuB9-PkYjoYDLgfMFtfij0SSHjvJE,6118
28
+ langchain-1.0.0a14.dist-info/WHEEL,sha256=qtCwoSJWgHk21S1Kb4ihdzI2rlJ1ZKaIurTj_ngOhyQ,87
29
+ langchain-1.0.0a14.dist-info/licenses/LICENSE,sha256=TsZ-TKbmch26hJssqCJhWXyGph7iFLvyFBYAa3stBHg,1067
30
+ langchain-1.0.0a14.dist-info/RECORD,,
File without changes
@@ -1,35 +0,0 @@
1
- """Internal document utilities."""
2
-
3
- from __future__ import annotations
4
-
5
- from typing import TYPE_CHECKING
6
-
7
- if TYPE_CHECKING:
8
- from langchain_core.documents import Document
9
-
10
-
11
- def format_document_xml(doc: Document) -> str:
12
- """Format a document as XML-like structure for LLM consumption.
13
-
14
- Args:
15
- doc: Document to format
16
-
17
- Returns:
18
- Document wrapped in XML tags:
19
- <document>
20
- <id>...</id>
21
- <content>...</content>
22
- <metadata>...</metadata>
23
- </document>
24
-
25
- !!! note
26
- Does not generate valid XML or escape special characters. Intended for
27
- semi-structured LLM input only.
28
-
29
- """
30
- id_str = f"<id>{doc.id}</id>" if doc.id is not None else "<id></id>"
31
- metadata_str = ""
32
- if doc.metadata:
33
- metadata_items = [f"{k}: {v!s}" for k, v in doc.metadata.items()]
34
- metadata_str = f"<metadata>{', '.join(metadata_items)}</metadata>"
35
- return f"<document>{id_str}<content>{doc.page_content}</content>{metadata_str}</document>"
@@ -1,35 +0,0 @@
1
- """Lazy import utilities."""
2
-
3
- from importlib import import_module
4
-
5
-
6
- def import_attr(
7
- attr_name: str,
8
- module_name: str | None,
9
- package: str | None,
10
- ) -> object:
11
- """Import an attribute from a module located in a package.
12
-
13
- This utility function is used in custom __getattr__ methods within __init__.py
14
- files to dynamically import attributes.
15
-
16
- Args:
17
- attr_name: The name of the attribute to import.
18
- module_name: The name of the module to import from. If None, the attribute
19
- is imported from the package itself.
20
- package: The name of the package where the module is located.
21
- """
22
- if module_name == "__module__" or module_name is None:
23
- try:
24
- result = import_module(f".{attr_name}", package=package)
25
- except ModuleNotFoundError:
26
- msg = f"module '{package!r}' has no attribute {attr_name!r}"
27
- raise AttributeError(msg) from None
28
- else:
29
- try:
30
- module = import_module(f".{module_name}", package=package)
31
- except ModuleNotFoundError as err:
32
- msg = f"module '{package!r}.{module_name!r}' not found ({err})"
33
- raise ImportError(msg) from None
34
- result = getattr(module, attr_name)
35
- return result
@@ -1,158 +0,0 @@
1
- """Internal prompt resolution utilities.
2
-
3
- This module provides utilities for resolving different types of prompt specifications
4
- into standardized message formats for language models. It supports both synchronous
5
- and asynchronous prompt resolution with automatic detection of callable types.
6
-
7
- The module is designed to handle common prompt patterns across LangChain components,
8
- particularly for summarization chains and other document processing workflows.
9
-
10
- """
11
-
12
- from __future__ import annotations
13
-
14
- import inspect
15
- from typing import TYPE_CHECKING
16
-
17
- if TYPE_CHECKING:
18
- from collections.abc import Awaitable, Callable
19
-
20
- from langchain_core.messages import MessageLikeRepresentation
21
- from langgraph.runtime import Runtime
22
-
23
- from langchain._internal._typing import ContextT, StateT
24
-
25
-
26
- def resolve_prompt(
27
- prompt: str | None | Callable[[StateT, Runtime[ContextT]], list[MessageLikeRepresentation]],
28
- state: StateT,
29
- runtime: Runtime[ContextT],
30
- default_user_content: str,
31
- default_system_content: str,
32
- ) -> list[MessageLikeRepresentation]:
33
- """Resolve a prompt specification into a list of messages.
34
-
35
- Handles prompt resolution across different strategies. Supports callable functions,
36
- string system messages, and None for default behavior.
37
-
38
- Args:
39
- prompt: The prompt specification to resolve. Can be:
40
- - Callable: Function taking (state, runtime) returning message list.
41
- - str: A system message string.
42
- - None: Use the provided default system message.
43
- state: Current state, passed to callable prompts.
44
- runtime: LangGraph runtime instance, passed to callable prompts.
45
- default_user_content: User content to include (e.g., document text).
46
- default_system_content: Default system message when prompt is None.
47
-
48
- Returns:
49
- List of message dictionaries for language models, typically containing
50
- a system message and user message with content.
51
-
52
- Raises:
53
- TypeError: If prompt type is not str, None, or callable.
54
-
55
- Example:
56
- ```python
57
- def custom_prompt(state, runtime):
58
- return [{"role": "system", "content": "Custom"}]
59
-
60
-
61
- messages = resolve_prompt(custom_prompt, state, runtime, "content", "default")
62
- messages = resolve_prompt("Custom system", state, runtime, "content", "default")
63
- messages = resolve_prompt(None, state, runtime, "content", "Default")
64
- ```
65
-
66
- !!! note
67
- Callable prompts have full control over message structure and content parameter
68
- is ignored. String/None prompts create standard system + user structure.
69
-
70
- """
71
- if callable(prompt):
72
- return prompt(state, runtime)
73
- if isinstance(prompt, str):
74
- system_msg = prompt
75
- elif prompt is None:
76
- system_msg = default_system_content
77
- else:
78
- msg = f"Invalid prompt type: {type(prompt)}. Expected str, None, or callable."
79
- raise TypeError(msg)
80
-
81
- return [
82
- {"role": "system", "content": system_msg},
83
- {"role": "user", "content": default_user_content},
84
- ]
85
-
86
-
87
- async def aresolve_prompt(
88
- prompt: str
89
- | None
90
- | Callable[[StateT, Runtime[ContextT]], list[MessageLikeRepresentation]]
91
- | Callable[[StateT, Runtime[ContextT]], Awaitable[list[MessageLikeRepresentation]]],
92
- state: StateT,
93
- runtime: Runtime[ContextT],
94
- default_user_content: str,
95
- default_system_content: str,
96
- ) -> list[MessageLikeRepresentation]:
97
- """Async version of resolve_prompt supporting both sync and async callables.
98
-
99
- Handles prompt resolution across different strategies. Supports sync/async callable
100
- functions, string system messages, and None for default behavior.
101
-
102
- Args:
103
- prompt: The prompt specification to resolve. Can be:
104
- - Callable (sync): Function taking (state, runtime) returning message list.
105
- - Callable (async): Async function taking (state, runtime) returning
106
- awaitable message list.
107
- - str: A system message string.
108
- - None: Use the provided default system message.
109
- state: Current state, passed to callable prompts.
110
- runtime: LangGraph runtime instance, passed to callable prompts.
111
- default_user_content: User content to include (e.g., document text).
112
- default_system_content: Default system message when prompt is None.
113
-
114
- Returns:
115
- List of message dictionaries for language models, typically containing
116
- a system message and user message with content.
117
-
118
- Raises:
119
- TypeError: If prompt type is not str, None, or callable.
120
-
121
- Example:
122
- ```python
123
- async def async_prompt(state, runtime):
124
- return [{"role": "system", "content": "Async"}]
125
-
126
-
127
- def sync_prompt(state, runtime):
128
- return [{"role": "system", "content": "Sync"}]
129
-
130
-
131
- messages = await aresolve_prompt(async_prompt, state, runtime, "content", "default")
132
- messages = await aresolve_prompt(sync_prompt, state, runtime, "content", "default")
133
- messages = await aresolve_prompt("Custom", state, runtime, "content", "default")
134
- ```
135
-
136
- !!! note
137
- Callable prompts have full control over message structure and content parameter
138
- is ignored. Automatically detects and handles async callables.
139
-
140
- """
141
- if callable(prompt):
142
- result = prompt(state, runtime)
143
- # Check if the result is awaitable (async function)
144
- if inspect.isawaitable(result):
145
- return await result
146
- return result
147
- if isinstance(prompt, str):
148
- system_msg = prompt
149
- elif prompt is None:
150
- system_msg = default_system_content
151
- else:
152
- msg = f"Invalid prompt type: {type(prompt)}. Expected str, None, or callable."
153
- raise TypeError(msg)
154
-
155
- return [
156
- {"role": "system", "content": system_msg},
157
- {"role": "user", "content": default_user_content},
158
- ]
@@ -1,70 +0,0 @@
1
- """Private typing utilities for langchain."""
2
-
3
- from __future__ import annotations
4
-
5
- from typing import TYPE_CHECKING, Any, ClassVar, Protocol, TypeAlias, TypeVar
6
-
7
- from langgraph.graph._node import StateNode
8
- from pydantic import BaseModel
9
-
10
- if TYPE_CHECKING:
11
- from dataclasses import Field
12
-
13
-
14
- class TypedDictLikeV1(Protocol):
15
- """Protocol to represent types that behave like ``TypedDict``s.
16
-
17
- Version 1: using ``ClassVar`` for keys.
18
-
19
- """
20
-
21
- __required_keys__: ClassVar[frozenset[str]]
22
- __optional_keys__: ClassVar[frozenset[str]]
23
-
24
-
25
- class TypedDictLikeV2(Protocol):
26
- """Protocol to represent types that behave like ``TypedDict``s.
27
-
28
- Version 2: not using ``ClassVar`` for keys.
29
-
30
- """
31
-
32
- __required_keys__: frozenset[str]
33
- __optional_keys__: frozenset[str]
34
-
35
-
36
- class DataclassLike(Protocol):
37
- """Protocol to represent types that behave like dataclasses.
38
-
39
- Inspired by the private ``_DataclassT`` from dataclasses that uses a similar
40
- protocol as a bound.
41
-
42
- """
43
-
44
- __dataclass_fields__: ClassVar[dict[str, Field[Any]]]
45
-
46
-
47
- StateLike: TypeAlias = TypedDictLikeV1 | TypedDictLikeV2 | DataclassLike | BaseModel
48
- """Type alias for state-like types.
49
-
50
- It can either be a ``TypedDict``, ``dataclass``, or Pydantic ``BaseModel``.
51
-
52
- !!! note
53
- We cannot use either ``TypedDict`` or ``dataclass`` directly due to limitations in
54
- type checking.
55
-
56
- """
57
-
58
- StateT = TypeVar("StateT", bound=StateLike)
59
- """Type variable used to represent the state in a graph."""
60
-
61
- ContextT = TypeVar("ContextT", bound=StateLike | None)
62
- """Type variable for context types."""
63
-
64
-
65
- __all__ = [
66
- "ContextT",
67
- "StateLike",
68
- "StateNode",
69
- "StateT",
70
- ]
@@ -1,7 +0,0 @@
1
- # Re-exporting internal utilities from LangGraph for internal use in LangChain.
2
- # A different wrapper needs to be created for this purpose in LangChain.
3
- from langgraph._internal._runnable import RunnableCallable
4
-
5
- __all__ = [
6
- "RunnableCallable",
7
- ]
@@ -1 +0,0 @@
1
- """Internal utilities for agents."""
@@ -1,13 +0,0 @@
1
- """Typing utilities for agents."""
2
-
3
- from __future__ import annotations
4
-
5
- from collections.abc import Awaitable, Callable
6
- from typing import TypeVar
7
-
8
- from typing_extensions import ParamSpec
9
-
10
- P = ParamSpec("P")
11
- R = TypeVar("R")
12
-
13
- SyncOrAsync = Callable[P, R | Awaitable[R]]
@@ -1,7 +0,0 @@
1
- """Document."""
2
-
3
- from langchain_core.documents import Document
4
-
5
- __all__ = [
6
- "Document",
7
- ]