Skip to content

feat(adk): add retries for agent tools - #1162

Open
March-77 wants to merge 1 commit into
cloudwego:mainfrom
March-77:agent/issue-889-agent-tool-retry
Open

feat(adk): add retries for agent tools#1162
March-77 wants to merge 1 commit into
cloudwego:mainfrom
March-77:agent/issue-889-agent-tool-retry

Conversation

@March-77

Copy link
Copy Markdown

What type of PR is this?

feat

Check the PR title.

  • This PR title matches the format: <type>(optional scope): <description>.
  • The description is user-oriented and clear enough for others to understand.
  • The additive API is documented inline, including retry safety constraints.

(Optional) Translate the PR title into Chinese.

feat(adk): 为 AgentTool 添加失败重试

(Optional) More detailed description for this PR(en: English/zh: Chinese).

en:

Deep-agent applications can execute many subagents through AgentTool. A transient failure from one child currently fails the complete parent tool-call batch even when rerunning that child would be safe.

This PR adds opt-in whole-invocation retry support through WithAgentToolRetry and AgentToolRetryConfig:

  • configurable maximum retries, retry predicate, and context-aware backoff;
  • fresh child-agent run and bridge store for every retry;
  • preservation of the final original error and its errors.Is/errors.As chain;
  • cancellation, deadlines, ADK cancellation errors, and interrupt signals are never retried;
  • interrupt/resume invocations always execute once so checkpoint state is preserved;
  • configuration is cloned when the AgentTool is constructed;
  • both regular and typed AgentTool implementations use the same generic retry path.

Retries are disabled by default. Documentation explicitly warns that the wrapped agent must be safe to repeat and that already-forwarded internal events from a failed attempt remain observable.

User impact: callers can recover from transient subagent failures without failing an entire parallel DeepAgent turn, while retaining explicit control over retryability and backoff.

Compatibility/risk: additive option only; existing AgentTool behavior is unchanged. The main operational risk is retrying a non-idempotent agent, which is why the feature is opt-in and documented accordingly.

Validation:

  • go test ./adk -run TestAgentToolRetry -count=10 (pass)
  • go test -race ./adk -run TestAgentToolRetry -count=1 (pass)
  • go test ./adk -count=1 (pass)
  • go test ./... -count=1 (pass)
  • go vet ./... (pass)
  • gofmt -s and git diff --check (pass)

Tests cover retry success, predicate rejection, exhaustion, context cancellation during backoff, interrupt suppression, and invalid configuration.

zh(optional):

为 AgentTool 增加显式启用的整次调用重试,支持重试判断和退避,并确保取消、超时、interrupt 与 resume 路径不会被重复执行。

(Optional) Which issue(s) this PR fixes:

Fixes #889

(optional) The PR that updates user documentation:

N/A

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] 需要AgentAsTool能进行失败重试

1 participant