pub struct RetryPolicy { /* private fields */ }Expand description
重试策略配置。
max_attempts 表示总尝试次数(初始执行 + 重试),与主流 SDK 语义一致:
max_attempts = 1→ 不重试,只执行一次max_attempts = 3→ 初始执行 + 最多 2 次重试
Implementations§
Source§impl RetryPolicy
impl RetryPolicy
pub fn new(max_attempts: u32, backoff: BackoffStrategy) -> Self
Sourcepub fn max_attempts(&self) -> u32
pub fn max_attempts(&self) -> u32
获取总尝试次数。
Sourcepub fn backoff(&self) -> &BackoffStrategy
pub fn backoff(&self) -> &BackoffStrategy
获取退避策略引用。
Sourcepub async fn execute_with_retry(
&self,
tool_fn: &ToolFn,
args: &Value,
) -> ToolResult
pub async fn execute_with_retry( &self, tool_fn: &ToolFn, args: &Value, ) -> ToolResult
执行工具函数并自动重试可重试的错误。
max_attempts = 总尝试次数(初始执行 + 重试),与 AWS SDK / reqwest 等语义一致。
执行链:ToolUseLoop → ToolExecutor → RetryPolicy → tool_fn()
Sourcepub async fn execute_with_retry_and_emission(
&self,
tool_fn: &ToolFn,
args: &Value,
tx: &Sender<AgentEvent>,
tool_call_id: &str,
) -> ToolResult
pub async fn execute_with_retry_and_emission( &self, tool_fn: &ToolFn, args: &Value, tx: &Sender<AgentEvent>, tool_call_id: &str, ) -> ToolResult
执行工具函数并自动重试可重试的错误,同时发射 Retry 事件。
与 [execute_with_retry] 的区别:每次重试前通过 tx 发射 AgentEvent::Retry。
Trait Implementations§
Source§impl Clone for RetryPolicy
impl Clone for RetryPolicy
Source§fn clone(&self) -> RetryPolicy
fn clone(&self) -> RetryPolicy
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for RetryPolicy
impl Debug for RetryPolicy
Auto Trait Implementations§
impl Freeze for RetryPolicy
impl RefUnwindSafe for RetryPolicy
impl Send for RetryPolicy
impl Sync for RetryPolicy
impl Unpin for RetryPolicy
impl UnsafeUnpin for RetryPolicy
impl UnwindSafe for RetryPolicy
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more