mirror of
https://github.com/langchain-ai/langgraph.git
synced 2026-09-06 09:47:51 +02:00
Disable retries by default
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user