註冊並分享邀請連結,可獲得影片播放與邀請獎勵。

cv usk
@cv_usk
AI / Software Research Notes AI Agent, LLMOps, MLOps, Software Architecture 投稿は個人の意見です。
加入 May 2026
280 正在關注    415 粉絲
# Useful but Little-Known Features of OpenAI Agent SDK 🌍 Has a transient LLM API error ever crashed your entire agent pipeline? `ModelRetrySettings` lets the Runner automatically manage retry strategies, building agents resilient to temporary failures. 📌 Title: Runner-Managed Retries 🔗 URL: 🧩 Overview By passing `ModelRetrySettings` to the `retry` parameter of `ModelSettings`, you gain fine-grained control over retry count, backoff strategy, and retry policy. `max_retries` sets the maximum attempts, `backoff` configures delay strategy (`initial_delay`, `max_delay`, `multiplier`, `jitter`), and `policy` defines which error types qualify for retry. Importantly, abort errors, unsafe replays, streams after output begins, and stateful requests are never retried. 🛠 How to use it ```python from agents import Agent, ModelRetrySettings, ModelSettings, retry_policies agent = Agent( name="Assistant", model="gpt-5.5", model_settings=ModelSettings( retry=ModelRetrySettings( max_retries=4, backoff={ "initial_delay": 0.5, "max_delay": 5.0, "multiplier": 2.0, "jitter": True, }, policy=retry_policies.any( retry_policies.provider_suggested(), retry_policies.retry_after(), retry_policies.network_error(), retry_policies.http_status([408, 429, 500, 502, 503, 504]), ), ) ), ) ``` Available policy helpers: - `retry_policies.never()` - always opt out - `retry_policies.provider_suggested()` - follow provider guidance - `retry_policies.network_error()` - transient network failures - `retry_policies.http_status([...])` - specific HTTP status codes - `retry_policies.retry_after()` - honor Retry-After headers - `retry_policies.any(...)` / `retry_policies.all(...)` - combine policies 🏗 Building it into production ・Define default retry settings at the Runner level, override only `max_retries` per Agent ・Use `jitter: True` to avoid thundering herd when multiple agents retry simultaneously ・Always include 429 (rate limit) and 5xx (server errors) in your retry targets ・Agent-level settings deep-merge with Runner-level settings 💡 Use cases 🔄 Automatic backoff on rate limits (429) 🌐 Self-healing through transient network failures 🏢 Agent stability in multi-tenant environments 📊 Absorbing temporary errors in batch processing ⚠️ Watch out Abort errors, requests marked replay-unsafe by the provider, streams after output has started, and stateful requests using `previous_response_id` or `conversation_id` are never retried for safety. The `policy` field is not serialized, so it only takes effect at runtime. ✨ With ModelRetrySettings, build agents that stay resilient through transient failures. #OpenAIAgentSDK# #AIAgent#
顯示更多