Disable retries by default

This commit is contained in:
Nuno Campos
2024-05-16 15:59:45 -07:00
parent 2414e0ab5e
commit a4e88e930f
4 changed files with 12 additions and 4 deletions
+1 -1
View File
@@ -214,7 +214,7 @@ class Pregel(
checkpointer: Optional[BaseCheckpointSaver] = None
"""Checkpointer used to save and load graph state. Defaults to None."""
retry_policy: Optional[RetryPolicy] = RetryPolicy()
retry_policy: Optional[RetryPolicy] = None
"""Retry policy to use when running tasks. Set to None to disable."""
config_type: Optional[Type[Any]] = None
+7 -3
View File
@@ -2,7 +2,7 @@ import asyncio
import logging
import random
import time
from typing import Callable, NamedTuple, Union
from typing import Callable, NamedTuple, Optional, Union
import httpx
import requests
@@ -53,7 +53,7 @@ class RetryPolicy(NamedTuple):
def run_with_retry(
task: PregelExecutableTask,
retry_policy: RetryPolicy,
retry_policy: Optional[RetryPolicy],
) -> None:
"""Run a task with retries."""
interval = retry_policy.initial_interval
@@ -67,6 +67,8 @@ def run_with_retry(
# if successful, end
break
except Exception as exc:
if retry_policy is None:
raise
# increment attempts
attempts += 1
# check if we should retry
@@ -94,7 +96,7 @@ def run_with_retry(
async def arun_with_retry(
task: PregelExecutableTask,
retry_policy: RetryPolicy,
retry_policy: Optional[RetryPolicy],
stream: bool = False,
) -> None:
"""Run a task asynchronously with retries."""
@@ -113,6 +115,8 @@ async def arun_with_retry(
# if successful, end
break
except Exception as exc:
if retry_policy is None:
raise
# increment attempts
attempts += 1
# check if we should retry
+2
View File
@@ -38,6 +38,7 @@ from langgraph.prebuilt.chat_agent_executor import (
)
from langgraph.prebuilt.tool_node import ToolNode
from langgraph.pregel import Channel, GraphRecursionError, Pregel, StateSnapshot
from langgraph.pregel.retry import RetryPolicy
from tests.any_str import AnyStr
from tests.memory_assert import MemorySaverAssertImmutable
@@ -762,6 +763,7 @@ def test_invoke_checkpoint(mocker: MockerFixture) -> None:
input_channels="input",
output_channels="output",
checkpointer=memory,
retry_policy=RetryPolicy(),
)
# total starts out as 0, so output is 0+2=2
+2
View File
@@ -38,6 +38,7 @@ from langgraph.prebuilt.chat_agent_executor import (
from langgraph.prebuilt.tool_executor import ToolExecutor
from langgraph.prebuilt.tool_node import ToolNode
from langgraph.pregel import Channel, GraphRecursionError, Pregel, StateSnapshot
from langgraph.pregel.retry import RetryPolicy
from tests.any_str import AnyStr
from tests.memory_assert import MemorySaverAssertImmutable
@@ -743,6 +744,7 @@ async def test_invoke_checkpoint(mocker: MockerFixture) -> None:
input_channels="input",
output_channels="output",
checkpointer=memory,
retry_policy=RetryPolicy(),
)
# total starts out as 0, so output is 0+2=2