Skip to content

FEAT: 在模型请求失败时能够自动重试#82

Open
leeyyi wants to merge 1 commit into
trpc-group:mainfrom
leeyyi:feat/model_retry
Open

FEAT: 在模型请求失败时能够自动重试#82
leeyyi wants to merge 1 commit into
trpc-group:mainfrom
leeyyi:feat/model_retry

Conversation

@leeyyi

@leeyyi leeyyi commented Jun 16, 2026

Copy link
Copy Markdown
Contributor

No description provided.

@codecov

codecov Bot commented Jun 16, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 94.07407% with 16 lines in your changes missing coverage. Please review.
⚠️ Please upload report for BASE (main@32d7af9). Learn more about missing BASE report.

Files with missing lines Patch % Lines
trpc_agent_sdk/models/_retry.py 93.86503% 10 Missing ⚠️
trpc_agent_sdk/configs/_model_retry_config.py 95.77465% 3 Missing ⚠️
trpc_agent_sdk/models/_anthropic_model.py 57.14286% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main         #82   +/-   ##
==========================================
  Coverage        ?   87.46347%           
==========================================
  Files           ?         418           
  Lines           ?       40721           
  Branches        ?           0           
==========================================
  Hits            ?       35616           
  Misses          ?        5105           
  Partials        ?           0           

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@leeyyi leeyyi force-pushed the feat/model_retry branch 2 times, most recently from 2d23ed5 to 4335b2b Compare June 16, 2026 07:52
of not retrying.
"""

num_retries: int = Field(default=2, ge=0)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里的策略可以让用户自己来实现吗?

namespaces, and message strings for the same condition.
"""

from __future__ import annotations

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个retry缺少类的封装,业界是这样实现的吗?

@@ -0,0 +1,227 @@
# Tencent is pleased to support the open source community by making tRPC-Agent-Python available.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

文档加下用法

`agent/config.py` 从环境变量构造:

```python
ModelRetryConfig(

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个配置加一下解释说明

@leeyyi leeyyi force-pushed the feat/model_retry branch from 4335b2b to 21f5804 Compare June 17, 2026 09:47

model_config = ConfigDict(extra="forbid")

retryable_error_codes: list[str] = Field(default_factory=lambda: ["408", "409", "429", "500", "502", "503", "504"])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个不需要用户配置吧

from pydantic import model_validator


class RetryRuleConfig(BaseModel):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个类是否需要让用户类配呢?

"""Honor provider ``Retry-After`` or ``retry-after-ms`` hints when present."""


class FixedBackoffConfig(BaseModel):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

别人是怎么命名的

"""Honor provider ``Retry-After`` or ``retry-after-ms`` hints when present."""


class RegisteredBackoffConfig(BaseModel):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里的类设计有问题,既然RegisteredBackoffConfig是让用户扩展的类,那么为啥FixedBackoffConfig没有继承RegisteredBackoffConfig呢

_BACKOFF_STRATEGIES[type_name] = strategy


class DefaultRetryPolicy(RetryPolicy):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RetryPolicy和BackoffStrategy有啥区别

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants