feat(providers): add shared authentication and resilience - #16
Merged
Conversation
danielkov
force-pushed
the
feat/provider-resiliency
branch
from
August 30, 2026 00:35
eba8025 to
99dcb62
Compare
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
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.
Summary
Adds shared authentication and resilience configuration across AgentKit model providers. Introduces separate OpenAI Chat Completions and Responses adapters, including configurable support for public OpenAI Responses and private ChatGPT deployments.
Motivation
Provider adapters previously stored raw credential strings and implemented inconsistent authentication, retry, timeout, and stream-recovery behavior. This change gives providers reusable HTTP-layer authentication and resilience primitives while keeping each provider’s authentication scheme and wire protocol explicit.
Impact
Existing constructors continue to accept string credentials, and omitted resilience preserves the current single-attempt behavior. The following public API changes require migration:
api_keyandauth_tokenbecomeauthentication: Authentication; Ollama and vLLM useOption<Authentication>because authentication remains optional.resilience: Option<ResilienceConfig>. Exhaustive struct literals must addresilience: Noneor move to constructors and builders.SessionConfiggainsconsumer_capabilities; direct struct literals must add the field or useSessionConfig::new(...).ModelTurnEventandAgentEventgainResponseAttemptSuperseded; exhaustive matches must handle the new variant.x-api-keyfrom bearer authentication. A bare string converted directly toAuthenticationalways means bearer authentication.Technical details
Shared authentication API
agentkit-httpnow exportsAuthentication,AuthenticationAttempt, and the asynchronousAuthenticationProvidercontract. A provider receivesNonefor initial authentication and the rejected attempt after a401, allowing one controlled refresh while keeping provider-private state opaque.Static bearer authentication remains concise:
Refreshable authentication can retain rejected-attempt state and attach a stable, non-secret binding:
The rejected-attempt refresh is independent of resilience retries. OpenAI Responses additionally requires the refreshed attempt to retain the original non-secret binding before replaying continuation state.
Optional resilience
All provider configurations can opt into a shared retry and timeout policy:
resilience: Nonepreserves the existing no-timeout, single-attempt behavior.Some(ResilienceConfig::default())enables bounded retries and timeouts; it is not equivalent to omission.Authentication schemes remain provider-specific:
x-api-keyvianew, bearer viawith_auth_tokenFor Anthropic, use the constructor matching the intended scheme:
Protected Ollama and vLLM deployments can now opt in without changing local defaults:
Separate OpenAI schema adapters
Chat Completions and Responses remain separate request codecs and stream state machines. The explicit Chat Completions name is
OpenAIChatCompletionsAdapter; the historicalOpenAIAdapteralias remains available.OpenAIResponsesConfig::new(authentication, model)follows the existingOpenAIConfigargument order. Profile-specific constructors are model-first:The Responses adapter supports configurable endpoints, request policy, limits, attribution, encrypted reasoning continuation, idempotency, response-size bounds, and private ChatGPT request/stream behavior without embedding any consumer-specific metadata or persistence formats.
Typed response-attempt supersession
OpenAI Responses retries only before visible output by default. A consumer that can discard an already-rendered attempt may opt into post-output recovery with a typed capability:
Opting in asserts that the consumer can discard all deltas, tool calls, usage, and reconstruction state from the failed attempt. AgentKit emits
ResponseAttemptSupersededafter the failed attempt and before any replacement output. Without the capability, a failure after visible output is returned instead of replayed.