-
Notifications
You must be signed in to change notification settings - Fork 0
Providers
TinyAgents keeps model calls behind provider-neutral harness traits. Provider
adapters translate ModelRequest into the provider wire format and normalize
responses, usage, streaming chunks, and errors back into TinyAgents types.
ProviderKind currently covers:
openaianthropicollamadeepseekgroqxaiopenroutertogethermistralcompatible
Most hosted providers listed here are reached through an OpenAI-compatible Chat
Completions endpoint. The compatible kind is for any endpoint that implements
that wire format but does not need a named preset.
ProviderSpec is the portable provider configuration:
use tinyagents::harness::providers::{ProviderKind, ProviderSpec};
let spec = ProviderSpec::for_kind(ProviderKind::Groq)
.with_model("llama-3.3-70b-versatile");Each spec records:
- provider kind
- provider id used in profiles and normalized errors
- default model id
- base URL
- API-key environment variable, when required
- whether a real API key is required
export OPENAI_API_KEY=...
export OPENAI_MODEL=gpt-4.1-mini
cargo run --features openai --example openai_chatuse tinyagents::harness::providers::openai::OpenAiModel;
let model = OpenAiModel::from_env()?;OpenAiModel::from_env() reads OPENAI_API_KEY, optional OPENAI_MODEL, and
optional OPENAI_BASE_URL.
The OpenAI-compatible adapter includes convenience constructors:
use tinyagents::harness::providers::openai::OpenAiModel;
let anthropic = OpenAiModel::anthropic(std::env::var("ANTHROPIC_API_KEY")?);
let groq = OpenAiModel::groq(std::env::var("GROQ_API_KEY")?);
let ollama = OpenAiModel::ollama();Named constructors set the provider id, default base URL, and default model.
Override the model with with_model(...) when needed.
use tinyagents::harness::providers::{ProviderKind, ProviderSpec};
use tinyagents::harness::providers::openai::OpenAiModel;
let spec = ProviderSpec::for_kind(ProviderKind::Mistral)
.with_model("mistral-small-latest");
let model = OpenAiModel::from_spec_env(spec)?;from_spec_env reads the spec's configured environment variable. Use
from_spec(spec, api_key) when credentials come from another secret source.
Start Ollama with an OpenAI-compatible endpoint available at
http://localhost:11434/v1, then use:
use tinyagents::harness::providers::openai::OpenAiModel;
let model = OpenAiModel::ollama().with_model("llama3.2");Ollama ignores the API key, so TinyAgents uses a placeholder.
Providers should report failures as ProviderError with:
- provider id
- model id when known
- HTTP status when available
- provider error code when available
- human-readable message
- retryability hint
- raw provider payload when useful
Streaming providers emit ModelStreamItem values. Normal chunks become deltas,
usage updates, tool-call chunks, or final messages. Provider-side stream errors
become ModelStreamItem::ProviderFailed, so the accumulator and harness see the
same normalized failure shape as non-streaming calls.
ProviderKind::infer(...) supports LangChain-style explicit prefixes such as
openai:gpt-4.1-mini, anthropic:claude-..., and ollama:llama3.2, plus
conservative bare-model inference for common model families.
Prefer explicit ProviderSpec values in production. Inference is useful for
configuration files, examples, and interactive workflows where the model string
is the only user input.
Recursive language-model (RLM) harness for Rust.
Getting started
Concepts
Modules
Providers
Contributing