fix(flow): treat agent exceptions as failed steps so retry/fallback engage - #98
Open
XuQuanxin04 wants to merge 1 commit into
Open
fix(flow): treat agent exceptions as failed steps so retry/fallback engage#98XuQuanxin04 wants to merge 1 commit into
XuQuanxin04 wants to merge 1 commit into
Conversation
…ngage _run_step called _call_agent without catching exceptions. Real agents typically raise on API/network/rate-limit failures rather than returning a RunResult with an error set, and _call_agent re-raises those (either directly or via future.result()). The exception therefore escaped the retry loop on the first attempt: max_retry never retried a raising agent, fallback_agent was never consulted, and flow.run() crashed instead of marking the step failed and skipping dependents. Wrap both the primary and fallback agent calls so a raised exception is normalized into a failed step result (using the existing [LA-FLOW-...] error convention), allowing the retry loop and fallback path to engage, and letting the flow fail gracefully with downstream steps skipped. Co-Authored-By: Claude <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
_run_stepcalled_call_agentwithout catching exceptions. Real agents typically raise on API/network/rate-limit failures (rather than returning aRunResultwitherrorset), and_call_agentre-raises those — directly when no timeout is set, or viafuture.result()when one is. The exception therefore escaped the retry loop on the first attempt:max_retrynever retried a raising agent (the workflow crashed on attempt 1 instead of trying again),fallback_agentwas never consulted for a raising agent,flow.run()raised instead of marking the stepfailedand skipping its dependents.[LA-FLOW-...]error convention. The retry loop and fallback path then engage exactly as they do for errors returned in aRunResult, and the flow fails gracefully with downstream steps skipped.Reproduction (before this patch)
Compatibility
agent.run("hello")behavior is unchanged for agents that return normally.stream=Truebehavior is unchanged.RunResult(error=...)failures are already handled.KeyboardInterrupt/SystemExit(not subclasses ofException) still propagate.Tests
python -m compileall -q LightAgentPYTHONPATH=. python -m pytest -q tests/test_lightflow.py— 17 passedtest_lightflow_retries_when_agent_raises— a transiently-raising agent is retried and succeeds.test_lightflow_fallback_runs_when_agent_always_raises— a persistently-raising agent falls back.test_lightflow_marks_step_failed_when_agent_always_raises_without_fallback— the step isfailed, the dependent step isskipped, andrun()returns a failed result instead of raising.Notes
No API changes. The pre-existing retry/fallback tests only covered errors delivered via
RunResult(error=...); this covers the raised-exception path, which is the common failure mode for real LLM integrations.