mirror of
https://github.com/langchain-ai/langgraph.git
synced 2026-09-23 10:05:08 +02:00
Add retry_policy for graphs
- default is to retry, fully configurable - configuration options follow temporal https://docs.temporal.io/retry-policies#properties
This commit is contained in:
@@ -729,8 +729,16 @@ def test_invoke_two_processes_two_in_two_out_valid(mocker: MockerFixture) -> Non
|
||||
|
||||
def test_invoke_checkpoint(mocker: MockerFixture) -> None:
|
||||
add_one = mocker.Mock(side_effect=lambda x: x["total"] + x["input"])
|
||||
errored_once = False
|
||||
|
||||
def raise_if_above_10(input: int) -> int:
|
||||
nonlocal errored_once
|
||||
if input > 4:
|
||||
if errored_once:
|
||||
pass
|
||||
else:
|
||||
errored_once = True
|
||||
raise OSError("I will be retried")
|
||||
if input > 10:
|
||||
raise ValueError("Input is too large")
|
||||
return input
|
||||
@@ -763,6 +771,7 @@ def test_invoke_checkpoint(mocker: MockerFixture) -> None:
|
||||
assert checkpoint["channel_values"].get("total") == 2
|
||||
# total is now 2, so output is 2+3=5
|
||||
assert app.invoke(3, {"configurable": {"thread_id": "1"}}) == 5
|
||||
assert errored_once, "errored and retried"
|
||||
checkpoint = memory.get({"configurable": {"thread_id": "1"}})
|
||||
assert checkpoint is not None
|
||||
assert checkpoint["channel_values"].get("total") == 7
|
||||
|
||||
@@ -710,8 +710,16 @@ async def test_invoke_two_processes_two_in_two_out_valid(mocker: MockerFixture)
|
||||
|
||||
async def test_invoke_checkpoint(mocker: MockerFixture) -> None:
|
||||
add_one = mocker.Mock(side_effect=lambda x: x["total"] + x["input"])
|
||||
errored_once = False
|
||||
|
||||
def raise_if_above_10(input: int) -> int:
|
||||
nonlocal errored_once
|
||||
if input > 4:
|
||||
if errored_once:
|
||||
pass
|
||||
else:
|
||||
errored_once = True
|
||||
raise OSError("I will be retried")
|
||||
if input > 10:
|
||||
raise ValueError("Input is too large")
|
||||
return input
|
||||
@@ -744,6 +752,7 @@ async def test_invoke_checkpoint(mocker: MockerFixture) -> None:
|
||||
assert checkpoint["channel_values"].get("total") == 2
|
||||
# total is now 2, so output is 2+3=5
|
||||
assert await app.ainvoke(3, {"configurable": {"thread_id": "1"}}) == 5
|
||||
assert errored_once, "errored and retried"
|
||||
checkpoint = await memory.aget({"configurable": {"thread_id": "1"}})
|
||||
assert checkpoint is not None
|
||||
assert checkpoint["channel_values"].get("total") == 7
|
||||
|
||||
Reference in New Issue
Block a user