langchain-core 1.0.0rc1__py3-none-any.whl → 1.0.0rc2__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 (92) hide show
  1. langchain_core/agents.py +3 -3
  2. langchain_core/caches.py +44 -48
  3. langchain_core/callbacks/base.py +5 -5
  4. langchain_core/callbacks/file.py +2 -2
  5. langchain_core/callbacks/stdout.py +1 -1
  6. langchain_core/chat_history.py +1 -1
  7. langchain_core/document_loaders/base.py +21 -21
  8. langchain_core/document_loaders/langsmith.py +2 -2
  9. langchain_core/documents/base.py +39 -39
  10. langchain_core/embeddings/fake.py +4 -2
  11. langchain_core/example_selectors/semantic_similarity.py +4 -6
  12. langchain_core/exceptions.py +3 -4
  13. langchain_core/indexing/api.py +8 -14
  14. langchain_core/language_models/__init__.py +11 -25
  15. langchain_core/language_models/_utils.py +2 -1
  16. langchain_core/language_models/base.py +7 -0
  17. langchain_core/language_models/chat_models.py +14 -16
  18. langchain_core/language_models/fake_chat_models.py +3 -3
  19. langchain_core/language_models/llms.py +4 -4
  20. langchain_core/load/dump.py +3 -4
  21. langchain_core/load/load.py +0 -9
  22. langchain_core/load/serializable.py +3 -3
  23. langchain_core/messages/ai.py +20 -22
  24. langchain_core/messages/base.py +8 -8
  25. langchain_core/messages/block_translators/__init__.py +1 -1
  26. langchain_core/messages/block_translators/anthropic.py +1 -1
  27. langchain_core/messages/block_translators/bedrock_converse.py +1 -1
  28. langchain_core/messages/block_translators/google_genai.py +3 -2
  29. langchain_core/messages/block_translators/google_vertexai.py +4 -32
  30. langchain_core/messages/block_translators/langchain_v0.py +1 -1
  31. langchain_core/messages/block_translators/openai.py +1 -1
  32. langchain_core/messages/chat.py +2 -6
  33. langchain_core/messages/content.py +34 -17
  34. langchain_core/messages/function.py +3 -7
  35. langchain_core/messages/human.py +4 -9
  36. langchain_core/messages/modifier.py +1 -1
  37. langchain_core/messages/system.py +2 -10
  38. langchain_core/messages/tool.py +30 -42
  39. langchain_core/messages/utils.py +24 -30
  40. langchain_core/output_parsers/base.py +24 -24
  41. langchain_core/output_parsers/json.py +0 -1
  42. langchain_core/output_parsers/list.py +1 -1
  43. langchain_core/output_parsers/openai_functions.py +2 -2
  44. langchain_core/output_parsers/openai_tools.py +4 -9
  45. langchain_core/output_parsers/string.py +1 -1
  46. langchain_core/outputs/generation.py +1 -1
  47. langchain_core/prompt_values.py +7 -7
  48. langchain_core/prompts/base.py +1 -1
  49. langchain_core/prompts/chat.py +12 -13
  50. langchain_core/prompts/dict.py +2 -2
  51. langchain_core/prompts/few_shot_with_templates.py +1 -1
  52. langchain_core/prompts/image.py +1 -1
  53. langchain_core/prompts/message.py +2 -2
  54. langchain_core/prompts/prompt.py +7 -8
  55. langchain_core/prompts/string.py +1 -1
  56. langchain_core/prompts/structured.py +2 -2
  57. langchain_core/rate_limiters.py +23 -29
  58. langchain_core/retrievers.py +29 -29
  59. langchain_core/runnables/base.py +9 -16
  60. langchain_core/runnables/branch.py +1 -1
  61. langchain_core/runnables/config.py +1 -1
  62. langchain_core/runnables/configurable.py +2 -2
  63. langchain_core/runnables/fallbacks.py +1 -1
  64. langchain_core/runnables/graph.py +23 -28
  65. langchain_core/runnables/graph_mermaid.py +9 -9
  66. langchain_core/runnables/graph_png.py +1 -1
  67. langchain_core/runnables/history.py +2 -2
  68. langchain_core/runnables/passthrough.py +3 -3
  69. langchain_core/runnables/router.py +1 -1
  70. langchain_core/runnables/utils.py +5 -5
  71. langchain_core/tools/base.py +9 -10
  72. langchain_core/tools/convert.py +13 -17
  73. langchain_core/tools/retriever.py +6 -6
  74. langchain_core/tools/simple.py +1 -1
  75. langchain_core/tools/structured.py +5 -10
  76. langchain_core/tracers/memory_stream.py +1 -1
  77. langchain_core/tracers/root_listeners.py +2 -2
  78. langchain_core/tracers/stdout.py +1 -2
  79. langchain_core/utils/__init__.py +1 -1
  80. langchain_core/utils/aiter.py +1 -1
  81. langchain_core/utils/function_calling.py +15 -38
  82. langchain_core/utils/input.py +1 -1
  83. langchain_core/utils/iter.py +1 -1
  84. langchain_core/utils/json.py +1 -1
  85. langchain_core/utils/strings.py +1 -1
  86. langchain_core/vectorstores/base.py +14 -25
  87. langchain_core/vectorstores/utils.py +2 -2
  88. langchain_core/version.py +1 -1
  89. {langchain_core-1.0.0rc1.dist-info → langchain_core-1.0.0rc2.dist-info}/METADATA +1 -1
  90. langchain_core-1.0.0rc2.dist-info/RECORD +172 -0
  91. langchain_core-1.0.0rc1.dist-info/RECORD +0 -172
  92. {langchain_core-1.0.0rc1.dist-info → langchain_core-1.0.0rc2.dist-info}/WHEEL +0 -0
@@ -276,7 +276,7 @@ class StringPromptTemplate(BasePromptTemplate, ABC):
276
276
 
277
277
  @classmethod
278
278
  def get_lc_namespace(cls) -> list[str]:
279
- """Get the namespace of the langchain object.
279
+ """Get the namespace of the LangChain object.
280
280
 
281
281
  Returns:
282
282
  `["langchain", "prompts", "base"]`
@@ -63,13 +63,13 @@ class StructuredPrompt(ChatPromptTemplate):
63
63
 
64
64
  @classmethod
65
65
  def get_lc_namespace(cls) -> list[str]:
66
- """Get the namespace of the langchain object.
66
+ """Get the namespace of the LangChain object.
67
67
 
68
68
  For example, if the class is `langchain.llms.openai.OpenAI`, then the
69
69
  namespace is `["langchain", "llms", "openai"]`
70
70
 
71
71
  Returns:
72
- The namespace of the langchain object.
72
+ The namespace of the LangChain object.
73
73
  """
74
74
  return cls.__module__.split(".")
75
75
 
@@ -21,11 +21,8 @@ class BaseRateLimiter(abc.ABC):
21
21
  Current limitations:
22
22
 
23
23
  - Rate limiting information is not surfaced in tracing or callbacks. This means
24
- that the total time it takes to invoke a chat model will encompass both
25
- the time spent waiting for tokens and the time spent making the request.
26
-
27
-
28
- !!! version-added "Added in version 0.2.24"
24
+ that the total time it takes to invoke a chat model will encompass both
25
+ the time spent waiting for tokens and the time spent making the request.
29
26
  """
30
27
 
31
28
  @abc.abstractmethod
@@ -33,18 +30,18 @@ class BaseRateLimiter(abc.ABC):
33
30
  """Attempt to acquire the necessary tokens for the rate limiter.
34
31
 
35
32
  This method blocks until the required tokens are available if `blocking`
36
- is set to True.
33
+ is set to `True`.
37
34
 
38
- If `blocking` is set to False, the method will immediately return the result
35
+ If `blocking` is set to `False`, the method will immediately return the result
39
36
  of the attempt to acquire the tokens.
40
37
 
41
38
  Args:
42
39
  blocking: If `True`, the method will block until the tokens are available.
43
40
  If `False`, the method will return immediately with the result of
44
- the attempt. Defaults to `True`.
41
+ the attempt.
45
42
 
46
43
  Returns:
47
- `True` if the tokens were successfully acquired, `False` otherwise.
44
+ `True` if the tokens were successfully acquired, `False` otherwise.
48
45
  """
49
46
 
50
47
  @abc.abstractmethod
@@ -52,18 +49,18 @@ class BaseRateLimiter(abc.ABC):
52
49
  """Attempt to acquire the necessary tokens for the rate limiter.
53
50
 
54
51
  This method blocks until the required tokens are available if `blocking`
55
- is set to True.
52
+ is set to `True`.
56
53
 
57
- If `blocking` is set to False, the method will immediately return the result
54
+ If `blocking` is set to `False`, the method will immediately return the result
58
55
  of the attempt to acquire the tokens.
59
56
 
60
57
  Args:
61
58
  blocking: If `True`, the method will block until the tokens are available.
62
59
  If `False`, the method will return immediately with the result of
63
- the attempt. Defaults to `True`.
60
+ the attempt.
64
61
 
65
62
  Returns:
66
- `True` if the tokens were successfully acquired, `False` otherwise.
63
+ `True` if the tokens were successfully acquired, `False` otherwise.
67
64
  """
68
65
 
69
66
 
@@ -84,7 +81,7 @@ class InMemoryRateLimiter(BaseRateLimiter):
84
81
  not enough tokens in the bucket, the request is blocked until there are
85
82
  enough tokens.
86
83
 
87
- These *tokens* have NOTHING to do with LLM tokens. They are just
84
+ These tokens have nothing to do with LLM tokens. They are just
88
85
  a way to keep track of how many requests can be made at a given time.
89
86
 
90
87
  Current limitations:
@@ -109,7 +106,7 @@ class InMemoryRateLimiter(BaseRateLimiter):
109
106
  from langchain_anthropic import ChatAnthropic
110
107
 
111
108
  model = ChatAnthropic(
112
- model_name="claude-3-opus-20240229", rate_limiter=rate_limiter
109
+ model_name="claude-sonnet-4-5-20250929", rate_limiter=rate_limiter
113
110
  )
114
111
 
115
112
  for _ in range(5):
@@ -118,9 +115,6 @@ class InMemoryRateLimiter(BaseRateLimiter):
118
115
  toc = time.time()
119
116
  print(toc - tic)
120
117
  ```
121
-
122
- !!! version-added "Added in version 0.2.24"
123
-
124
118
  """ # noqa: E501
125
119
 
126
120
  def __init__(
@@ -132,7 +126,7 @@ class InMemoryRateLimiter(BaseRateLimiter):
132
126
  ) -> None:
133
127
  """A rate limiter based on a token bucket.
134
128
 
135
- These *tokens* have NOTHING to do with LLM tokens. They are just
129
+ These tokens have nothing to do with LLM tokens. They are just
136
130
  a way to keep track of how many requests can be made at a given time.
137
131
 
138
132
  This rate limiter is designed to work in a threaded environment.
@@ -145,11 +139,11 @@ class InMemoryRateLimiter(BaseRateLimiter):
145
139
  Args:
146
140
  requests_per_second: The number of tokens to add per second to the bucket.
147
141
  The tokens represent "credit" that can be used to make requests.
148
- check_every_n_seconds: check whether the tokens are available
142
+ check_every_n_seconds: Check whether the tokens are available
149
143
  every this many seconds. Can be a float to represent
150
144
  fractions of a second.
151
145
  max_bucket_size: The maximum number of tokens that can be in the bucket.
152
- Must be at least 1. Used to prevent bursts of requests.
146
+ Must be at least `1`. Used to prevent bursts of requests.
153
147
  """
154
148
  # Number of requests that we can make per second.
155
149
  self.requests_per_second = requests_per_second
@@ -199,18 +193,18 @@ class InMemoryRateLimiter(BaseRateLimiter):
199
193
  """Attempt to acquire a token from the rate limiter.
200
194
 
201
195
  This method blocks until the required tokens are available if `blocking`
202
- is set to True.
196
+ is set to `True`.
203
197
 
204
- If `blocking` is set to False, the method will immediately return the result
198
+ If `blocking` is set to `False`, the method will immediately return the result
205
199
  of the attempt to acquire the tokens.
206
200
 
207
201
  Args:
208
202
  blocking: If `True`, the method will block until the tokens are available.
209
203
  If `False`, the method will return immediately with the result of
210
- the attempt. Defaults to `True`.
204
+ the attempt.
211
205
 
212
206
  Returns:
213
- `True` if the tokens were successfully acquired, `False` otherwise.
207
+ `True` if the tokens were successfully acquired, `False` otherwise.
214
208
  """
215
209
  if not blocking:
216
210
  return self._consume()
@@ -223,18 +217,18 @@ class InMemoryRateLimiter(BaseRateLimiter):
223
217
  """Attempt to acquire a token from the rate limiter. Async version.
224
218
 
225
219
  This method blocks until the required tokens are available if `blocking`
226
- is set to True.
220
+ is set to `True`.
227
221
 
228
- If `blocking` is set to False, the method will immediately return the result
222
+ If `blocking` is set to `False`, the method will immediately return the result
229
223
  of the attempt to acquire the tokens.
230
224
 
231
225
  Args:
232
226
  blocking: If `True`, the method will block until the tokens are available.
233
227
  If `False`, the method will return immediately with the result of
234
- the attempt. Defaults to `True`.
228
+ the attempt.
235
229
 
236
230
  Returns:
237
- `True` if the tokens were successfully acquired, `False` otherwise.
231
+ `True` if the tokens were successfully acquired, `False` otherwise.
238
232
  """
239
233
  if not blocking:
240
234
  return self._consume()
@@ -70,45 +70,45 @@ class BaseRetriever(RunnableSerializable[RetrieverInput, RetrieverOutput], ABC):
70
70
 
71
71
  Example: A 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
90
  Example: A 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(
@@ -871,7 +871,6 @@ class Runnable(ABC, Generic[Input, Output]):
871
871
  to do in parallel, and other keys. Please refer to the
872
872
  `RunnableConfig` for more details.
873
873
  return_exceptions: Whether to return exceptions instead of raising them.
874
- Defaults to `False`.
875
874
  **kwargs: Additional keyword arguments to pass to the `Runnable`.
876
875
 
877
876
  Returns:
@@ -938,7 +937,6 @@ class Runnable(ABC, Generic[Input, Output]):
938
937
  do in parallel, and other keys. Please refer to the `RunnableConfig`
939
938
  for more details.
940
939
  return_exceptions: Whether to return exceptions instead of raising them.
941
- Defaults to `False`.
942
940
  **kwargs: Additional keyword arguments to pass to the `Runnable`.
943
941
 
944
942
  Yields:
@@ -1005,7 +1003,6 @@ class Runnable(ABC, Generic[Input, Output]):
1005
1003
  do in parallel, and other keys. Please refer to the `RunnableConfig`
1006
1004
  for more details.
1007
1005
  return_exceptions: Whether to return exceptions instead of raising them.
1008
- Defaults to `False`.
1009
1006
  **kwargs: Additional keyword arguments to pass to the `Runnable`.
1010
1007
 
1011
1008
  Returns:
@@ -1069,7 +1066,6 @@ class Runnable(ABC, Generic[Input, Output]):
1069
1066
  do in parallel, and other keys. Please refer to the `RunnableConfig`
1070
1067
  for more details.
1071
1068
  return_exceptions: Whether to return exceptions instead of raising them.
1072
- Defaults to `False`.
1073
1069
  **kwargs: Additional keyword arguments to pass to the `Runnable`.
1074
1070
 
1075
1071
  Yields:
@@ -1357,7 +1353,8 @@ class Runnable(ABC, Generic[Input, Output]):
1357
1353
  ).with_config({"run_name": "my_template", "tags": ["my_template"]})
1358
1354
  ```
1359
1355
 
1360
- Example:
1356
+ For instance:
1357
+
1361
1358
  ```python
1362
1359
  from langchain_core.runnables import RunnableLambda
1363
1360
 
@@ -1837,11 +1834,10 @@ class Runnable(ABC, Generic[Input, Output]):
1837
1834
 
1838
1835
  Args:
1839
1836
  retry_if_exception_type: A tuple of exception types to retry on.
1840
- Defaults to (Exception,).
1841
1837
  wait_exponential_jitter: Whether to add jitter to the wait
1842
- time between retries. Defaults to `True`.
1838
+ time between retries.
1843
1839
  stop_after_attempt: The maximum number of attempts to make before
1844
- giving up. Defaults to 3.
1840
+ giving up.
1845
1841
  exponential_jitter_params: Parameters for
1846
1842
  `tenacity.wait_exponential_jitter`. Namely: `initial`, `max`,
1847
1843
  `exp_base`, and `jitter` (all float values).
@@ -1929,7 +1925,6 @@ class Runnable(ABC, Generic[Input, Output]):
1929
1925
  fallbacks: A sequence of runnables to try if the original `Runnable`
1930
1926
  fails.
1931
1927
  exceptions_to_handle: A tuple of exception types to handle.
1932
- Defaults to `(Exception,)`.
1933
1928
  exception_key: If string is specified then handled exceptions will be passed
1934
1929
  to fallbacks as part of the input under the specified key.
1935
1930
  If `None`, exceptions will not be passed to fallbacks.
@@ -2633,9 +2628,7 @@ class RunnableSerializable(Serializable, Runnable[Input, Output]):
2633
2628
  which: The `ConfigurableField` instance that will be used to select the
2634
2629
  alternative.
2635
2630
  default_key: The default key to use if no alternative is selected.
2636
- Defaults to `'default'`.
2637
2631
  prefix_keys: Whether to prefix the keys with the `ConfigurableField` id.
2638
- Defaults to `False`.
2639
2632
  **kwargs: A dictionary of keys to `Runnable` instances or callables that
2640
2633
  return `Runnable` instances.
2641
2634
 
@@ -2896,7 +2889,7 @@ class RunnableSequence(RunnableSerializable[Input, Output]):
2896
2889
  @classmethod
2897
2890
  @override
2898
2891
  def get_lc_namespace(cls) -> list[str]:
2899
- """Get the namespace of the langchain object.
2892
+ """Get the namespace of the LangChain object.
2900
2893
 
2901
2894
  Returns:
2902
2895
  `["langchain", "schema", "runnable"]`
@@ -3627,7 +3620,7 @@ class RunnableParallel(RunnableSerializable[Input, dict[str, Any]]):
3627
3620
  @classmethod
3628
3621
  @override
3629
3622
  def get_lc_namespace(cls) -> list[str]:
3630
- """Get the namespace of the langchain object.
3623
+ """Get the namespace of the LangChain object.
3631
3624
 
3632
3625
  Returns:
3633
3626
  `["langchain", "schema", "runnable"]`
@@ -5156,7 +5149,7 @@ class RunnableEachBase(RunnableSerializable[list[Input], list[Output]]):
5156
5149
  @classmethod
5157
5150
  @override
5158
5151
  def get_lc_namespace(cls) -> list[str]:
5159
- """Get the namespace of the langchain object.
5152
+ """Get the namespace of the LangChain object.
5160
5153
 
5161
5154
  Returns:
5162
5155
  `["langchain", "schema", "runnable"]`
@@ -5479,7 +5472,7 @@ class RunnableBindingBase(RunnableSerializable[Input, Output]): # type: ignore[
5479
5472
  @classmethod
5480
5473
  @override
5481
5474
  def get_lc_namespace(cls) -> list[str]:
5482
- """Get the namespace of the langchain object.
5475
+ """Get the namespace of the LangChain object.
5483
5476
 
5484
5477
  Returns:
5485
5478
  `["langchain", "schema", "runnable"]`
@@ -5761,7 +5754,7 @@ class RunnableBinding(RunnableBindingBase[Input, Output]): # type: ignore[no-re
5761
5754
  `bind`: Bind kwargs to pass to the underlying `Runnable` when running it.
5762
5755
 
5763
5756
  ```python
5764
- # Create a Runnable binding that invokes the ChatModel with the
5757
+ # Create a Runnable binding that invokes the chat model with the
5765
5758
  # additional kwarg `stop=['-']` when running it.
5766
5759
  from langchain_community.chat_models import ChatOpenAI
5767
5760
 
@@ -146,7 +146,7 @@ class RunnableBranch(RunnableSerializable[Input, Output]):
146
146
  @classmethod
147
147
  @override
148
148
  def get_lc_namespace(cls) -> list[str]:
149
- """Get the namespace of the langchain object.
149
+ """Get the namespace of the LangChain object.
150
150
 
151
151
  Returns:
152
152
  `["langchain", "schema", "runnable"]`
@@ -536,7 +536,7 @@ class ContextThreadPoolExecutor(ThreadPoolExecutor):
536
536
  fn: The function to map.
537
537
  *iterables: The iterables to map over.
538
538
  timeout: The timeout for the map.
539
- chunksize: The chunksize for the map. Defaults to 1.
539
+ chunksize: The chunksize for the map.
540
540
 
541
541
  Returns:
542
542
  The iterator for the mapped function.
@@ -72,7 +72,7 @@ class DynamicRunnable(RunnableSerializable[Input, Output]):
72
72
  @classmethod
73
73
  @override
74
74
  def get_lc_namespace(cls) -> list[str]:
75
- """Get the namespace of the langchain object.
75
+ """Get the namespace of the LangChain object.
76
76
 
77
77
  Returns:
78
78
  `["langchain", "schema", "runnable"]`
@@ -540,7 +540,7 @@ class RunnableConfigurableAlternatives(DynamicRunnable[Input, Output]):
540
540
  """The alternatives to choose from."""
541
541
 
542
542
  default_key: str = "default"
543
- """The enum value to use for the default option. Defaults to `'default'`."""
543
+ """The enum value to use for the default option."""
544
544
 
545
545
  prefix_keys: bool
546
546
  """Whether to prefix configurable fields of each alternative with a namespace
@@ -143,7 +143,7 @@ class RunnableWithFallbacks(RunnableSerializable[Input, Output]):
143
143
  @classmethod
144
144
  @override
145
145
  def get_lc_namespace(cls) -> list[str]:
146
- """Get the namespace of the langchain object.
146
+ """Get the namespace of the LangChain object.
147
147
 
148
148
  Returns:
149
149
  `["langchain", "schema", "runnable"]`
@@ -71,7 +71,7 @@ class Edge(NamedTuple):
71
71
  data: Stringifiable | None = None
72
72
  """Optional data associated with the edge. """
73
73
  conditional: bool = False
74
- """Whether the edge is conditional. Defaults to `False`."""
74
+ """Whether the edge is conditional."""
75
75
 
76
76
  def copy(self, *, source: str | None = None, target: str | None = None) -> Edge:
77
77
  """Return a copy of the edge with optional new source and target nodes.
@@ -157,9 +157,9 @@ class NodeStyles:
157
157
  """Schema for Hexadecimal color codes for different node types.
158
158
 
159
159
  Args:
160
- default: The default color code. Defaults to "fill:#f2f0ff,line-height:1.2".
161
- first: The color code for the first node. Defaults to "fill-opacity:0".
162
- last: The color code for the last node. Defaults to "fill:#bfb6fc".
160
+ default: The default color code.
161
+ first: The color code for the first node.
162
+ last: The color code for the last node.
163
163
  """
164
164
 
165
165
  default: str = "fill:#f2f0ff,line-height:1.2"
@@ -201,9 +201,9 @@ def node_data_json(
201
201
  """Convert the data of a node to a JSON-serializable format.
202
202
 
203
203
  Args:
204
- node: The node to convert.
205
- with_schemas: Whether to include the schema of the data if
206
- it is a Pydantic model. Defaults to `False`.
204
+ node: The `Node` to convert.
205
+ with_schemas: Whether to include the schema of the data if it is a Pydantic
206
+ model.
207
207
 
208
208
  Returns:
209
209
  A dictionary with the type of the data and the data itself.
@@ -267,7 +267,7 @@ class Graph:
267
267
 
268
268
  Args:
269
269
  with_schemas: Whether to include the schemas of the nodes if they are
270
- Pydantic models. Defaults to `False`.
270
+ Pydantic models.
271
271
 
272
272
  Returns:
273
273
  A dictionary with the nodes and edges of the graph.
@@ -362,7 +362,7 @@ class Graph:
362
362
  source: The source node of the edge.
363
363
  target: The target node of the edge.
364
364
  data: Optional data associated with the edge.
365
- conditional: Whether the edge is conditional. Defaults to `False`.
365
+ conditional: Whether the edge is conditional.
366
366
 
367
367
  Returns:
368
368
  The edge that was added to the graph.
@@ -391,7 +391,7 @@ class Graph:
391
391
 
392
392
  Args:
393
393
  graph: The graph to add.
394
- prefix: The prefix to add to the node ids. Defaults to "".
394
+ prefix: The prefix to add to the node ids.
395
395
 
396
396
  Returns:
397
397
  A tuple of the first and last nodes of the subgraph.
@@ -458,7 +458,7 @@ class Graph:
458
458
  def first_node(self) -> Node | None:
459
459
  """Find the single node that is not a target of any edge.
460
460
 
461
- If there is no such node, or there are multiple, return None.
461
+ If there is no such node, or there are multiple, return `None`.
462
462
  When drawing the graph, this node would be the origin.
463
463
 
464
464
  Returns:
@@ -470,7 +470,7 @@ class Graph:
470
470
  def last_node(self) -> Node | None:
471
471
  """Find the single node that is not a source of any edge.
472
472
 
473
- If there is no such node, or there are multiple, return None.
473
+ If there is no such node, or there are multiple, return `None`.
474
474
  When drawing the graph, this node would be the destination.
475
475
 
476
476
  Returns:
@@ -585,11 +585,10 @@ class Graph:
585
585
  """Draw the graph as a Mermaid syntax string.
586
586
 
587
587
  Args:
588
- with_styles: Whether to include styles in the syntax. Defaults to `True`.
589
- curve_style: The style of the edges. Defaults to CurveStyle.LINEAR.
590
- node_colors: The colors of the nodes. Defaults to NodeStyles().
588
+ with_styles: Whether to include styles in the syntax.
589
+ curve_style: The style of the edges.
590
+ node_colors: The colors of the nodes.
591
591
  wrap_label_n_words: The number of words to wrap the node labels at.
592
- Defaults to 9.
593
592
  frontmatter_config: Mermaid frontmatter config.
594
593
  Can be used to customize theme and styles. Will be converted to YAML and
595
594
  added to the beginning of the mermaid graph.
@@ -647,20 +646,16 @@ class Graph:
647
646
  """Draw the graph as a PNG image using Mermaid.
648
647
 
649
648
  Args:
650
- curve_style: The style of the edges. Defaults to CurveStyle.LINEAR.
651
- node_colors: The colors of the nodes. Defaults to NodeStyles().
649
+ curve_style: The style of the edges.
650
+ node_colors: The colors of the nodes.
652
651
  wrap_label_n_words: The number of words to wrap the node labels at.
653
- Defaults to 9.
654
652
  output_file_path: The path to save the image to. If `None`, the image
655
653
  is not saved.
656
654
  draw_method: The method to use to draw the graph.
657
- Defaults to MermaidDrawMethod.API.
658
- background_color: The color of the background. Defaults to "white".
659
- padding: The padding around the graph. Defaults to 10.
660
- max_retries: The maximum number of retries (MermaidDrawMethod.API).
661
- Defaults to 1.
662
- retry_delay: The delay between retries (MermaidDrawMethod.API).
663
- Defaults to 1.0.
655
+ background_color: The color of the background.
656
+ padding: The padding around the graph.
657
+ max_retries: The maximum number of retries (`MermaidDrawMethod.API`).
658
+ retry_delay: The delay between retries (`MermaidDrawMethod.API`).
664
659
  frontmatter_config: Mermaid frontmatter config.
665
660
  Can be used to customize theme and styles. Will be converted to YAML and
666
661
  added to the beginning of the mermaid graph.
@@ -712,7 +707,7 @@ def _first_node(graph: Graph, exclude: Sequence[str] = ()) -> Node | None:
712
707
  """Find the single node that is not a target of any edge.
713
708
 
714
709
  Exclude nodes/sources with ids in the exclude list.
715
- If there is no such node, or there are multiple, return None.
710
+ If there is no such node, or there are multiple, return `None`.
716
711
  When drawing the graph, this node would be the origin.
717
712
  """
718
713
  targets = {edge.target for edge in graph.edges if edge.source not in exclude}
@@ -728,7 +723,7 @@ def _last_node(graph: Graph, exclude: Sequence[str] = ()) -> Node | None:
728
723
  """Find the single node that is not a source of any edge.
729
724
 
730
725
  Exclude nodes/targets with ids in the exclude list.
731
- If there is no such node, or there are multiple, return None.
726
+ If there is no such node, or there are multiple, return `None`.
732
727
  When drawing the graph, this node would be the destination.
733
728
  """
734
729
  sources = {edge.source for edge in graph.edges if edge.target not in exclude}
@@ -60,10 +60,10 @@ def draw_mermaid(
60
60
  edges: List of edges, object with a source, target and data.
61
61
  first_node: Id of the first node.
62
62
  last_node: Id of the last node.
63
- with_styles: Whether to include styles in the graph. Defaults to `True`.
64
- curve_style: Curve style for the edges. Defaults to CurveStyle.LINEAR.
65
- node_styles: Node colors for different types. Defaults to NodeStyles().
66
- wrap_label_n_words: Words to wrap the edge labels. Defaults to 9.
63
+ with_styles: Whether to include styles in the graph.
64
+ curve_style: Curve style for the edges.
65
+ node_styles: Node colors for different types.
66
+ wrap_label_n_words: Words to wrap the edge labels.
67
67
  frontmatter_config: Mermaid frontmatter config.
68
68
  Can be used to customize theme and styles. Will be converted to YAML and
69
69
  added to the beginning of the mermaid graph.
@@ -287,11 +287,11 @@ def draw_mermaid_png(
287
287
  Args:
288
288
  mermaid_syntax: Mermaid graph syntax.
289
289
  output_file_path: Path to save the PNG image.
290
- draw_method: Method to draw the graph. Defaults to MermaidDrawMethod.API.
291
- background_color: Background color of the image. Defaults to "white".
292
- padding: Padding around the image. Defaults to 10.
293
- max_retries: Maximum number of retries (MermaidDrawMethod.API). Defaults to 1.
294
- retry_delay: Delay between retries (MermaidDrawMethod.API). Defaults to 1.0.
290
+ draw_method: Method to draw the graph.
291
+ background_color: Background color of the image.
292
+ padding: Padding around the image.
293
+ max_retries: Maximum number of retries (MermaidDrawMethod.API).
294
+ retry_delay: Delay between retries (MermaidDrawMethod.API).
295
295
  base_url: Base URL for the Mermaid.ink API.
296
296
 
297
297
  Returns:
@@ -105,7 +105,7 @@ class PngDrawer:
105
105
  source: The source node.
106
106
  target: The target node.
107
107
  label: The label for the edge.
108
- conditional: Whether the edge is conditional. Defaults to `False`.
108
+ conditional: Whether the edge is conditional.
109
109
  """
110
110
  viz.add_edge(
111
111
  source,
@@ -296,9 +296,9 @@ class RunnableWithMessageHistory(RunnableBindingBase): # type: ignore[no-redef]
296
296
  ```
297
297
 
298
298
  input_messages_key: Must be specified if the base runnable accepts a dict
299
- as input. Default is None.
299
+ as input.
300
300
  output_messages_key: Must be specified if the base runnable returns a dict
301
- as output. Default is None.
301
+ as output.
302
302
  history_messages_key: Must be specified if the base runnable accepts a dict
303
303
  as input and expects a separate key for historical messages.
304
304
  history_factory_config: Configure fields that should be passed to the
@@ -185,7 +185,7 @@ class RunnablePassthrough(RunnableSerializable[Other, Other]):
185
185
 
186
186
  @classmethod
187
187
  def get_lc_namespace(cls) -> list[str]:
188
- """Get the namespace of the langchain object.
188
+ """Get the namespace of the LangChain object.
189
189
 
190
190
  Returns:
191
191
  `["langchain", "schema", "runnable"]`
@@ -409,7 +409,7 @@ class RunnableAssign(RunnableSerializable[dict[str, Any], dict[str, Any]]):
409
409
  @classmethod
410
410
  @override
411
411
  def get_lc_namespace(cls) -> list[str]:
412
- """Get the namespace of the langchain object.
412
+ """Get the namespace of the LangChain object.
413
413
 
414
414
  Returns:
415
415
  `["langchain", "schema", "runnable"]`
@@ -714,7 +714,7 @@ class RunnablePick(RunnableSerializable[dict[str, Any], dict[str, Any]]):
714
714
  @classmethod
715
715
  @override
716
716
  def get_lc_namespace(cls) -> list[str]:
717
- """Get the namespace of the langchain object.
717
+ """Get the namespace of the LangChain object.
718
718
 
719
719
  Returns:
720
720
  `["langchain", "schema", "runnable"]`
@@ -96,7 +96,7 @@ class RouterRunnable(RunnableSerializable[RouterInput, Output]):
96
96
  @classmethod
97
97
  @override
98
98
  def get_lc_namespace(cls) -> list[str]:
99
- """Get the namespace of the langchain object.
99
+ """Get the namespace of the LangChain object.
100
100
 
101
101
  Returns:
102
102
  `["langchain", "schema", "runnable"]`