Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Provider Patterns?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/tylerjrbuell-provider-patterns)
---
name: provider-patterns
description: Configure per-provider behavior, understand streaming quirks, and use the 5-hook adapter system for optimal performance across LLM providers.
compatibility: Reactive Agents TypeScript projects using @reactive-agents/*
metadata:
author: reactive-agents
version: "2.0"
tier: "capability"
---
# Provider Patterns
## Agent objective
Produce a builder with the correct provider + model + any provider-specific configuration; know which providers need special handling for streaming and tool calls.
## When to load this skill
- Configuring a non-Anthropic provider
- Debugging tool call or streaming issues specific to one provider
- Using local models (Ollama) or proxy routing (LiteLLM)
- Enabling extended thinking or provider-specific model options
## Implementation baseline
```ts
// Anthropic — highest quality, native FC, prompt caching
const agent = await ReactiveAgents.create()
.withProvider("anthropic")
.withModel("claude-sonnet-4-6")
.withReasoning({ defaultStrategy: "adaptive" })
.withTools({ builtins: true })
.build();
// Local Ollama model
const agent = await ReactiveAgents.create()
.withProvider("ollama")
.withModel("qwen2.5:7b")
.withReasoning({ defaultStrategy: "reactive", maxIterations: 6 })
.withTools({ allowedTools: ["web-search"] })
.build();
```
## Provider selection guide
| Provider | Best for | Key notes |
|----------|----------|-----------|
| `"anthropic"` | Production, highest quality | Native FC, prompt caching, streaming |
| `"openai"` | GPT-4o, broad compatibility | Native FC, streaming |
| `"gemini"` | Multimodal, long context | Native FC; `functionResponse.name` quirk |
| `"ollama"` | Local, privacy-first | Tool calls arrive on `chunk.done` |
| `"litellm"` | Proxy routing, cost optimization | OpenAI-compatible; use for Groq, OpenRouter, etc. |
| `"test"` | Unit tests, CI | Returns deterministic mock responses |
## Key patterns
### Extended thinking (Anthropic)
```ts
.withProvider("anthropic")
.withModel({ model: "claude-opus-4-6", thinking: true })
// Enables extended thinking — model reasons before responding
// Higher quality on complex reasoning tasks; adds latency and cost
```
### LiteLLM for provider routing
```ts
// Groq, OpenRouter, Bedrock, Vertex — all through LiteLLM
.withProvider("litellm")
.withModel("groq/llama-3.1-70b-versatile")
// Model name format: "provider/model-name" as per LiteLLM docs
```
### Ollama Cloud and per-agent endpoints
Pass the endpoint and key on the provider; a `baseUrl` here is per agent, so two agents can target different Ollama servers:
```ts
const agent = await ReactiveAgents.create()
.withProvider("ollama", { baseUrl: "https://ollama.com", apiKey: process.env.OLLAMA_API_KEY })
.withModel("gpt-oss:120b")
.build();
```
An explicit `apiKey` is always sent (as a Bearer token, only to that endpoint). An `OLLAMA_API_KEY` from the environment is attached only when the endpoint is `https`, never to loopback or plain `http` hosts. A rejected key fails with a typed `OllamaAuthError`. Judgment models are not available on Ollama Cloud.
### Keys saved with `rax keys` or Cortex
```ts
// Uses the key saved with `rax keys set anthropic` (or in Cortex Settings) when ANTHROPIC_API_KEY is unset.
.withProvider("anthropic", { useStoredKey: true })
```
Off by default: without `useStoredKey: true` the builder never reads `~/.reactive-agents/keys`. Precedence: explicit `apiKey`, then the provider's env variable, then the stored key, read once when `.withProvider()` runs. The key never appears in logs or `toConfig()`. An unreadable store prints one builder notice and the agent continues without it.
### Input modalities
Ask what a model accepts before sending images or audio: `modelInputCapabilities(provider, model)` returns `{ vision, audioIn?, authoritative }`. `audioIn` mirrors the capability's `supportsAudioIn`. An image or audio part for a model that authoritatively cannot take it fails with `UnsupportedModalityError`; otherwise audio on providers with no audio slot (Anthropic, Ollama, LiteLLM) becomes a text placeholder. See the Multimodal Input guide on the docs site.
### Circuit breaker for unreliable providers
```ts
.withProvider("ollama")
.withModel("llama3:8b")
.withCircuitBreaker({
failureThreshold: 3, // open after 3 consecutive failures
cooldownMs: 30_000, // wait 30s before half-open probe
halfOpenRequests: 1,
})
.withRateLimiting({ requestsPerMinute: 10 })
```
### Enabling temperature and sampling
```ts
.withModel({ model: "gpt-4o", temperature: 0.2 }) // more deterministic
.withModel({ model: "claude-sonnet-4-6", temperature: 0.9 }) // more creative
```
## 5 adapter hooks (automatic — no configuration needed)
These hooks run automatically and adapt prompts/behavior for each provider's strengths:
| Hook | What it does |
|------|-------------|
| `continuationHint` | Tells the model to continue after tool results while required tools are pending |
| `errorRecovery` | Recovery prompt appended to the observation on tool errors |
| `synthesisPrompt` | Final answer synthesis guidance on the research→produce transition |
| `qualityCheck` | Post-step quality assessment (fires once before the final answer) |
| `parseToolCalls` | Normalizes malformed native tool calls (e.g. qwen3 stringified `arguments`) in every provider `complete()`/`stream()` response |
Adapter selection is automatic via `selectAdapter(capabilities, tier)`. Each provider (Anthropic, OpenAI, Gemini, Ollama) has an adapter with specialized implementations.
## Builder API reference
| Method | Key params | Notes |
|--------|-----------|-------|
| `.withProvider(p, opts?)` | `"anthropic"\|"openai"\|"gemini"\|"ollama"\|"litellm"\|"test"`; `opts: { baseUrl?, apiKey?, headers?, useStoredKey? }` | Required. `useStoredKey: true` reads the `rax keys` store when the env var is unset |
| `.withModel(m)` | `string \| { model, thinking?, temperature? }` | `thinking: true` = extended reasoning |
| `.withCircuitBreaker(cfg?)` | `{ failureThreshold?, cooldownMs?, halfOpenRequests? }` | Auto-retry with backoff |
| `.withRateLimiting(cfg)` | `{ requestsPerMinute?, tokensPerMinute?, maxConcurrent? }` | |
## Pitfalls
- `"groq"` and `"openrouter"` are **not** valid provider names — use `"litellm"` with the appropriate model prefix
- **Gemini**: `functionResponse.name` must use `msg.toolName`, not hard-coded `"tool"` — framework handles this but custom tool parsers must follow the same pattern
- **Ollama**: tool_calls arrive on `chunk.done`, not during the stream — don't parse mid-stream chunks for tool calls
- **Anthropic streaming**: use raw `streamEvent`, not helper events (`inputJson` fires before `contentBlock` in streaming FC)
- `thinking: true` requires a model that supports extended thinking — verify model capability before enabling
- LiteLLM model names are `"provider/model"` format — check LiteLLM docs for exact names