generated from cloudwego/.github
-
Notifications
You must be signed in to change notification settings - Fork 694
feat(adk): implement ChatModel retry for ChatModelAgent #635
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
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
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #635 +/- ##
==========================================
+ Coverage 79.44% 79.94% +0.50%
==========================================
Files 123 124 +1
Lines 11602 11812 +210
==========================================
+ Hits 9217 9443 +226
+ Misses 1658 1635 -23
- Partials 727 734 +7 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
2f1191a to
aa1c7d0
Compare
hi-pender
reviewed
Dec 24, 2025
hi-pender
reviewed
Dec 24, 2025
hi-pender
reviewed
Dec 24, 2025
Change-Id: Iac018949691d91456fdcf67cececf0c0ca55bdcb
…ut tools Change-Id: I027fd9ad577caa4006c170aa70ad9e4e1fac7879
Change-Id: Ibbe7cd78e49c7e0f833dc4dc7b4e121df92bb9db
…onential backoff - Add RetryAbleError and NonRetryAbleError types for distinguishing error types in streams - Implement exponential backoff with jitter (base 100ms, max 10s, 0-50% jitter) - Change StreamErr field from string to error type for proper error propagation - Add error wrapper support in StreamReaderWithConvert for stream error classification - Update genAgentInput to skip RetryAbleError events but propagate other errors - Pass ModelRetryConfig to callback handlers for stream error wrapping - Add TotalRetries field to RetryExhaustedError - Update IsRetryAble and BackoffFunc signatures to include context Test coverage: - Add sequential workflow tests for retry scenarios - Add gob encoding tests for RetryAbleError and NonRetryAbleError - Add test for unregistered error type gob encoding failure - Update existing tests for StreamErr type change Change-Id: I9d822665e23fc12cfa1997de02ab3bf85849c0e4
- Rename RetryAbleError to WillRetryError (indicates retry will happen) - Rename NonRetryAbleError to WontRetryError (indicates no retry) - Fix genErrWrapper to check max retries before emitting WillRetryError - Consolidate duplicate stream error tests into table-driven test - Remove redundant TestChatModelAgentRetry_WithTools_StreamError_SequentialFlow - Add coverage tests for error string methods and default IsRetryAble The naming change better reflects the user's perspective: when receiving WillRetryError in a stream, the retry is about to happen (not already done). WontRetryError indicates the error is final - either non-retryable or max retries exhausted. Change-Id: Ia613c83b1da69c600130a69f2039ff9425552ecd
47d74c5 to
b6dfb48
Compare
hi-pender
reviewed
Dec 25, 2025
hi-pender
reviewed
Dec 25, 2025
hi-pender
reviewed
Dec 25, 2025
- Remove WontRetryError type - no need to wrap non-retryable errors - Update genErrWrapper to return original error when not retrying - Simpler API: only WillRetryError needs special handling - Users can directly use errors.Is(err, specificError) for non-retry cases This makes the error handling more intuitive: - WillRetryError: retry is pending, expect another stream - Original error: this is final, no more retries Change-Id: I13a8db602823a9ed3ab2164b63b585db7e55399b
hi-pender
approved these changes
Dec 25, 2025
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.
PR #635: feat(adk): implement ChatModel retry for ChatModelAgent
Summary
This PR adds automatic retry functionality for ChatModel calls in
ChatModelAgent, enabling graceful handling of transient LLM API failures (network timeouts, rate limits, temporary unavailability).Quick Start
Core Design: Two Types of Errors
LLM calls can fail in two ways, and this feature handles both:
Generate()orStream()returns error immediatelyWhy Stream Errors Are Different
For direct errors, retry is invisible to the user. But for stream errors, the user has already started receiving chunks. We can't "take back" what was sent, so instead:
WillRetryErrorto signal "retry is pending"If the error won't be retried (non-retryable or max retries exhausted), the original error is returned directly without wrapping.
Handling AgentEvents with Stream Retry
When retry is configured and streaming is enabled, users should handle events like this:
Key insight: With retry enabled, you may receive multiple streaming events for a single LLM call - one for each attempt. Only the last successful stream should be used for the final response.
Multi-Agent Workflow Behavior
In sequential workflows (Agent A → Agent B), stream errors are handled intelligently:
WillRetryError, then success)This prevents partial/errored responses from polluting the context window of downstream agents.
Error Propagation Rules
WillRetryError→ SuccessConfiguration Reference
Error Handling
Implementation Notes
retryChatModelwraps the model without changing graph topologyOnChatModelEndfor observabilityWillRetryErroris registered for checkpoint serializationIsRetryAbleandBackoffFuncreceive context for cancellation supportFiles Changed
adk/retry_chatmodel.goadk/chatmodel.goadk/react.goadk/flow.goWillRetryErrorevents ingenAgentInputadk/runctx.goStreamErrfield:string→erroradk/utils.goschema/stream.goWithErrWrapperoption for stream conversionadk/*_test.go