Polly
Resilience and transient fault handling library for .NET — implements retry, circuit breaker, timeout, rate limiting, fallback, and hedging patterns. Polly v8 (via Microsoft.Extensions.Resilience): ResiliencePipelineBuilder<HttpResponseMessage>().AddRetry(new RetryStrategyOptions { MaxRetryAttempts = 3, BackoffType = DelayBackoffType.Exponential }).AddCircuitBreaker().AddTimeout(TimeSpan.FromSeconds(30)).Build(). AddResilienceHandler in IHttpClientBuilder for HttpClient integration. Handles transient failures in agent service-to-service calls, LLM API calls (rate limits, timeouts), and database operations. Policies chain into pipeline executing from outer to inner.
Score Breakdown
⚙ Agent Friendliness
🔒 Security
Polly retry can amplify security issues — retrying agent auth failures wastes LLM API rate limit; configure ShouldHandle to exclude 401/403 responses from retry. Circuit breaker prevents agent service from hammering failing endpoints (DoS protection). Ensure retry budget accounts for LLM API rate limits to avoid auto-banning agent API keys.
⚡ Reliability
Best When
Your .NET agent service makes external calls (LLM APIs, tool APIs, databases) that experience transient failures — Polly makes your agent resilient to temporary failures with minimal code changes.
Avoid When
Your calls are to local in-process dependencies, you need saga compensation, or your 'failures' are business logic errors that shouldn't be retried.
Use Cases
- • Retry agent LLM API calls on transient failures — ResiliencePipeline with AddRetry retries OpenAI/Anthropic calls on 429 (rate limit) and 503 (service unavailable) with exponential backoff; prevents agent failures from temporary LLM service blips
- • Circuit breaker for agent external tool calls — AddCircuitBreaker opens after 5 failures in 30 seconds, preventing cascading failures when agent tool API is down; half-open probing resumes calls after recovery window
- • Timeout protection for agent API calls — AddTimeout(TimeSpan.FromSeconds(10)) limits agent tool call execution time; prevents agent from hanging indefinitely on slow external services
- • HttpClient resilience pipeline for agent services — builder.AddHttpClient<IAgentApiClient, AgentApiClient>().AddResilienceHandler('agent-api', builder => { builder.AddRetry(...).AddCircuitBreaker(...) }) applies resilience to all agent HTTP calls
- • Rate limiting outbound agent LLM requests — AddRateLimiter(new SlidingWindowRateLimiter(options)) controls agent request rate to LLM API to stay within provider rate limits and prevent 429 errors
Not For
- • Inbound rate limiting for agent APIs — Polly limits outbound calls; for limiting incoming agent API requests from clients, use ASP.NET Core rate limiting middleware or API gateway
- • Saga compensation — Polly handles transient failures with retry/fallback; for complex agent workflow compensation (undo completed steps on failure), use Temporal or MassTransit Sagas
- • Infinite retry loops — Polly retry must have MaxRetryAttempts; unbounded retry on non-transient errors causes infinite loops; always configure max attempts and handle non-retryable exceptions
Interface
Authentication
Resilience library — no auth concepts. Handles retry/circuit breaker for HTTP calls that already have auth configured.
Pricing
Polly is BSD-3 licensed, maintained by App-vNext. Free for all use.
Agent Metadata
Known Gotchas
- ⚠ Polly v8 is a breaking change from v7 — Polly 8 renamed to Microsoft.Extensions.Resilience and changed API entirely (PolicyWrap → ResiliencePipeline, Execute → ExecuteAsync); agent projects upgrading must rewrite all Policy.Handle<>().Retry() calls; v7 and v8 are not compatible in same registration approach
- ⚠ Retry non-idempotent agent operations causes data duplication — retrying POST /agents without idempotency key creates duplicate agents on each retry; Polly retries are transparent to business logic; add idempotency key header and handle 409 Conflict as retry-safe for agent creation endpoints
- ⚠ Circuit breaker is per-ResiliencePipeline instance — each agent client using separate ResiliencePipeline has isolated circuit breaker; all agent API calls should share same ResiliencePipeline instance via DI; separate instances don't share circuit state and each opens independently causing partial protection
- ⚠ jitter required for thundering herd on retry — ExponentialBackoff without jitter causes all failed agent instances to retry simultaneously after identical delay; AddRetry with UseJitter = true spreads retry attempts; critical for agent services with multiple instances hitting shared LLM API under load
- ⚠ ShouldHandle must explicitly include exception types — by default Polly v8 handles no exceptions; must configure ShouldHandle: new PredicateBuilder().Handle<HttpRequestException>().HandleResult(r => r.StatusCode == HttpStatusCode.TooManyRequests) for agent LLM retry; unspecified exception types are not retried even with retry policy
- ⚠ Timeout cancels via CancellationToken not exception — Polly timeout cancels operation via CancellationToken passed to agent handler; handler must observe CancellationToken for timeout to work; synchronous agent code ignoring cancellation token continues past timeout and TimeoutRejectedException is thrown after handler returns
Alternatives
Full Evaluation Report
Comprehensive deep-dive: security analysis, reliability audit, agent experience review, cost modeling, competitive positioning, and improvement roadmap for Polly.
AI-powered analysis · PDF + markdown · Delivered within 30 minutes
Package Brief
Quick verdict, integration guide, cost projections, gotchas with workarounds, and alternatives comparison.
Delivered within 10 minutes
Score Monitoring
Get alerted when this package's AF, security, or reliability scores change significantly. Stay ahead of regressions.
Continuous monitoring
Scores are editorial opinions as of 2026-03-07.