langchain-core 1.0.0rc3__py3-none-any.whl → 1.0.2__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 (76) hide show
  1. langchain_core/agents.py +2 -4
  2. langchain_core/caches.py +16 -7
  3. langchain_core/callbacks/base.py +0 -4
  4. langchain_core/callbacks/manager.py +0 -11
  5. langchain_core/chat_history.py +5 -5
  6. langchain_core/document_loaders/base.py +6 -4
  7. langchain_core/document_loaders/blob_loaders.py +1 -1
  8. langchain_core/document_loaders/langsmith.py +9 -13
  9. langchain_core/documents/__init__.py +24 -3
  10. langchain_core/documents/base.py +72 -61
  11. langchain_core/documents/compressor.py +6 -6
  12. langchain_core/documents/transformers.py +6 -6
  13. langchain_core/embeddings/fake.py +2 -2
  14. langchain_core/example_selectors/semantic_similarity.py +7 -7
  15. langchain_core/exceptions.py +2 -2
  16. langchain_core/indexing/__init__.py +1 -1
  17. langchain_core/indexing/api.py +62 -62
  18. langchain_core/indexing/base.py +20 -22
  19. langchain_core/indexing/in_memory.py +2 -4
  20. langchain_core/language_models/__init__.py +6 -5
  21. langchain_core/language_models/base.py +7 -8
  22. langchain_core/language_models/chat_models.py +84 -78
  23. langchain_core/language_models/fake_chat_models.py +1 -1
  24. langchain_core/language_models/llms.py +20 -18
  25. langchain_core/load/dump.py +6 -8
  26. langchain_core/load/serializable.py +4 -1
  27. langchain_core/messages/__init__.py +9 -0
  28. langchain_core/messages/ai.py +11 -7
  29. langchain_core/messages/base.py +4 -0
  30. langchain_core/messages/block_translators/google_genai.py +5 -3
  31. langchain_core/messages/content.py +4 -4
  32. langchain_core/messages/utils.py +17 -17
  33. langchain_core/output_parsers/__init__.py +17 -1
  34. langchain_core/output_parsers/base.py +3 -0
  35. langchain_core/output_parsers/format_instructions.py +9 -4
  36. langchain_core/output_parsers/json.py +5 -2
  37. langchain_core/output_parsers/list.py +16 -16
  38. langchain_core/output_parsers/openai_tools.py +2 -2
  39. langchain_core/output_parsers/pydantic.py +1 -1
  40. langchain_core/output_parsers/string.py +3 -3
  41. langchain_core/output_parsers/xml.py +28 -25
  42. langchain_core/outputs/generation.py +2 -3
  43. langchain_core/prompt_values.py +0 -6
  44. langchain_core/prompts/base.py +5 -3
  45. langchain_core/prompts/chat.py +60 -52
  46. langchain_core/prompts/string.py +5 -2
  47. langchain_core/prompts/structured.py +12 -8
  48. langchain_core/rate_limiters.py +1 -3
  49. langchain_core/retrievers.py +41 -37
  50. langchain_core/runnables/base.py +25 -29
  51. langchain_core/runnables/branch.py +9 -9
  52. langchain_core/runnables/config.py +2 -4
  53. langchain_core/runnables/configurable.py +3 -3
  54. langchain_core/runnables/fallbacks.py +1 -1
  55. langchain_core/runnables/graph.py +7 -3
  56. langchain_core/runnables/retry.py +1 -1
  57. langchain_core/runnables/schema.py +2 -5
  58. langchain_core/runnables/utils.py +3 -3
  59. langchain_core/stores.py +4 -6
  60. langchain_core/tools/base.py +68 -14
  61. langchain_core/tools/convert.py +8 -7
  62. langchain_core/tools/retriever.py +6 -5
  63. langchain_core/tools/structured.py +7 -5
  64. langchain_core/tracers/event_stream.py +4 -1
  65. langchain_core/tracers/log_stream.py +6 -3
  66. langchain_core/utils/function_calling.py +8 -0
  67. langchain_core/utils/json_schema.py +1 -1
  68. langchain_core/utils/strings.py +1 -4
  69. langchain_core/utils/utils.py +12 -5
  70. langchain_core/vectorstores/base.py +130 -130
  71. langchain_core/vectorstores/in_memory.py +4 -4
  72. langchain_core/vectorstores/utils.py +1 -1
  73. langchain_core/version.py +1 -1
  74. {langchain_core-1.0.0rc3.dist-info → langchain_core-1.0.2.dist-info}/METADATA +8 -7
  75. {langchain_core-1.0.0rc3.dist-info → langchain_core-1.0.2.dist-info}/RECORD +76 -76
  76. {langchain_core-1.0.0rc3.dist-info → langchain_core-1.0.2.dist-info}/WHEEL +0 -0
@@ -104,19 +104,23 @@ class StructuredPrompt(ChatPromptTemplate):
104
104
  )
105
105
  ```
106
106
  Args:
107
- messages: sequence of message representations.
107
+ messages: Sequence of message representations.
108
+
108
109
  A message can be represented using the following formats:
109
- (1) BaseMessagePromptTemplate, (2) BaseMessage, (3) 2-tuple of
110
- (message type, template); e.g., ("human", "{user_input}"),
111
- (4) 2-tuple of (message class, template), (5) a string which is
112
- shorthand for ("human", template); e.g., "{user_input}"
113
- schema: a dictionary representation of function call, or a Pydantic model.
110
+
111
+ 1. `BaseMessagePromptTemplate`
112
+ 2. `BaseMessage`
113
+ 3. 2-tuple of `(message type, template)`; e.g.,
114
+ `("human", "{user_input}")`
115
+ 4. 2-tuple of `(message class, template)`
116
+ 5. A string which is shorthand for `("human", template)`; e.g.,
117
+ `"{user_input}"`
118
+ schema: A dictionary representation of function call, or a Pydantic model.
114
119
  **kwargs: Any additional kwargs to pass through to
115
120
  `ChatModel.with_structured_output(schema, **kwargs)`.
116
121
 
117
122
  Returns:
118
- a structured prompt template
119
-
123
+ A structured prompt template
120
124
  """
121
125
  return cls(messages, schema, **kwargs)
122
126
 
@@ -105,9 +105,7 @@ class InMemoryRateLimiter(BaseRateLimiter):
105
105
 
106
106
  from langchain_anthropic import ChatAnthropic
107
107
 
108
- model = ChatAnthropic(
109
- model_name="claude-sonnet-4-5-20250929", rate_limiter=rate_limiter
110
- )
108
+ model = ChatAnthropic(model_name="claude-sonnet-4-5", rate_limiter=rate_limiter)
111
109
 
112
110
  for _ in range(5):
113
111
  tic = time.time()
@@ -50,65 +50,65 @@ class LangSmithRetrieverParams(TypedDict, total=False):
50
50
 
51
51
 
52
52
  class BaseRetriever(RunnableSerializable[RetrieverInput, RetrieverOutput], ABC):
53
- """Abstract base class for a Document retrieval system.
53
+ """Abstract base class for a document retrieval system.
54
54
 
55
55
  A retrieval system is defined as something that can take string queries and return
56
- the most 'relevant' Documents from some source.
56
+ the most 'relevant' documents from some source.
57
57
 
58
58
  Usage:
59
59
 
60
- A retriever follows the standard Runnable interface, and should be used
61
- via the standard Runnable methods of `invoke`, `ainvoke`, `batch`, `abatch`.
60
+ A retriever follows the standard `Runnable` interface, and should be used via the
61
+ standard `Runnable` methods of `invoke`, `ainvoke`, `batch`, `abatch`.
62
62
 
63
63
  Implementation:
64
64
 
65
- When implementing a custom retriever, the class should implement
66
- the `_get_relevant_documents` method to define the logic for retrieving documents.
65
+ When implementing a custom retriever, the class should implement the
66
+ `_get_relevant_documents` method to define the logic for retrieving documents.
67
67
 
68
68
  Optionally, an async native implementations can be provided by overriding the
69
69
  `_aget_relevant_documents` method.
70
70
 
71
- Example: A retriever that returns the first 5 documents from a list of documents
71
+ !!! example "Retriever that returns the first 5 documents from a list of documents"
72
72
 
73
- ```python
74
- from langchain_core.documents import Document
75
- from langchain_core.retrievers import BaseRetriever
73
+ ```python
74
+ from langchain_core.documents import Document
75
+ from langchain_core.retrievers import BaseRetriever
76
76
 
77
- class SimpleRetriever(BaseRetriever):
78
- docs: list[Document]
79
- k: int = 5
77
+ class SimpleRetriever(BaseRetriever):
78
+ docs: list[Document]
79
+ k: int = 5
80
80
 
81
- def _get_relevant_documents(self, query: str) -> list[Document]:
82
- \"\"\"Return the first k documents from the list of documents\"\"\"
83
- return self.docs[:self.k]
81
+ def _get_relevant_documents(self, query: str) -> list[Document]:
82
+ \"\"\"Return the first k documents from the list of documents\"\"\"
83
+ return self.docs[:self.k]
84
84
 
85
- async def _aget_relevant_documents(self, query: str) -> list[Document]:
86
- \"\"\"(Optional) async native implementation.\"\"\"
87
- return self.docs[:self.k]
88
- ```
85
+ async def _aget_relevant_documents(self, query: str) -> list[Document]:
86
+ \"\"\"(Optional) async native implementation.\"\"\"
87
+ return self.docs[:self.k]
88
+ ```
89
89
 
90
- Example: A simple retriever based on a scikit-learn vectorizer
90
+ !!! example "Simple retriever based on a scikit-learn vectorizer"
91
91
 
92
- ```python
93
- from sklearn.metrics.pairwise import cosine_similarity
92
+ ```python
93
+ from sklearn.metrics.pairwise import cosine_similarity
94
94
 
95
95
 
96
- class TFIDFRetriever(BaseRetriever, BaseModel):
97
- vectorizer: Any
98
- docs: list[Document]
99
- tfidf_array: Any
100
- k: int = 4
96
+ class TFIDFRetriever(BaseRetriever, BaseModel):
97
+ vectorizer: Any
98
+ docs: list[Document]
99
+ tfidf_array: Any
100
+ k: int = 4
101
101
 
102
- class Config:
103
- arbitrary_types_allowed = True
102
+ class Config:
103
+ arbitrary_types_allowed = True
104
104
 
105
- def _get_relevant_documents(self, query: str) -> list[Document]:
106
- # Ip -- (n_docs,x), Op -- (n_docs,n_Feats)
107
- query_vec = self.vectorizer.transform([query])
108
- # Op -- (n_docs,1) -- Cosine Sim with each doc
109
- results = cosine_similarity(self.tfidf_array, query_vec).reshape((-1,))
110
- return [self.docs[i] for i in results.argsort()[-self.k :][::-1]]
111
- ```
105
+ def _get_relevant_documents(self, query: str) -> list[Document]:
106
+ # Ip -- (n_docs,x), Op -- (n_docs,n_Feats)
107
+ query_vec = self.vectorizer.transform([query])
108
+ # Op -- (n_docs,1) -- Cosine Sim with each doc
109
+ results = cosine_similarity(self.tfidf_array, query_vec).reshape((-1,))
110
+ return [self.docs[i] for i in results.argsort()[-self.k :][::-1]]
111
+ ```
112
112
  """
113
113
 
114
114
  model_config = ConfigDict(
@@ -119,15 +119,19 @@ class BaseRetriever(RunnableSerializable[RetrieverInput, RetrieverOutput], ABC):
119
119
  _expects_other_args: bool = False
120
120
  tags: list[str] | None = None
121
121
  """Optional list of tags associated with the retriever.
122
+
122
123
  These tags will be associated with each call to this retriever,
123
124
  and passed as arguments to the handlers defined in `callbacks`.
125
+
124
126
  You can use these to eg identify a specific instance of a retriever with its
125
127
  use case.
126
128
  """
127
129
  metadata: dict[str, Any] | None = None
128
130
  """Optional metadata associated with the retriever.
131
+
129
132
  This metadata will be associated with each call to this retriever,
130
133
  and passed as arguments to the handlers defined in `callbacks`.
134
+
131
135
  You can use these to eg identify a specific instance of a retriever with its
132
136
  use case.
133
137
  """
@@ -147,11 +147,11 @@ class Runnable(ABC, Generic[Input, Output]):
147
147
  the `input_schema` property, the `output_schema` property and `config_schema`
148
148
  method.
149
149
 
150
- LCEL and Composition
151
- ====================
150
+ Composition
151
+ ===========
152
+
153
+ Runnable objects can be composed together to create chains in a declarative way.
152
154
 
153
- The LangChain Expression Language (LCEL) is a declarative way to compose
154
- `Runnable` objectsinto chains.
155
155
  Any chain constructed this way will automatically have sync, async, batch, and
156
156
  streaming support.
157
157
 
@@ -235,21 +235,21 @@ class Runnable(ABC, Generic[Input, Output]):
235
235
 
236
236
  You can set the global debug flag to True to enable debug output for all chains:
237
237
 
238
- ```python
239
- from langchain_core.globals import set_debug
238
+ ```python
239
+ from langchain_core.globals import set_debug
240
240
 
241
- set_debug(True)
242
- ```
241
+ set_debug(True)
242
+ ```
243
243
 
244
244
  Alternatively, you can pass existing or custom callbacks to any given chain:
245
245
 
246
- ```python
247
- from langchain_core.tracers import ConsoleCallbackHandler
246
+ ```python
247
+ from langchain_core.tracers import ConsoleCallbackHandler
248
248
 
249
- chain.invoke(..., config={"callbacks": [ConsoleCallbackHandler()]})
250
- ```
249
+ chain.invoke(..., config={"callbacks": [ConsoleCallbackHandler()]})
250
+ ```
251
251
 
252
- For a UI (and much more) checkout [LangSmith](https://docs.smith.langchain.com/).
252
+ For a UI (and much more) checkout [LangSmith](https://docs.langchain.com/langsmith/home).
253
253
 
254
254
  """
255
255
 
@@ -1367,8 +1367,8 @@ class Runnable(ABC, Generic[Input, Output]):
1367
1367
 
1368
1368
  events = [event async for event in chain.astream_events("hello", version="v2")]
1369
1369
 
1370
- # will produce the following events (run_id, and parent_ids
1371
- # has been omitted for brevity):
1370
+ # Will produce the following events
1371
+ # (run_id, and parent_ids has been omitted for brevity):
1372
1372
  [
1373
1373
  {
1374
1374
  "data": {"input": "hello"},
@@ -1423,7 +1423,7 @@ class Runnable(ABC, Generic[Input, Output]):
1423
1423
 
1424
1424
  async for event in slow_thing.astream_events("some_input", version="v2"):
1425
1425
  print(event)
1426
- ``
1426
+ ```
1427
1427
 
1428
1428
  Args:
1429
1429
  input: The input to the `Runnable`.
@@ -1813,7 +1813,7 @@ class Runnable(ABC, Generic[Input, Output]):
1813
1813
  output_type: The output type to bind to the `Runnable`.
1814
1814
 
1815
1815
  Returns:
1816
- A new Runnable with the types bound.
1816
+ A new `Runnable` with the types bound.
1817
1817
  """
1818
1818
  return RunnableBinding(
1819
1819
  bound=self,
@@ -1840,7 +1840,7 @@ class Runnable(ABC, Generic[Input, Output]):
1840
1840
  giving up.
1841
1841
  exponential_jitter_params: Parameters for
1842
1842
  `tenacity.wait_exponential_jitter`. Namely: `initial`, `max`,
1843
- `exp_base`, and `jitter` (all float values).
1843
+ `exp_base`, and `jitter` (all `float` values).
1844
1844
 
1845
1845
  Returns:
1846
1846
  A new Runnable that retries the original Runnable on exceptions.
@@ -1925,15 +1925,15 @@ class Runnable(ABC, Generic[Input, Output]):
1925
1925
  fallbacks: A sequence of runnables to try if the original `Runnable`
1926
1926
  fails.
1927
1927
  exceptions_to_handle: A tuple of exception types to handle.
1928
- exception_key: If string is specified then handled exceptions will be passed
1929
- to fallbacks as part of the input under the specified key.
1928
+ exception_key: If `string` is specified then handled exceptions will be
1929
+ passed to fallbacks as part of the input under the specified key.
1930
1930
  If `None`, exceptions will not be passed to fallbacks.
1931
1931
  If used, the base `Runnable` and its fallbacks must accept a
1932
1932
  dictionary as input.
1933
1933
 
1934
1934
  Returns:
1935
1935
  A new `Runnable` that will try the original `Runnable`, and then each
1936
- Fallback in order, upon failures.
1936
+ Fallback in order, upon failures.
1937
1937
 
1938
1938
  Example:
1939
1939
  ```python
@@ -1961,16 +1961,15 @@ class Runnable(ABC, Generic[Input, Output]):
1961
1961
  fallbacks: A sequence of runnables to try if the original `Runnable`
1962
1962
  fails.
1963
1963
  exceptions_to_handle: A tuple of exception types to handle.
1964
- exception_key: If string is specified then handled exceptions will be passed
1965
- to fallbacks as part of the input under the specified key.
1964
+ exception_key: If `string` is specified then handled exceptions will be
1965
+ passed to fallbacks as part of the input under the specified key.
1966
1966
  If `None`, exceptions will not be passed to fallbacks.
1967
1967
  If used, the base `Runnable` and its fallbacks must accept a
1968
1968
  dictionary as input.
1969
1969
 
1970
1970
  Returns:
1971
1971
  A new `Runnable` that will try the original `Runnable`, and then each
1972
- Fallback in order, upon failures.
1973
-
1972
+ Fallback in order, upon failures.
1974
1973
  """
1975
1974
  # Import locally to prevent circular import
1976
1975
  from langchain_core.runnables.fallbacks import ( # noqa: PLC0415
@@ -2520,9 +2519,6 @@ class Runnable(ABC, Generic[Input, Output]):
2520
2519
  as_tool = runnable.as_tool()
2521
2520
  as_tool.invoke("b")
2522
2521
  ```
2523
-
2524
- !!! version-added "Added in version 0.2.14"
2525
-
2526
2522
  """
2527
2523
  # Avoid circular import
2528
2524
  from langchain_core.tools import convert_runnable_to_tool # noqa: PLC0415
@@ -3504,7 +3500,7 @@ class RunnableParallel(RunnableSerializable[Input, dict[str, Any]]):
3504
3500
 
3505
3501
  Returns a mapping of their outputs.
3506
3502
 
3507
- `RunnableParallel` is one of the two main composition primitives for the LCEL,
3503
+ `RunnableParallel` is one of the two main composition primitives,
3508
3504
  alongside `RunnableSequence`. It invokes `Runnable`s concurrently, providing the
3509
3505
  same input to each.
3510
3506
 
@@ -40,13 +40,13 @@ from langchain_core.runnables.utils import (
40
40
  class RunnableBranch(RunnableSerializable[Input, Output]):
41
41
  """Runnable that selects which branch to run based on a condition.
42
42
 
43
- The Runnable is initialized with a list of (condition, Runnable) pairs and
43
+ The Runnable is initialized with a list of `(condition, Runnable)` pairs and
44
44
  a default branch.
45
45
 
46
46
  When operating on an input, the first condition that evaluates to True is
47
- selected, and the corresponding Runnable is run on the input.
47
+ selected, and the corresponding `Runnable` is run on the input.
48
48
 
49
- If no condition evaluates to True, the default branch is run on the input.
49
+ If no condition evaluates to `True`, the default branch is run on the input.
50
50
 
51
51
  Examples:
52
52
  ```python
@@ -65,9 +65,9 @@ class RunnableBranch(RunnableSerializable[Input, Output]):
65
65
  """
66
66
 
67
67
  branches: Sequence[tuple[Runnable[Input, bool], Runnable[Input, Output]]]
68
- """A list of (condition, Runnable) pairs."""
68
+ """A list of `(condition, Runnable)` pairs."""
69
69
  default: Runnable[Input, Output]
70
- """A Runnable to run if no condition is met."""
70
+ """A `Runnable` to run if no condition is met."""
71
71
 
72
72
  def __init__(
73
73
  self,
@@ -79,15 +79,15 @@ class RunnableBranch(RunnableSerializable[Input, Output]):
79
79
  ]
80
80
  | RunnableLike,
81
81
  ) -> None:
82
- """A Runnable that runs one of two branches based on a condition.
82
+ """A `Runnable` that runs one of two branches based on a condition.
83
83
 
84
84
  Args:
85
- *branches: A list of (condition, Runnable) pairs.
86
- Defaults a Runnable to run if no condition is met.
85
+ *branches: A list of `(condition, Runnable)` pairs.
86
+ Defaults a `Runnable` to run if no condition is met.
87
87
 
88
88
  Raises:
89
89
  ValueError: If the number of branches is less than 2.
90
- TypeError: If the default branch is not Runnable, Callable or Mapping.
90
+ TypeError: If the default branch is not `Runnable`, `Callable` or `Mapping`.
91
91
  TypeError: If a branch is not a tuple or list.
92
92
  ValueError: If a branch is not of length 2.
93
93
  """
@@ -527,8 +527,7 @@ class ContextThreadPoolExecutor(ThreadPoolExecutor):
527
527
  self,
528
528
  fn: Callable[..., T],
529
529
  *iterables: Iterable[Any],
530
- timeout: float | None = None,
531
- chunksize: int = 1,
530
+ **kwargs: Any,
532
531
  ) -> Iterator[T]:
533
532
  """Map a function to multiple iterables.
534
533
 
@@ -549,8 +548,7 @@ class ContextThreadPoolExecutor(ThreadPoolExecutor):
549
548
  return super().map(
550
549
  _wrapped_fn,
551
550
  *iterables,
552
- timeout=timeout,
553
- chunksize=chunksize,
551
+ **kwargs,
554
552
  )
555
553
 
556
554
 
@@ -475,11 +475,11 @@ _enums_for_spec_lock = threading.Lock()
475
475
  class RunnableConfigurableAlternatives(DynamicRunnable[Input, Output]):
476
476
  """Runnable that can be dynamically configured.
477
477
 
478
- A RunnableConfigurableAlternatives should be initiated using the
478
+ A `RunnableConfigurableAlternatives` should be initiated using the
479
479
  `configurable_alternatives` method of a Runnable or can be
480
480
  initiated directly as well.
481
481
 
482
- Here is an example of using a RunnableConfigurableAlternatives that uses
482
+ Here is an example of using a `RunnableConfigurableAlternatives` that uses
483
483
  alternative prompts to illustrate its functionality:
484
484
 
485
485
  ```python
@@ -506,7 +506,7 @@ class RunnableConfigurableAlternatives(DynamicRunnable[Input, Output]):
506
506
  chain.with_config(configurable={"prompt": "poem"}).invoke({"topic": "bears"})
507
507
  ```
508
508
 
509
- Equivalently, you can initialize RunnableConfigurableAlternatives directly
509
+ Equivalently, you can initialize `RunnableConfigurableAlternatives` directly
510
510
  and use in LCEL in the same way:
511
511
 
512
512
  ```python
@@ -96,7 +96,7 @@ class RunnableWithFallbacks(RunnableSerializable[Input, Output]):
96
96
  Any exception that is not a subclass of these exceptions will be raised immediately.
97
97
  """
98
98
  exception_key: str | None = None
99
- """If string is specified then handled exceptions will be passed to fallbacks as
99
+ """If `string` is specified then handled exceptions will be passed to fallbacks as
100
100
  part of the input under the specified key. If `None`, exceptions
101
101
  will not be passed to fallbacks. If used, the base Runnable and its fallbacks
102
102
  must accept a dictionary as input."""
@@ -132,7 +132,7 @@ class Branch(NamedTuple):
132
132
  condition: Callable[..., str]
133
133
  """A callable that returns a string representation of the condition."""
134
134
  ends: dict[str, str] | None
135
- """Optional dictionary of end node ids for the branches. """
135
+ """Optional dictionary of end node IDs for the branches. """
136
136
 
137
137
 
138
138
  class CurveStyle(Enum):
@@ -706,8 +706,10 @@ class Graph:
706
706
  def _first_node(graph: Graph, exclude: Sequence[str] = ()) -> Node | None:
707
707
  """Find the single node that is not a target of any edge.
708
708
 
709
- Exclude nodes/sources with ids in the exclude list.
709
+ Exclude nodes/sources with IDs in the exclude list.
710
+
710
711
  If there is no such node, or there are multiple, return `None`.
712
+
711
713
  When drawing the graph, this node would be the origin.
712
714
  """
713
715
  targets = {edge.target for edge in graph.edges if edge.source not in exclude}
@@ -722,8 +724,10 @@ def _first_node(graph: Graph, exclude: Sequence[str] = ()) -> Node | None:
722
724
  def _last_node(graph: Graph, exclude: Sequence[str] = ()) -> Node | None:
723
725
  """Find the single node that is not a source of any edge.
724
726
 
725
- Exclude nodes/targets with ids in the exclude list.
727
+ Exclude nodes/targets with IDs in the exclude list.
728
+
726
729
  If there is no such node, or there are multiple, return `None`.
730
+
727
731
  When drawing the graph, this node would be the destination.
728
732
  """
729
733
  sources = {edge.source for edge in graph.edges if edge.target not in exclude}
@@ -126,7 +126,7 @@ class RunnableRetry(RunnableBindingBase[Input, Output]): # type: ignore[no-rede
126
126
 
127
127
  exponential_jitter_params: ExponentialJitterParams | None = None
128
128
  """Parameters for `tenacity.wait_exponential_jitter`. Namely: `initial`,
129
- `max`, `exp_base`, and `jitter` (all float values).
129
+ `max`, `exp_base`, and `jitter` (all `float` values).
130
130
  """
131
131
 
132
132
  max_attempt_number: int = 3
@@ -65,7 +65,7 @@ class BaseStreamEvent(TypedDict):
65
65
 
66
66
  events = [event async for event in chain.astream_events("hello")]
67
67
 
68
- # will produce the following events
68
+ # Will produce the following events
69
69
  # (where some fields have been omitted for brevity):
70
70
  [
71
71
  {
@@ -168,10 +168,7 @@ class StandardStreamEvent(BaseStreamEvent):
168
168
 
169
169
 
170
170
  class CustomStreamEvent(BaseStreamEvent):
171
- """Custom stream event created by the user.
172
-
173
- !!! version-added "Added in version 0.2.15"
174
- """
171
+ """Custom stream event created by the user."""
175
172
 
176
173
  # Overwrite the event field to be more specific.
177
174
  event: Literal["on_custom_event"] # type: ignore[misc]
@@ -5,6 +5,7 @@ from __future__ import annotations
5
5
  import ast
6
6
  import asyncio
7
7
  import inspect
8
+ import sys
8
9
  import textwrap
9
10
  from collections.abc import Callable, Mapping, Sequence
10
11
  from contextvars import Context
@@ -118,14 +119,13 @@ def accepts_context(callable: Callable[..., Any]) -> bool: # noqa: A002
118
119
  return False
119
120
 
120
121
 
121
- @lru_cache(maxsize=1)
122
122
  def asyncio_accepts_context() -> bool:
123
- """Cache the result of checking if asyncio.create_task accepts a `context` arg.
123
+ """Check if asyncio.create_task accepts a `context` arg.
124
124
 
125
125
  Returns:
126
126
  True if `asyncio.create_task` accepts a context argument, `False` otherwise.
127
127
  """
128
- return accepts_context(asyncio.create_task)
128
+ return sys.version_info >= (3, 11)
129
129
 
130
130
 
131
131
  def coro_with_context(
langchain_core/stores.py CHANGED
@@ -86,7 +86,7 @@ class BaseStore(ABC, Generic[K, V]):
86
86
 
87
87
  Returns:
88
88
  A sequence of optional values associated with the keys.
89
- If a key is not found, the corresponding value will be None.
89
+ If a key is not found, the corresponding value will be `None`.
90
90
  """
91
91
 
92
92
  async def amget(self, keys: Sequence[K]) -> list[V | None]:
@@ -97,7 +97,7 @@ class BaseStore(ABC, Generic[K, V]):
97
97
 
98
98
  Returns:
99
99
  A sequence of optional values associated with the keys.
100
- If a key is not found, the corresponding value will be None.
100
+ If a key is not found, the corresponding value will be `None`.
101
101
  """
102
102
  return await run_in_executor(None, self.mget, keys)
103
103
 
@@ -243,8 +243,7 @@ class InMemoryStore(InMemoryBaseStore[Any]):
243
243
  """In-memory store for any type of data.
244
244
 
245
245
  Attributes:
246
- store (dict[str, Any]): The underlying dictionary that stores
247
- the key-value pairs.
246
+ store: The underlying dictionary that stores the key-value pairs.
248
247
 
249
248
  Examples:
250
249
  ```python
@@ -267,8 +266,7 @@ class InMemoryByteStore(InMemoryBaseStore[bytes]):
267
266
  """In-memory store for bytes.
268
267
 
269
268
  Attributes:
270
- store (dict[str, bytes]): The underlying dictionary that stores
271
- the key-value pairs.
269
+ store: The underlying dictionary that stores the key-value pairs.
272
270
 
273
271
  Examples:
274
272
  ```python