agentskit.js

@agentskit/adapters — for agents

Provider adapters (OpenAI-compatible + native) + router + ensemble + fallback + generic factory.

#Purpose

Every LLM provider, one contract. Stream, tool calls, retry, abort all normalized. Plus higher-order adapters that compose candidates (router, ensemble, fallback) and a createAdapter factory for custom providers.

#Install

npm install @agentskit/adapters

#Primary exports

#Native adapters

  • anthropic, openai, gemini, grok, ollama, deepseek, kimi, langchain, langgraph, vercelAI, generic.
  • azureOpenAI / azureOpenAIAdapter — Azure-hosted OpenAI deployments.
  • vertex / vertexAdapter — Google Vertex AI (Gemini, Anthropic-on-Vertex).
  • bedrock / bedrockAdapter — AWS Bedrock.
  • replicate / replicateAdapter — Replicate inference.
  • bail / bailAdapter (alias qwen) — Alibaba DashScope / Qwen.
  • webllm / webllmAdapter — browser-only WebGPU via @mlc-ai/web-llm (peer dep).
  • createAdapter({ send, parse, abort }) — build your own. See Custom adapter recipe.

#OpenAI-compatible providers

mistral, cohere, together, groq, fireworks, openrouter, huggingface, lmstudio, vllm, llamacpp, cerebras (with cerebrasAdapter factory variant). All share the createOpenAICompatibleAdapter base; each exposes a default baseUrl and accepts an override.

#Composition

  • createRouter({ candidates, policy, classify, onRoute }) — pick one per request by cost / latency / tags / custom. See Adapter router.
  • createEnsembleAdapter({ candidates, aggregate }) — fan-out + merge (majority-vote / concat / longest / fn). See Ensemble.
  • createFallbackAdapter([candidates], { shouldRetry, onFallback }) — try in order, fall through on open / first-chunk / zero-chunk failures. See Fallback chain.

#Testing + utilities

  • mockAdapter, recordingAdapter, replayAdapter, inMemorySink — ship without network.
  • simulateStream, chunkText, fetchWithRetry — lower-level helpers.

#Cost / carbon / lifecycle

  • applyCarbonTable, estimateCO2Grams, DEFAULT_CARBON_TABLE — carbon-aware routing inputs; feed into createRouter policy.
  • resolveModel, withDeprecationPolicy, DEFAULT_DEPRECATION_TABLE — auto-upgrade deprecated model IDs at adapter construction.
  • refreshCredentials, createRotatingCredentials — async credential refresh for short-lived tokens (Bedrock, Vertex).

#Embedders

  • openaiEmbedder, geminiEmbedder, ollamaEmbedder, deepseekEmbedder, grokEmbedder, kimiEmbedder, createOpenAICompatibleEmbedder.

#Minimal example

import { openai } from '@agentskit/adapters'

const adapter = openai({ apiKey: process.env.OPENAI_API_KEY!, model: 'gpt-4o-mini' })

#Common patterns

  • Rank candidates by cost and fall back on errors: compose createRouter with createFallbackAdapter.
  • A/B providers without users: speculate or replayAgainst.
  • Test without keys: pair recordingAdapter + replayAdapter (deterministic replay).

#Source

Explore nearby

✎ Edit this page on GitHub·Found a problem? Open an issue →·How to contribute →

On this page