The agent engineering platform.
Python agentsaiai-agentsanthropicchatgptdeepagentsenterpriseframeworkgeminigenerative-ailangchainlanggraphllmmultiagentopen-sourceopenaipydanticpythonragtypescript
code[patch]: Add in code documentation to core Runnable with_retry method (docs only) (#19192)
Guangdong Liu2c835baae4c6
diff --git a/libs/core/langchain_core/runnables/base.py b/libs/core/langchain_core/runnables/base.pyindex 88d71407ca..8b265d7f33 100644--- a/libs/core/langchain_core/runnables/base.py+++ b/libs/core/langchain_core/runnables/base.py@@ -1344,6 +1344,35 @@ class Runnable(Generic[Input, Output], ABC):) -> Runnable[Input, Output]:"""Create a new Runnable that retries the original runnable on exceptions.+ Example:++ .. code-block:: python+ from langchain_core.runnables import RunnableLambda++ count = 0+++ def _lambda(x: int) -> None:+ global count+ count = count + 1+ if x == 1:+ raise ValueError("x is 1")+ else:+ pass+++ runnable = RunnableLambda(_lambda)+ try:+ runnable.with_retry(+ stop_after_attempt=2,+ retry_if_exception_type=(ValueError,),+ ).invoke(1)+ except ValueError:+ pass++ assert (count == 2)++Args:retry_if_exception_type: A tuple of exception types to retry onwait_exponential_jitter: Whether to add jitter to the wait time