ADR-0026: The provider path: one turn loop, provider profiles, then native adapters
- Status: Accepted on 2026-11-25 (task z1). Decision 1 is built (see "As built in 0.6"); decisions 2 to 7 are the plan for 0.9 and later, and their details are checked again when built.
- Date: 2026-11-23
- Extends: ADR-0002. The official
openaiSDK, the Responses wire format,src/openai/as the only module that importsopenai, and no foreign types in the public API all stay. ADR-0002's "OpenAI only" becomes "OpenAI by default, other providers through profiles", from 0.9. - Amends, for Claude only: ADR-0015 variant A (decision 6).
- Evidence: spikes S6a (findings) and S6b (findings).
Context
Two spikes looked at a second model provider:
- S6a, Claude natively (
@anthropic-ai/sdk): go, with conditions. Every protocol event has a Claude source and caching held 96 % over 20 turns. But it needs an own conversation store and own retrieval;suggest_repliesmust come before the answer, or the answer disappears (0 of 3); the forced last step needs a system note (6 of 8 runs failed without it); deleted or expired files in history make every later turn fail; and there is no voice or moderation. About 4× the cost ofgpt-6.1-terraper conversation, and knowledge answers start about 2× later. - S6b, Open Responses endpoints through the same
openaiSDK: go, with conditions, for OpenRouter. The stream mapper ran unchanged on every endpoint, with 0 exceptions, and stateless replay worked everywhere. What differs per endpoint is small and server-side: error shapes, a field that turns on prompt caching (Claude through OpenRouter cached 0 % withoutcache_controland 94 % with it), the forced-last-step note, and model quality (gpt-oss-120bfailed: no parallel calls, nosuggest_replies, tool-output markers leaked into 11 of 20 answers). - Hugging Face and local servers were not verified, not rejected. Hugging Face answered every model call with 402 for want of pre-paid credits, so only its request validation and error shapes were seen: every error arrives as HTTP 200 with
response.failed, and it refusesallowed_tools. The 16 GB laptop couldn't run a local model through a whole experiment.
Both spikes need what 0.6 builds anyway: conversation state outside the provider (ADR-0024) and retrieval as a function tool (ADR-0025).
Decision
-
0.6 splits the gateway, and adds no provider. Conversation state and retrieval move out of
ModelGatewayinto their ports, the turn loop gains its stateless mode for item stores, and knowledge on an index becomes a function tool. After that a second provider only has to run turns.ModelGatewaystays internal in 0.6; fields with OpenAI names (safetyIdentifier,vectorStoreId, the reservedfile_search, the meaning ofanswerItemId) are renamed while they still can be, as each 0.6 task touches them. -
The second provider path is a profile of
src/openai/, not a new module (0.9). The same SDK, request builder, stream mapper and tool loop serve every endpoint that speaks the Responses wire format. A provider profile, chosen in server configuration and never by the client (ADR-0004), holds:- the
baseURLand the name of its key's environment variable; - state:
conversations(OpenAI only) orstateless(an item store is required,store: false, encrypted reasoning replayed). A stateless profile refuses a provider store at startup, and never sendsconversation, which OpenRouter silently ignores; - extra request fields the provider needs, such as top-level
cache_controlfor Claude on OpenRouter; - capabilities:
allowed_tools(without it,suggest_repliesis dropped from the tool list on a later step instead), moderation, files, transcription and hosted search, checked bydefineBotandcreateChatHandlerat startup rather than failing at runtime; - the forced-last-step note: a line in the instructions that tools are unavailable, for models that return nothing under
tool_choice: 'none', plus a lower output limit on that step; - an error classifier on top of today's mapping: 402 and an unknown model become
bot_unavailable, a context-length message becomeserror.conversationTooLong, and astoreorprevious_response_idrefusal is a configuration error thatdoctorreports.
- the
-
Supported in 0.9: OpenAI (
conversationsorstateless) and OpenRouter (stateless). Each profile is supported for verified models only, listed in the docs, not in code (the library names no model IDs). A model is verified by rerunning S6b's probes (spikes/s6b-open-responses/): stream conformance, parallel calls,suggest_replies, the forced last step, replay and errors. Claude Haiku 5.5 through OpenRouter passed;gpt-oss-120bdid not. -
Hugging Face and local servers (Ollama and others): not verified in 0.6, and left open. The profile shape above is meant to take them; a profile for each is added once a verification run passes. What that run must look at:
- errors that arrive as HTTP 200 with
response.failed(Hugging Face), which need the classifier to read the status out of the in-stream error; - Hugging Face refusing
allowed_tools, which needs the fallback in decision 2; - a local step that spends its whole output on reasoning and still ends
completed(seen once on Ollama), which must map tomax_output_tokens.
The run needs a funded Hugging Face account (about 5 USD) and a machine that can run a local model with tools; it is a roadmap line, not a 0.6 task.
- errors that arrive as HTTP 200 with
-
Native adapters come later, as add-ons. A native Claude adapter (
@boldare/askdare-anthropic) is the first, when a client needs what the Responses wire format can't give. It makesModelGatewaya public port implemented by an official add-on, asRateLimitStoreis (ADR-0006), so the port gets a review first. Its conditions, from S6a:- an item store (ADR-0024) that keeps Claude's assistant content exactly, as
nativeitems, and replaces a file block with a text placeholder when its file is deleted or expires; - own retrieval (ADR-0025), with
search_resultblocks whosesourceis the source ID; - per-request context (identity, guardrail notes) as
role: "system"messages after the cached prefix, never insystem; metadata.user_idinstead ofsafety_identifier, server-sidefallbacks, andrefusalmapped tocontent_filter;- no voice and no moderation on that gateway, refused by
defineBot; - usage mapped so
inputTokensincludes cached and written tokens, and the OpenTelemetry add-on takesgen_ai.provider.namefrom the gateway instead of hardcodingopenai. - Message threads are not used: no gain at chatbot sizes,
tool_choicefixed per thread, and not ZDR-eligible.
- an item store (ADR-0024) that keeps Claude's assistant content exactly, as
-
Reply options on Claude (amends ADR-0015 variant A for Claude only): on the native Messages API,
suggest_repliesis called before the answer, because text written before a tool call comes back as an empty thinking block. It costs one more model call (about 1.7 s) on turns that offer options. A profile or adapter saysreplies: 'after' | 'before' | 'off'per verified model. Through OpenRouter, Claude Haiku called it after the answer as ADR-0015 expects. OpenAI is unchanged. -
Shared guards, whatever the provider:
- Zod re-validation of tool arguments stays mandatory: OpenRouter accepted
strictschemas OpenAI rejects and didn't enforce them. - Output sanitising strips
【…】-style tool-output markers before rendering. - Usage reads optional fields defensively (
input_tokens_details, cache writes), and a provider's chargedusage.cost, when present, is passed toonStepas an optional field.
- Zod re-validation of tool arguments stays mandatory: OpenRouter accepted
As built in 0.6
- The gateway is split (tasks 1, 2 and k2): conversations live behind
ConversationStore(ADR-0024), retrieval on an own index behindKnowledgeIndexand thesearch_knowledgefunction tool (ADR-0025), and the turn loop runs statelessly from an item store.ModelGatewaykeeps file uploads and deletes, transcription, turns, compaction, moderation anddiagnose, and stays internal. - The OpenAI-named fields are not renamed yet.
safetyIdentifier,vectorStoreIdand the meaning ofanswerItemIdare still on the internalModelGatewaytypes: no 0.6 task needed to change them, and renaming them costs nothing while the port is internal. They are renamed in the review that makes the port public (decision 5). - Shared guards (decision 7) that 0.6 already has: Zod re-validation of tool arguments, and usage read defensively (missing cache details count as 0). Stripping
【…】markers andusage.costcome with the first profile that needs them.
Consequences
- 0.6 ships no new provider but leaves only the turn to write for one. The seams are proven by OpenAI's own stateless mode, which S7 measured at the same cost as conversation mode.
- 0.9's profile work is small: S6b ran four endpoints through the library's own mapper unchanged. Supporting a model costs a verification run, not code.
- The supported list stays short and explicit. "Any endpoint that claims Open Responses" is not a support promise.
- Without moderation, files or transcription on a profile, those features are off for its bots;
doctorand startup checks say so. - A native Claude adapter costs a public
ModelGatewayport, the replies-first variant, and docs that warn about cost and latency.
Alternatives considered
- Native Claude first, in 0.6: it needs the most change (a public gateway port, a new SDK in an add-on, replies-first) for a provider S6b reaches through OpenRouter with the existing module.
- Any Open Responses endpoint, unverified: S6b found a model that leaks tool-output markers into answers and another endpoint that hides every error behind HTTP 200. Unverified models would fail in ways visitors see.
- Rejecting Hugging Face and local servers: S6b couldn't run them, which says nothing about whether they work. A profile slot and a verification run cost little.
- The Vercel AI SDK or
@openai/agentsas the multi-provider layer: ADR-0002's reasons stand: leaked types and breaking minors, and askdare's own protocol, tool loop and guardrails would sit on top anyway. - Anthropic message threads for Claude's state: see decision 5.