langchain-core 1.0.0a8__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 (142) hide show
  1. langchain_core/__init__.py +1 -1
  2. langchain_core/_api/__init__.py +0 -1
  3. langchain_core/_api/beta_decorator.py +17 -20
  4. langchain_core/_api/deprecation.py +30 -35
  5. langchain_core/_import_utils.py +1 -1
  6. langchain_core/agents.py +10 -9
  7. langchain_core/caches.py +46 -56
  8. langchain_core/callbacks/__init__.py +1 -8
  9. langchain_core/callbacks/base.py +232 -243
  10. langchain_core/callbacks/file.py +33 -33
  11. langchain_core/callbacks/manager.py +353 -416
  12. langchain_core/callbacks/stdout.py +21 -22
  13. langchain_core/callbacks/streaming_stdout.py +32 -32
  14. langchain_core/callbacks/usage.py +54 -51
  15. langchain_core/chat_history.py +43 -58
  16. langchain_core/document_loaders/base.py +21 -21
  17. langchain_core/document_loaders/langsmith.py +22 -22
  18. langchain_core/documents/__init__.py +0 -1
  19. langchain_core/documents/base.py +46 -49
  20. langchain_core/documents/transformers.py +28 -29
  21. langchain_core/embeddings/fake.py +50 -54
  22. langchain_core/example_selectors/semantic_similarity.py +4 -6
  23. langchain_core/exceptions.py +7 -8
  24. langchain_core/indexing/api.py +19 -25
  25. langchain_core/indexing/base.py +24 -24
  26. langchain_core/language_models/__init__.py +11 -27
  27. langchain_core/language_models/_utils.py +53 -54
  28. langchain_core/language_models/base.py +30 -24
  29. langchain_core/language_models/chat_models.py +123 -148
  30. langchain_core/language_models/fake_chat_models.py +7 -7
  31. langchain_core/language_models/llms.py +14 -16
  32. langchain_core/load/dump.py +3 -4
  33. langchain_core/load/load.py +7 -16
  34. langchain_core/load/serializable.py +37 -36
  35. langchain_core/messages/__init__.py +1 -16
  36. langchain_core/messages/ai.py +122 -123
  37. langchain_core/messages/base.py +31 -31
  38. langchain_core/messages/block_translators/__init__.py +17 -17
  39. langchain_core/messages/block_translators/anthropic.py +3 -3
  40. langchain_core/messages/block_translators/bedrock_converse.py +3 -3
  41. langchain_core/messages/block_translators/google_genai.py +5 -4
  42. langchain_core/messages/block_translators/google_vertexai.py +4 -32
  43. langchain_core/messages/block_translators/groq.py +117 -21
  44. langchain_core/messages/block_translators/langchain_v0.py +3 -3
  45. langchain_core/messages/block_translators/openai.py +5 -5
  46. langchain_core/messages/chat.py +2 -6
  47. langchain_core/messages/content.py +222 -209
  48. langchain_core/messages/function.py +6 -10
  49. langchain_core/messages/human.py +17 -24
  50. langchain_core/messages/modifier.py +2 -2
  51. langchain_core/messages/system.py +12 -22
  52. langchain_core/messages/tool.py +53 -69
  53. langchain_core/messages/utils.py +399 -417
  54. langchain_core/output_parsers/__init__.py +1 -14
  55. langchain_core/output_parsers/base.py +46 -47
  56. langchain_core/output_parsers/json.py +3 -4
  57. langchain_core/output_parsers/list.py +2 -2
  58. langchain_core/output_parsers/openai_functions.py +46 -44
  59. langchain_core/output_parsers/openai_tools.py +11 -16
  60. langchain_core/output_parsers/pydantic.py +10 -11
  61. langchain_core/output_parsers/string.py +2 -2
  62. langchain_core/output_parsers/transform.py +2 -2
  63. langchain_core/output_parsers/xml.py +1 -1
  64. langchain_core/outputs/__init__.py +1 -1
  65. langchain_core/outputs/chat_generation.py +14 -14
  66. langchain_core/outputs/generation.py +6 -6
  67. langchain_core/outputs/llm_result.py +5 -5
  68. langchain_core/prompt_values.py +11 -11
  69. langchain_core/prompts/__init__.py +3 -23
  70. langchain_core/prompts/base.py +33 -38
  71. langchain_core/prompts/chat.py +222 -229
  72. langchain_core/prompts/dict.py +3 -3
  73. langchain_core/prompts/few_shot.py +76 -83
  74. langchain_core/prompts/few_shot_with_templates.py +7 -9
  75. langchain_core/prompts/image.py +12 -14
  76. langchain_core/prompts/loading.py +1 -1
  77. langchain_core/prompts/message.py +3 -3
  78. langchain_core/prompts/prompt.py +20 -23
  79. langchain_core/prompts/string.py +20 -8
  80. langchain_core/prompts/structured.py +26 -27
  81. langchain_core/rate_limiters.py +50 -58
  82. langchain_core/retrievers.py +41 -182
  83. langchain_core/runnables/base.py +565 -597
  84. langchain_core/runnables/branch.py +8 -8
  85. langchain_core/runnables/config.py +37 -44
  86. langchain_core/runnables/configurable.py +9 -10
  87. langchain_core/runnables/fallbacks.py +9 -9
  88. langchain_core/runnables/graph.py +46 -50
  89. langchain_core/runnables/graph_ascii.py +19 -18
  90. langchain_core/runnables/graph_mermaid.py +20 -31
  91. langchain_core/runnables/graph_png.py +7 -7
  92. langchain_core/runnables/history.py +22 -22
  93. langchain_core/runnables/passthrough.py +11 -11
  94. langchain_core/runnables/retry.py +3 -3
  95. langchain_core/runnables/router.py +2 -2
  96. langchain_core/runnables/schema.py +33 -33
  97. langchain_core/runnables/utils.py +30 -34
  98. langchain_core/stores.py +72 -102
  99. langchain_core/sys_info.py +27 -29
  100. langchain_core/tools/__init__.py +1 -14
  101. langchain_core/tools/base.py +70 -71
  102. langchain_core/tools/convert.py +100 -104
  103. langchain_core/tools/render.py +9 -9
  104. langchain_core/tools/retriever.py +7 -7
  105. langchain_core/tools/simple.py +6 -7
  106. langchain_core/tools/structured.py +18 -24
  107. langchain_core/tracers/__init__.py +1 -9
  108. langchain_core/tracers/base.py +35 -35
  109. langchain_core/tracers/context.py +12 -17
  110. langchain_core/tracers/event_stream.py +3 -3
  111. langchain_core/tracers/langchain.py +8 -8
  112. langchain_core/tracers/log_stream.py +17 -18
  113. langchain_core/tracers/memory_stream.py +3 -3
  114. langchain_core/tracers/root_listeners.py +2 -2
  115. langchain_core/tracers/schemas.py +0 -129
  116. langchain_core/tracers/stdout.py +1 -2
  117. langchain_core/utils/__init__.py +1 -1
  118. langchain_core/utils/aiter.py +32 -32
  119. langchain_core/utils/env.py +5 -5
  120. langchain_core/utils/function_calling.py +59 -154
  121. langchain_core/utils/html.py +4 -4
  122. langchain_core/utils/input.py +3 -3
  123. langchain_core/utils/interactive_env.py +1 -1
  124. langchain_core/utils/iter.py +20 -20
  125. langchain_core/utils/json.py +1 -1
  126. langchain_core/utils/json_schema.py +2 -2
  127. langchain_core/utils/mustache.py +5 -5
  128. langchain_core/utils/pydantic.py +17 -17
  129. langchain_core/utils/strings.py +5 -5
  130. langchain_core/utils/utils.py +25 -28
  131. langchain_core/vectorstores/base.py +55 -87
  132. langchain_core/vectorstores/in_memory.py +83 -85
  133. langchain_core/vectorstores/utils.py +2 -2
  134. langchain_core/version.py +1 -1
  135. {langchain_core-1.0.0a8.dist-info → langchain_core-1.0.0rc2.dist-info}/METADATA +23 -11
  136. langchain_core-1.0.0rc2.dist-info/RECORD +172 -0
  137. langchain_core/memory.py +0 -120
  138. langchain_core/pydantic_v1/__init__.py +0 -30
  139. langchain_core/pydantic_v1/dataclasses.py +0 -23
  140. langchain_core/pydantic_v1/main.py +0 -23
  141. langchain_core-1.0.0a8.dist-info/RECORD +0 -176
  142. {langchain_core-1.0.0a8.dist-info → langchain_core-1.0.0rc2.dist-info}/WHEEL +0 -0
@@ -146,10 +146,10 @@ 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
- ``["langchain", "schema", "runnable"]``
152
+ `["langchain", "schema", "runnable"]`
153
153
  """
154
154
  return ["langchain", "schema", "runnable"]
155
155
 
@@ -191,8 +191,8 @@ class RunnableBranch(RunnableSerializable[Input, Output]):
191
191
 
192
192
  Args:
193
193
  input: The input to the Runnable.
194
- config: The configuration for the Runnable. Defaults to None.
195
- kwargs: Additional keyword arguments to pass to the Runnable.
194
+ config: The configuration for the Runnable.
195
+ **kwargs: Additional keyword arguments to pass to the Runnable.
196
196
 
197
197
  Returns:
198
198
  The output of the branch that was run.
@@ -301,8 +301,8 @@ class RunnableBranch(RunnableSerializable[Input, Output]):
301
301
 
302
302
  Args:
303
303
  input: The input to the Runnable.
304
- config: The configuration for the Runnable. Defaults to None.
305
- kwargs: Additional keyword arguments to pass to the Runnable.
304
+ config: The configuration for the Runnable.
305
+ **kwargs: Additional keyword arguments to pass to the Runnable.
306
306
 
307
307
  Yields:
308
308
  The output of the branch that was run.
@@ -385,8 +385,8 @@ class RunnableBranch(RunnableSerializable[Input, Output]):
385
385
 
386
386
  Args:
387
387
  input: The input to the Runnable.
388
- config: The configuration for the Runnable. Defaults to None.
389
- kwargs: Additional keyword arguments to pass to the Runnable.
388
+ config: The configuration for the Runnable.
389
+ **kwargs: Additional keyword arguments to pass to the Runnable.
390
390
 
391
391
  Yields:
392
392
  The output of the branch that was run.
@@ -131,7 +131,7 @@ def _set_config_context(
131
131
  """Set the child Runnable config + tracing context.
132
132
 
133
133
  Args:
134
- config (RunnableConfig): The config to set.
134
+ config: The config to set.
135
135
 
136
136
  Returns:
137
137
  The token to reset the config and the previous tracing context.
@@ -165,7 +165,7 @@ def set_config_context(config: RunnableConfig) -> Generator[Context, None, None]
165
165
  """Set the child Runnable config + tracing context.
166
166
 
167
167
  Args:
168
- config (RunnableConfig): The config to set.
168
+ config: The config to set.
169
169
 
170
170
  Yields:
171
171
  The config context.
@@ -193,11 +193,10 @@ def ensure_config(config: RunnableConfig | None = None) -> RunnableConfig:
193
193
  """Ensure that a config is a dict with all keys present.
194
194
 
195
195
  Args:
196
- config (Optional[RunnableConfig], optional): The config to ensure.
197
- Defaults to None.
196
+ config: The config to ensure.
198
197
 
199
198
  Returns:
200
- RunnableConfig: The ensured config.
199
+ The ensured config.
201
200
  """
202
201
  empty = RunnableConfig(
203
202
  tags=[],
@@ -251,12 +250,11 @@ def get_config_list(
251
250
  It is useful for subclasses overriding batch() or abatch().
252
251
 
253
252
  Args:
254
- config (Optional[Union[RunnableConfig, list[RunnableConfig]]]):
255
- The config or list of configs.
256
- length (int): The length of the list.
253
+ config: The config or list of configs.
254
+ length: The length of the list.
257
255
 
258
256
  Returns:
259
- list[RunnableConfig]: The list of configs.
257
+ The list of configs.
260
258
 
261
259
  Raises:
262
260
  ValueError: If the length of the list is not equal to the length of the inputs.
@@ -302,19 +300,15 @@ def patch_config(
302
300
  """Patch a config with new values.
303
301
 
304
302
  Args:
305
- config (Optional[RunnableConfig]): The config to patch.
306
- callbacks (Optional[BaseCallbackManager], optional): The callbacks to set.
307
- Defaults to None.
308
- recursion_limit (Optional[int], optional): The recursion limit to set.
309
- Defaults to None.
310
- max_concurrency (Optional[int], optional): The max concurrency to set.
311
- Defaults to None.
312
- run_name (Optional[str], optional): The run name to set. Defaults to None.
313
- configurable (Optional[dict[str, Any]], optional): The configurable to set.
314
- Defaults to None.
303
+ config: The config to patch.
304
+ callbacks: The callbacks to set.
305
+ recursion_limit: The recursion limit to set.
306
+ max_concurrency: The max concurrency to set.
307
+ run_name: The run name to set.
308
+ configurable: The configurable to set.
315
309
 
316
310
  Returns:
317
- RunnableConfig: The patched config.
311
+ The patched config.
318
312
  """
319
313
  config = ensure_config(config)
320
314
  if callbacks is not None:
@@ -340,10 +334,10 @@ def merge_configs(*configs: RunnableConfig | None) -> RunnableConfig:
340
334
  """Merge multiple configs into one.
341
335
 
342
336
  Args:
343
- *configs (Optional[RunnableConfig]): The configs to merge.
337
+ *configs: The configs to merge.
344
338
 
345
339
  Returns:
346
- RunnableConfig: The merged config.
340
+ The merged config.
347
341
  """
348
342
  base: RunnableConfig = {}
349
343
  # Even though the keys aren't literals, this is correct
@@ -418,7 +412,7 @@ def call_func_with_variable_args(
418
412
  func: The function to call.
419
413
  input: The input to the function.
420
414
  config: The config to pass to the function.
421
- run_manager: The run manager to pass to the function. Defaults to None.
415
+ run_manager: The run manager to pass to the function.
422
416
  **kwargs: The keyword arguments to pass to the function.
423
417
 
424
418
  Returns:
@@ -452,7 +446,7 @@ def acall_func_with_variable_args(
452
446
  func: The function to call.
453
447
  input: The input to the function.
454
448
  config: The config to pass to the function.
455
- run_manager: The run manager to pass to the function. Defaults to None.
449
+ run_manager: The run manager to pass to the function.
456
450
  **kwargs: The keyword arguments to pass to the function.
457
451
 
458
452
  Returns:
@@ -472,10 +466,10 @@ def get_callback_manager_for_config(config: RunnableConfig) -> CallbackManager:
472
466
  """Get a callback manager for a config.
473
467
 
474
468
  Args:
475
- config (RunnableConfig): The config.
469
+ config: The config.
476
470
 
477
471
  Returns:
478
- CallbackManager: The callback manager.
472
+ The callback manager.
479
473
  """
480
474
  return CallbackManager.configure(
481
475
  inheritable_callbacks=config.get("callbacks"),
@@ -490,10 +484,10 @@ def get_async_callback_manager_for_config(
490
484
  """Get an async callback manager for a config.
491
485
 
492
486
  Args:
493
- config (RunnableConfig): The config.
487
+ config: The config.
494
488
 
495
489
  Returns:
496
- AsyncCallbackManager: The async callback manager.
490
+ The async callback manager.
497
491
  """
498
492
  return AsyncCallbackManager.configure(
499
493
  inheritable_callbacks=config.get("callbacks"),
@@ -518,12 +512,12 @@ class ContextThreadPoolExecutor(ThreadPoolExecutor):
518
512
  """Submit a function to the executor.
519
513
 
520
514
  Args:
521
- func (Callable[..., T]): The function to submit.
522
- *args (Any): The positional arguments to the function.
523
- **kwargs (Any): The keyword arguments to the function.
515
+ func: The function to submit.
516
+ *args: The positional arguments to the function.
517
+ **kwargs: The keyword arguments to the function.
524
518
 
525
519
  Returns:
526
- Future[T]: The future for the function.
520
+ The future for the function.
527
521
  """
528
522
  return super().submit(
529
523
  cast("Callable[..., T]", partial(copy_context().run, func, *args, **kwargs))
@@ -539,14 +533,13 @@ class ContextThreadPoolExecutor(ThreadPoolExecutor):
539
533
  """Map a function to multiple iterables.
540
534
 
541
535
  Args:
542
- fn (Callable[..., T]): The function to map.
543
- *iterables (Iterable[Any]): The iterables to map over.
544
- timeout (float | None, optional): The timeout for the map.
545
- Defaults to None.
546
- chunksize (int, optional): The chunksize for the map. Defaults to 1.
536
+ fn: The function to map.
537
+ *iterables: The iterables to map over.
538
+ timeout: The timeout for the map.
539
+ chunksize: The chunksize for the map.
547
540
 
548
541
  Returns:
549
- Iterator[T]: The iterator for the mapped function.
542
+ The iterator for the mapped function.
550
543
  """
551
544
  contexts = [copy_context() for _ in range(len(iterables[0]))] # type: ignore[arg-type]
552
545
 
@@ -568,10 +561,10 @@ def get_executor_for_config(
568
561
  """Get an executor for a config.
569
562
 
570
563
  Args:
571
- config (RunnableConfig): The config.
564
+ config: The config.
572
565
 
573
566
  Yields:
574
- Generator[Executor, None, None]: The executor.
567
+ The executor.
575
568
  """
576
569
  config = config or {}
577
570
  with ContextThreadPoolExecutor(
@@ -590,12 +583,12 @@ async def run_in_executor(
590
583
 
591
584
  Args:
592
585
  executor_or_config: The executor or config to run in.
593
- func (Callable[P, Output]): The function.
594
- *args (Any): The positional arguments to the function.
595
- **kwargs (Any): The keyword arguments to the function.
586
+ func: The function.
587
+ *args: The positional arguments to the function.
588
+ **kwargs: The keyword arguments to the function.
596
589
 
597
590
  Returns:
598
- Output: The output of the function.
591
+ The output of the function.
599
592
  """
600
593
 
601
594
  def wrapper() -> T:
@@ -49,8 +49,8 @@ if TYPE_CHECKING:
49
49
  class DynamicRunnable(RunnableSerializable[Input, Output]):
50
50
  """Serializable Runnable that can be dynamically configured.
51
51
 
52
- A DynamicRunnable should be initiated using the ``configurable_fields`` or
53
- ``configurable_alternatives`` method of a Runnable.
52
+ A DynamicRunnable should be initiated using the `configurable_fields` or
53
+ `configurable_alternatives` method of a Runnable.
54
54
  """
55
55
 
56
56
  default: RunnableSerializable[Input, Output]
@@ -72,10 +72,10 @@ 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
- ``["langchain", "schema", "runnable"]``
78
+ `["langchain", "schema", "runnable"]`
79
79
  """
80
80
  return ["langchain", "schema", "runnable"]
81
81
 
@@ -123,11 +123,10 @@ class DynamicRunnable(RunnableSerializable[Input, Output]):
123
123
  """Prepare the Runnable for invocation.
124
124
 
125
125
  Args:
126
- config: The configuration to use. Defaults to None.
126
+ config: The configuration to use.
127
127
 
128
128
  Returns:
129
- tuple[Runnable[Input, Output], RunnableConfig]: The prepared Runnable and
130
- configuration.
129
+ The prepared Runnable and configuration.
131
130
  """
132
131
  runnable: Runnable[Input, Output] = self
133
132
  while isinstance(runnable, DynamicRunnable):
@@ -384,7 +383,7 @@ class RunnableConfigurableFields(DynamicRunnable[Input, Output]):
384
383
  """Get the configuration specs for the RunnableConfigurableFields.
385
384
 
386
385
  Returns:
387
- list[ConfigurableFieldSpec]: The configuration specs.
386
+ The configuration specs.
388
387
  """
389
388
  config_specs = []
390
389
 
@@ -541,7 +540,7 @@ class RunnableConfigurableAlternatives(DynamicRunnable[Input, Output]):
541
540
  """The alternatives to choose from."""
542
541
 
543
542
  default_key: str = "default"
544
- """The enum value to use for the default option. Defaults to ``'default'``."""
543
+ """The enum value to use for the default option."""
545
544
 
546
545
  prefix_keys: bool
547
546
  """Whether to prefix configurable fields of each alternative with a namespace
@@ -656,7 +655,7 @@ def prefix_config_spec(
656
655
  prefix: The prefix to add.
657
656
 
658
657
  Returns:
659
- ConfigurableFieldSpec: The prefixed ConfigurableFieldSpec.
658
+ The prefixed ConfigurableFieldSpec.
660
659
  """
661
660
  return (
662
661
  ConfigurableFieldSpec(
@@ -47,8 +47,8 @@ class RunnableWithFallbacks(RunnableSerializable[Input, Output]):
47
47
  of a chain of Runnables. Fallbacks are tried in order until one succeeds or
48
48
  all fail.
49
49
 
50
- While you can instantiate a ``RunnableWithFallbacks`` directly, it is usually
51
- more convenient to use the ``with_fallbacks`` method on a Runnable.
50
+ While you can instantiate a `RunnableWithFallbacks` directly, it is usually
51
+ more convenient to use the `with_fallbacks` method on a Runnable.
52
52
 
53
53
  Example:
54
54
  ```python
@@ -97,7 +97,7 @@ class RunnableWithFallbacks(RunnableSerializable[Input, Output]):
97
97
  """
98
98
  exception_key: str | None = None
99
99
  """If string is specified then handled exceptions will be passed to fallbacks as
100
- part of the input under the specified key. If None, exceptions
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."""
103
103
 
@@ -143,10 +143,10 @@ 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
- ``["langchain", "schema", "runnable"]``
149
+ `["langchain", "schema", "runnable"]`
150
150
  """
151
151
  return ["langchain", "schema", "runnable"]
152
152
 
@@ -594,7 +594,7 @@ class RunnableWithFallbacks(RunnableSerializable[Input, Output]):
594
594
  Returns:
595
595
  If the attribute is anything other than a method that outputs a Runnable,
596
596
  returns getattr(self.runnable, name). If the attribute is a method that
597
- does return a new Runnable (e.g. llm.bind_tools([...]) outputs a new
597
+ does return a new Runnable (e.g. model.bind_tools([...]) outputs a new
598
598
  RunnableBinding) then self.runnable and each of the runnables in
599
599
  self.fallbacks is replaced with getattr(x, name).
600
600
 
@@ -605,15 +605,15 @@ class RunnableWithFallbacks(RunnableSerializable[Input, Output]):
605
605
 
606
606
  gpt_4o = ChatOpenAI(model="gpt-4o")
607
607
  claude_3_sonnet = ChatAnthropic(model="claude-3-7-sonnet-20250219")
608
- llm = gpt_4o.with_fallbacks([claude_3_sonnet])
608
+ model = gpt_4o.with_fallbacks([claude_3_sonnet])
609
609
 
610
- llm.model_name
610
+ model.model_name
611
611
  # -> "gpt-4o"
612
612
 
613
613
  # .bind_tools() is called on both ChatOpenAI and ChatAnthropic
614
614
  # Equivalent to:
615
615
  # gpt_4o.bind_tools([...]).with_fallbacks([claude_3_sonnet.bind_tools([...])])
616
- llm.bind_tools([...])
616
+ model.bind_tools([...])
617
617
  # -> RunnableWithFallbacks(
618
618
  runnable=RunnableBinding(bound=ChatOpenAI(...), kwargs={"tools": [...]}),
619
619
  fallbacks=[RunnableBinding(bound=ChatAnthropic(...), kwargs={"tools": [...]})],
@@ -52,7 +52,7 @@ def is_uuid(value: str) -> bool:
52
52
  value: The string to check.
53
53
 
54
54
  Returns:
55
- True if the string is a valid UUID, False otherwise.
55
+ `True` if the string is a valid UUID, `False` otherwise.
56
56
  """
57
57
  try:
58
58
  UUID(value)
@@ -69,16 +69,16 @@ class Edge(NamedTuple):
69
69
  target: str
70
70
  """The target node id."""
71
71
  data: Stringifiable | None = None
72
- """Optional data associated with the edge. Defaults to None."""
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.
78
78
 
79
79
  Args:
80
- source: The new source node id. Defaults to None.
81
- target: The new target node id. Defaults to None.
80
+ source: The new source node id.
81
+ target: The new target node id.
82
82
 
83
83
  Returns:
84
84
  A copy of the edge with the new source and target nodes.
@@ -101,7 +101,7 @@ class Node(NamedTuple):
101
101
  data: type[BaseModel] | RunnableType | None
102
102
  """The data of the node."""
103
103
  metadata: dict[str, Any] | None
104
- """Optional metadata for the node. Defaults to None."""
104
+ """Optional metadata for the node. """
105
105
 
106
106
  def copy(
107
107
  self,
@@ -112,8 +112,8 @@ class Node(NamedTuple):
112
112
  """Return a copy of the node with optional new id and name.
113
113
 
114
114
  Args:
115
- id: The new node id. Defaults to None.
116
- name: The new node name. Defaults to None.
115
+ id: The new node id.
116
+ name: The new node name.
117
117
 
118
118
  Returns:
119
119
  A copy of the node with the new id and name.
@@ -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. Defaults to None."""
135
+ """Optional dictionary of end node ids for the branches. """
136
136
 
137
137
 
138
138
  class CurveStyle(Enum):
@@ -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.
@@ -321,8 +321,8 @@ class Graph:
321
321
 
322
322
  Args:
323
323
  data: The data of the node.
324
- id: The id of the node. Defaults to None.
325
- metadata: Optional metadata for the node. Defaults to None.
324
+ id: The id of the node.
325
+ metadata: Optional metadata for the node.
326
326
 
327
327
  Returns:
328
328
  The node that was added to the graph.
@@ -361,8 +361,8 @@ class Graph:
361
361
  Args:
362
362
  source: The source node of the edge.
363
363
  target: The target node of the edge.
364
- data: Optional data associated with the edge. Defaults to None.
365
- conditional: Whether the edge is conditional. Defaults to False.
364
+ data: Optional data associated with the edge.
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:
@@ -548,10 +548,11 @@ class Graph:
548
548
  """Draw the graph as a PNG image.
549
549
 
550
550
  Args:
551
- output_file_path: The path to save the image to. If None, the image
552
- is not saved. Defaults to None.
553
- fontname: The name of the font to use. Defaults to None.
554
- labels: Optional labels for nodes and edges in the graph. Defaults to None.
551
+ output_file_path: The path to save the image to. If `None`, the image
552
+ is not saved.
553
+ fontname: The name of the font to use.
554
+ labels: Optional labels for nodes and edges in the graph. Defaults to
555
+ `None`.
555
556
 
556
557
  Returns:
557
558
  The PNG image as bytes if output_file_path is None, None otherwise.
@@ -584,14 +585,13 @@ class Graph:
584
585
  """Draw the graph as a Mermaid syntax string.
585
586
 
586
587
  Args:
587
- with_styles: Whether to include styles in the syntax. Defaults to True.
588
- curve_style: The style of the edges. Defaults to CurveStyle.LINEAR.
589
- 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.
590
591
  wrap_label_n_words: The number of words to wrap the node labels at.
591
- Defaults to 9.
592
- frontmatter_config (dict[str, Any], optional): Mermaid frontmatter config.
592
+ frontmatter_config: Mermaid frontmatter config.
593
593
  Can be used to customize theme and styles. Will be converted to YAML and
594
- added to the beginning of the mermaid graph. Defaults to None.
594
+ added to the beginning of the mermaid graph.
595
595
 
596
596
  See more here: https://mermaid.js.org/config/configuration.html.
597
597
 
@@ -646,23 +646,19 @@ class Graph:
646
646
  """Draw the graph as a PNG image using Mermaid.
647
647
 
648
648
  Args:
649
- curve_style: The style of the edges. Defaults to CurveStyle.LINEAR.
650
- 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.
651
651
  wrap_label_n_words: The number of words to wrap the node labels at.
652
- Defaults to 9.
653
- output_file_path: The path to save the image to. If None, the image
654
- is not saved. Defaults to None.
652
+ output_file_path: The path to save the image to. If `None`, the image
653
+ is not saved.
655
654
  draw_method: The method to use to draw the graph.
656
- Defaults to MermaidDrawMethod.API.
657
- background_color: The color of the background. Defaults to "white".
658
- padding: The padding around the graph. Defaults to 10.
659
- max_retries: The maximum number of retries (MermaidDrawMethod.API).
660
- Defaults to 1.
661
- retry_delay: The delay between retries (MermaidDrawMethod.API).
662
- Defaults to 1.0.
663
- frontmatter_config (dict[str, Any], optional): Mermaid frontmatter config.
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`).
659
+ frontmatter_config: Mermaid frontmatter config.
664
660
  Can be used to customize theme and styles. Will be converted to YAML and
665
- added to the beginning of the mermaid graph. Defaults to None.
661
+ added to the beginning of the mermaid graph.
666
662
 
667
663
  See more here: https://mermaid.js.org/config/configuration.html.
668
664
 
@@ -678,7 +674,7 @@ class Graph:
678
674
  }
679
675
  ```
680
676
  base_url: The base URL of the Mermaid server for rendering via API.
681
- Defaults to None.
677
+
682
678
 
683
679
  Returns:
684
680
  The PNG image as bytes.
@@ -711,7 +707,7 @@ def _first_node(graph: Graph, exclude: Sequence[str] = ()) -> Node | None:
711
707
  """Find the single node that is not a target of any edge.
712
708
 
713
709
  Exclude nodes/sources with ids in the exclude list.
714
- 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`.
715
711
  When drawing the graph, this node would be the origin.
716
712
  """
717
713
  targets = {edge.target for edge in graph.edges if edge.source not in exclude}
@@ -727,7 +723,7 @@ def _last_node(graph: Graph, exclude: Sequence[str] = ()) -> Node | None:
727
723
  """Find the single node that is not a source of any edge.
728
724
 
729
725
  Exclude nodes/targets with ids in the exclude list.
730
- 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`.
731
727
  When drawing the graph, this node would be the destination.
732
728
  """
733
729
  sources = {edge.source for edge in graph.edges if edge.target not in exclude}