




















llama-agents 通过retry 可以进行异常的处理,同时还提供了一个全局的catch_error 装饰器
from workflows import Workflow, Context, step
from workflows.events import StartEvent, StopEvent
from workflows.retry_policy import (
retry_policy,
stop_after_attempt,
wait_fixed,
)
class MyWorkflow(Workflow):
@step(
retry_policy=retry_policy(
wait=wait_fixed(5),
stop=stop_after_attempt(10),
)
)
async def flaky_step(self, ctx: Context, ev: StartEvent) -> StopEvent:
result = flaky_call() # this might raise
return StopEvent(result=result)
通过catch_error
class Pipeline(Workflow):
@step(retry_policy=...)
async def fetch(self, ev: StartEvent) -> FetchedEvent: ...
@step(retry_policy=...)
async def parse(self, ev: FetchedEvent) -> StopEvent: ...
@catch_error(for_steps=["fetch"])
async def on_fetch_failure(
self, ctx: Context, ev: StepFailedEvent
) -> StopEvent:
return StopEvent(result={"fallback": True})
@catch_error # wildcard — covers `parse` and anything else
async def on_any_failure(
self, ctx: Context, ev: StepFailedEvent
) -> StopEvent:
return StopEvent(result={"aborted": ev.step_name})
https://developers.llamaindex.ai/python/llamaagents/workflows/retry_steps/
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。