Skip to main content

Model Providers

An agent uses a model to decide what to say or which tool to call. ISH provides one model interface for supported providers and lets you configure an ordered fallback with ModelCascade. You can also supply a host callback for tests or custom providers. The language SDKs use the shared Rust model request and response handling.

import asyncio
from ish import (
Agent,
AnthropicModel,
GeminiModel,
ModelCascade,
OpenAICompatibleModel,
)

async def main() -> None:
cascade = ModelCascade([
OpenAICompatibleModel(model="gpt-4o-mini"),
AnthropicModel(model="claude-sonnet-4-6"),
GeminiModel(model="gemini-2.5-flash"),
])

# Or connect directly to a custom OpenAI-compatible endpoint:
# model = OpenAICompatibleModel(
# model="Qwen/Qwen2.5-72B-Instruct",
# base_url="http://localhost:8000/v1",
# api_key="local-token",
# )

agent = Agent(name="assistant", model=cascade, instructions="Be concise.")
try:
result = await agent.run("Explain failover cascades in one sentence.")
print(result.content)
finally:
agent.close()

asyncio.run(main())

Provider Architecture​

  1. Unified message history: User, assistant, system, and tool-call turns use one normalized payload contract across providers.
  2. Failover cascades: ModelCascade configures an ordered list of providers handled natively by Rust, with retry and fallback semantics on transient failures.
  3. Host callbacks & deterministic tests: Every SDK supports offline/deterministic model providers (MockModel in Python and Rust, or host callback delegates in TypeScript, Go, C#, and Java).

Provider identifiers​

Use these identifiers in an agent model configuration. Keep the matching API key in the process environment or another secure configuration source.

Provider identifierServiceCredential
openai_chatOpenAI Chat Completions or a compatible endpointOPENAI_API_KEY
openai_responsesOpenAI Responses APIOPENAI_API_KEY
anthropicAnthropic Messages APIANTHROPIC_API_KEY
geminiGoogle Gemini GenerateContent APIGEMINI_API_KEY

ModelCascade accepts an ordered list of these providers. The runtime applies the configured retry and fallback policy; a cascade cannot guarantee that a provider remains available.

The provider names above configure agent model calls. The DecisionsClient uses a separate provider setting: openai selects OpenAI Chat Completions for structured decisions, while jev selects TypeSafe AI Jev. Neither identifier is an alias for the agent model provider openai_chat; jev is not an agent model provider.

Offline testing, host callbacks​

Run deterministic unit tests without network calls using MockModel (Python and Rust) or a host-language model callback (TypeScript, Go, C#, and Java):

import asyncio
from ish import Agent, MockModel
from ish.primitives.types import ModelResponse

async def main() -> None:
model = MockModel(responses=[ModelResponse(content="Fixed test response")])
agent = Agent(name="tester", model=model)
result = await agent.run("Check pipeline")
assert result.content == "Fixed test response"

asyncio.run(main())

Decisions API (model.decide)​

model.decide provides a schema-validated structured decision endpoint implemented by the shared runtime. It accepts named predicate, choice, and score questions in one request without requiring an agent tool loop.

Supported providers for model.decide​

ProviderWire protocolEnvironment variableDefault base_url
openaiChat Completions + response_format JSON SchemaOPENAI_API_KEYhttps://api.openai.com/v1
geminiGoogle generateContent + responseJsonSchemaGEMINI_API_KEYhttps://generativelanguage.googleapis.com/v1beta
jevTypeSafe AI Jev decision API with structured outputJEV_API_KEY (or OPENAI_API_KEY)https://api.typesafe.ai/v1
anthropicAnthropic Messages + tool-forcing JSON outputANTHROPIC_API_KEYhttps://api.anthropic.com/v1

When running the standalone server, POST /api/decisions exposes model.decide using ISH_LLM_PROVIDER, ISH_LLM_MODEL, and ISH_LLM_BASE_URL (plus the corresponding provider API key environment variable).

Polyglot usage​

Each SDK exposes a typed DecisionsClient that submits a decision request to the shared Rust runtime. Rust applications can use that same client directly; the C ABI also makes the operation available to native callers. You do not need to know the internal operation name to use the SDK.

Questions use Rust's tagged schema: predicate has name and instructions; choice adds a choices string array; score adds a levels string array. Answers are keyed by name.

from ish.decisions import DecisionsClient

client = DecisionsClient(provider="openai", model="gpt-4o-mini")
result = client.decide("Should we deploy?", [
{"type": "predicate", "name": "safe", "instructions": "Is the build safe?"},
{"type": "choice", "name": "environment", "instructions": "Choose a target.", "choices": ["staging", "production"]},
{"type": "score", "name": "confidence", "instructions": "Rate confidence.", "levels": ["low", "medium", "high"]},
])
print(result["answers"])