langchain-core 1.0.0a7__py3-none-any.whl → 1.0.0rc1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of langchain-core might be problematic. Click here for more details.

Files changed (135) 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 +7 -6
  7. langchain_core/caches.py +4 -10
  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 +76 -55
  16. langchain_core/document_loaders/langsmith.py +21 -21
  17. langchain_core/documents/__init__.py +0 -1
  18. langchain_core/documents/base.py +37 -40
  19. langchain_core/documents/transformers.py +28 -29
  20. langchain_core/embeddings/fake.py +46 -52
  21. langchain_core/exceptions.py +5 -5
  22. langchain_core/indexing/api.py +11 -11
  23. langchain_core/indexing/base.py +24 -24
  24. langchain_core/language_models/__init__.py +0 -2
  25. langchain_core/language_models/_utils.py +51 -53
  26. langchain_core/language_models/base.py +23 -24
  27. langchain_core/language_models/chat_models.py +121 -144
  28. langchain_core/language_models/fake_chat_models.py +5 -5
  29. langchain_core/language_models/llms.py +10 -12
  30. langchain_core/load/dump.py +1 -1
  31. langchain_core/load/load.py +16 -16
  32. langchain_core/load/serializable.py +35 -34
  33. langchain_core/messages/__init__.py +1 -16
  34. langchain_core/messages/ai.py +105 -104
  35. langchain_core/messages/base.py +26 -26
  36. langchain_core/messages/block_translators/__init__.py +17 -17
  37. langchain_core/messages/block_translators/anthropic.py +2 -2
  38. langchain_core/messages/block_translators/bedrock_converse.py +2 -2
  39. langchain_core/messages/block_translators/google_genai.py +2 -2
  40. langchain_core/messages/block_translators/groq.py +117 -21
  41. langchain_core/messages/block_translators/langchain_v0.py +2 -2
  42. langchain_core/messages/block_translators/openai.py +4 -4
  43. langchain_core/messages/chat.py +1 -1
  44. langchain_core/messages/content.py +189 -193
  45. langchain_core/messages/function.py +5 -5
  46. langchain_core/messages/human.py +15 -17
  47. langchain_core/messages/modifier.py +1 -1
  48. langchain_core/messages/system.py +12 -14
  49. langchain_core/messages/tool.py +45 -49
  50. langchain_core/messages/utils.py +384 -396
  51. langchain_core/output_parsers/__init__.py +1 -14
  52. langchain_core/output_parsers/base.py +22 -23
  53. langchain_core/output_parsers/json.py +3 -3
  54. langchain_core/output_parsers/list.py +1 -1
  55. langchain_core/output_parsers/openai_functions.py +46 -44
  56. langchain_core/output_parsers/openai_tools.py +7 -7
  57. langchain_core/output_parsers/pydantic.py +10 -11
  58. langchain_core/output_parsers/string.py +1 -1
  59. langchain_core/output_parsers/transform.py +2 -2
  60. langchain_core/output_parsers/xml.py +1 -1
  61. langchain_core/outputs/__init__.py +1 -1
  62. langchain_core/outputs/chat_generation.py +14 -14
  63. langchain_core/outputs/generation.py +5 -5
  64. langchain_core/outputs/llm_result.py +5 -5
  65. langchain_core/prompt_values.py +5 -5
  66. langchain_core/prompts/__init__.py +3 -23
  67. langchain_core/prompts/base.py +32 -37
  68. langchain_core/prompts/chat.py +216 -222
  69. langchain_core/prompts/dict.py +2 -2
  70. langchain_core/prompts/few_shot.py +76 -83
  71. langchain_core/prompts/few_shot_with_templates.py +6 -8
  72. langchain_core/prompts/image.py +11 -13
  73. langchain_core/prompts/loading.py +1 -1
  74. langchain_core/prompts/message.py +2 -2
  75. langchain_core/prompts/prompt.py +14 -16
  76. langchain_core/prompts/string.py +19 -7
  77. langchain_core/prompts/structured.py +24 -25
  78. langchain_core/rate_limiters.py +36 -38
  79. langchain_core/retrievers.py +41 -182
  80. langchain_core/runnables/base.py +565 -590
  81. langchain_core/runnables/branch.py +7 -7
  82. langchain_core/runnables/config.py +37 -44
  83. langchain_core/runnables/configurable.py +8 -9
  84. langchain_core/runnables/fallbacks.py +8 -8
  85. langchain_core/runnables/graph.py +28 -27
  86. langchain_core/runnables/graph_ascii.py +19 -18
  87. langchain_core/runnables/graph_mermaid.py +20 -31
  88. langchain_core/runnables/graph_png.py +7 -7
  89. langchain_core/runnables/history.py +20 -20
  90. langchain_core/runnables/passthrough.py +8 -8
  91. langchain_core/runnables/retry.py +3 -3
  92. langchain_core/runnables/router.py +1 -1
  93. langchain_core/runnables/schema.py +33 -33
  94. langchain_core/runnables/utils.py +30 -34
  95. langchain_core/stores.py +72 -102
  96. langchain_core/sys_info.py +27 -29
  97. langchain_core/tools/__init__.py +1 -14
  98. langchain_core/tools/base.py +63 -63
  99. langchain_core/tools/convert.py +92 -92
  100. langchain_core/tools/render.py +9 -9
  101. langchain_core/tools/retriever.py +1 -1
  102. langchain_core/tools/simple.py +6 -7
  103. langchain_core/tools/structured.py +17 -18
  104. langchain_core/tracers/__init__.py +1 -9
  105. langchain_core/tracers/base.py +35 -35
  106. langchain_core/tracers/context.py +12 -17
  107. langchain_core/tracers/event_stream.py +3 -3
  108. langchain_core/tracers/langchain.py +8 -8
  109. langchain_core/tracers/log_stream.py +17 -18
  110. langchain_core/tracers/memory_stream.py +2 -2
  111. langchain_core/tracers/schemas.py +0 -129
  112. langchain_core/utils/aiter.py +31 -31
  113. langchain_core/utils/env.py +5 -5
  114. langchain_core/utils/function_calling.py +48 -120
  115. langchain_core/utils/html.py +4 -4
  116. langchain_core/utils/input.py +2 -2
  117. langchain_core/utils/interactive_env.py +1 -1
  118. langchain_core/utils/iter.py +19 -19
  119. langchain_core/utils/json.py +1 -1
  120. langchain_core/utils/json_schema.py +2 -2
  121. langchain_core/utils/mustache.py +5 -5
  122. langchain_core/utils/pydantic.py +17 -17
  123. langchain_core/utils/strings.py +4 -4
  124. langchain_core/utils/utils.py +25 -28
  125. langchain_core/vectorstores/base.py +43 -64
  126. langchain_core/vectorstores/in_memory.py +83 -85
  127. langchain_core/version.py +1 -1
  128. {langchain_core-1.0.0a7.dist-info → langchain_core-1.0.0rc1.dist-info}/METADATA +23 -11
  129. langchain_core-1.0.0rc1.dist-info/RECORD +172 -0
  130. langchain_core/memory.py +0 -120
  131. langchain_core/pydantic_v1/__init__.py +0 -30
  132. langchain_core/pydantic_v1/dataclasses.py +0 -23
  133. langchain_core/pydantic_v1/main.py +0 -23
  134. langchain_core-1.0.0a7.dist-info/RECORD +0 -176
  135. {langchain_core-1.0.0a7.dist-info → langchain_core-1.0.0rc1.dist-info}/WHEEL +0 -0
@@ -149,7 +149,7 @@ class RunnableBranch(RunnableSerializable[Input, Output]):
149
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. Defaults to 1.
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]
@@ -75,7 +75,7 @@ class DynamicRunnable(RunnableSerializable[Input, Output]):
75
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. Defaults to `'default'`."""
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
 
@@ -146,7 +146,7 @@ class RunnableWithFallbacks(RunnableSerializable[Input, Output]):
146
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. Defaults to `False`."""
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):
@@ -203,7 +203,7 @@ def node_data_json(
203
203
  Args:
204
204
  node: The node to convert.
205
205
  with_schemas: Whether to include the schema of the data if
206
- it is a Pydantic model. Defaults to False.
206
+ it is a Pydantic model. Defaults to `False`.
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. Defaults to `False`.
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. Defaults to `False`.
366
366
 
367
367
  Returns:
368
368
  The edge that was added to the graph.
@@ -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,14 @@ 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
+ with_styles: Whether to include styles in the syntax. Defaults to `True`.
588
589
  curve_style: The style of the edges. Defaults to CurveStyle.LINEAR.
589
590
  node_colors: The colors of the nodes. Defaults to NodeStyles().
590
591
  wrap_label_n_words: The number of words to wrap the node labels at.
591
592
  Defaults to 9.
592
- frontmatter_config (dict[str, Any], optional): Mermaid frontmatter config.
593
+ frontmatter_config: Mermaid frontmatter config.
593
594
  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.
595
+ added to the beginning of the mermaid graph.
595
596
 
596
597
  See more here: https://mermaid.js.org/config/configuration.html.
597
598
 
@@ -650,8 +651,8 @@ class Graph:
650
651
  node_colors: The colors of the nodes. Defaults to NodeStyles().
651
652
  wrap_label_n_words: The number of words to wrap the node labels at.
652
653
  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.
654
+ output_file_path: The path to save the image to. If `None`, the image
655
+ is not saved.
655
656
  draw_method: The method to use to draw the graph.
656
657
  Defaults to MermaidDrawMethod.API.
657
658
  background_color: The color of the background. Defaults to "white".
@@ -660,9 +661,9 @@ class Graph:
660
661
  Defaults to 1.
661
662
  retry_delay: The delay between retries (MermaidDrawMethod.API).
662
663
  Defaults to 1.0.
663
- frontmatter_config (dict[str, Any], optional): Mermaid frontmatter config.
664
+ frontmatter_config: Mermaid frontmatter config.
664
665
  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.
666
+ added to the beginning of the mermaid graph.
666
667
 
667
668
  See more here: https://mermaid.js.org/config/configuration.html.
668
669
 
@@ -678,7 +679,7 @@ class Graph:
678
679
  }
679
680
  ```
680
681
  base_url: The base URL of the Mermaid server for rendering via API.
681
- Defaults to None.
682
+
682
683
 
683
684
  Returns:
684
685
  The PNG image as bytes.
@@ -62,8 +62,8 @@ class AsciiCanvas:
62
62
  """Create an ASCII canvas.
63
63
 
64
64
  Args:
65
- cols: number of columns in the canvas. Should be ``> 1``.
66
- lines: number of lines in the canvas. Should be ``> 1``.
65
+ cols: number of columns in the canvas. Should be `> 1`.
66
+ lines: number of lines in the canvas. Should be `> 1`.
67
67
 
68
68
  Raises:
69
69
  ValueError: if canvas dimensions are invalid.
@@ -90,9 +90,9 @@ class AsciiCanvas:
90
90
  """Create a point on ASCII canvas.
91
91
 
92
92
  Args:
93
- x: x coordinate. Should be ``>= 0`` and ``<`` number of columns in
93
+ x: x coordinate. Should be `>= 0` and `<` number of columns in
94
94
  the canvas.
95
- y: y coordinate. Should be ``>= 0`` an ``<`` number of lines in the
95
+ y: y coordinate. Should be `>= 0` an `<` number of lines in the
96
96
  canvas.
97
97
  char: character to place in the specified point on the
98
98
  canvas.
@@ -117,11 +117,11 @@ class AsciiCanvas:
117
117
  """Create a line on ASCII canvas.
118
118
 
119
119
  Args:
120
- x0 (int): x coordinate where the line should start.
121
- y0 (int): y coordinate where the line should start.
122
- x1 (int): x coordinate where the line should end.
123
- y1 (int): y coordinate where the line should end.
124
- char (str): character to draw the line with.
120
+ x0: x coordinate where the line should start.
121
+ y0: y coordinate where the line should start.
122
+ x1: x coordinate where the line should end.
123
+ y1: y coordinate where the line should end.
124
+ char: character to draw the line with.
125
125
  """
126
126
  if x0 > x1:
127
127
  x1, x0 = x0, x1
@@ -149,9 +149,9 @@ class AsciiCanvas:
149
149
  """Print a text on ASCII canvas.
150
150
 
151
151
  Args:
152
- x (int): x coordinate where the text should start.
153
- y (int): y coordinate where the text should start.
154
- text (str): string that should be printed.
152
+ x: x coordinate where the text should start.
153
+ y: y coordinate where the text should start.
154
+ text: string that should be printed.
155
155
  """
156
156
  for i, char in enumerate(text):
157
157
  self.point(x + i, y, char)
@@ -160,10 +160,10 @@ class AsciiCanvas:
160
160
  """Create a box on ASCII canvas.
161
161
 
162
162
  Args:
163
- x0 (int): x coordinate of the box corner.
164
- y0 (int): y coordinate of the box corner.
165
- width (int): box width.
166
- height (int): box height.
163
+ x0: x coordinate of the box corner.
164
+ y0: y coordinate of the box corner.
165
+ width: box width.
166
+ height: box height.
167
167
  """
168
168
  if width <= 1 or height <= 1:
169
169
  msg = "Box dimensions should be > 1"
@@ -267,7 +267,8 @@ def draw_ascii(vertices: Mapping[str, str], edges: Sequence[LangEdge]) -> str:
267
267
 
268
268
  print(draw_ascii(vertices, edges))
269
269
  ```
270
- .. code-block::
270
+
271
+ ```txt
271
272
 
272
273
  +---+
273
274
  | 1 |
@@ -284,7 +285,7 @@ def draw_ascii(vertices: Mapping[str, str], edges: Sequence[LangEdge]) -> str:
284
285
  +---+ +---+
285
286
  | 3 | | 4 |
286
287
  +---+ +---+
287
-
288
+ ```
288
289
  """
289
290
  # NOTE: coordinates might me negative, so we need to shift
290
291
  # everything to the positive plane before we actually draw it.