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.
- Python
- TypeScript
- Rust
- Go
- C#
- Java
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())
import { Agent, ModelCascade } from "ish-harness";
const cascade = new ModelCascade([
{ provider: "openai_chat", name: "gpt-4o-mini" },
{ provider: "anthropic", name: "claude-sonnet-4-6" },
{ provider: "gemini", name: "gemini-2.5-flash" },
]);
const agent = new Agent({
name: "assistant",
model: cascade,
instructions: "Be concise.",
});
try {
const result = await agent.run("Explain failover cascades in one sentence.");
console.log(result.content);
} finally {
agent.close();
}
use ish_harness::models::model_backend_from_config;
use ish_harness::Agent;
use serde_json::json;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let cascade = model_backend_from_config(
&json!({
"providers": [
{ "provider": "openai_chat", "name": "gpt-4o-mini" },
{ "provider": "anthropic", "name": "claude-sonnet-4-6" },
{ "provider": "gemini", "name": "gemini-2.5-flash" }
]
}),
None,
)?;
let agent = Agent::builder(cascade)
.name("assistant")
.instructions("Be concise.")
.build()?;
let result = agent.run("Explain failover cascades in one sentence.").await?;
println!("{}", result.content);
Ok(())
}
package main
import (
"context"
"fmt"
ish "github.com/ish-harness/ish-harness/sdks/go"
)
func main() {
client, err := ish.NewClient()
if err != nil {
panic(err)
}
defer client.Close()
cascade, err := ish.NewModelCascade([]ish.AgentModel{
{Provider: "openai_chat", Name: "gpt-4o-mini"},
{Provider: "anthropic", Name: "claude-sonnet-4-6"},
{Provider: "gemini", Name: "gemini-2.5-flash"},
})
if err != nil {
panic(err)
}
agent := ish.NewAgent(client, ish.AgentRunRequest{
Model: cascade.ToAgentModel(),
SystemPrompt: ish.StringPtr("Be concise."),
})
res, err := agent.Run(context.Background(), "Explain failover cascades in one sentence.")
if err != nil {
panic(err)
}
fmt.Println(res["content"])
}
using System;
using Ish.Harness;
using var client = new IshClient();
var cascade = new ModelCascade(
[
new AgentModel { Provider = "openai_chat", Name = "gpt-4o-mini" },
new AgentModel { Provider = "anthropic", Name = "claude-sonnet-4-6" },
new AgentModel { Provider = "gemini", Name = "gemini-2.5-flash" }
]);
var result = client.Run(new AgentRunRequest
{
Model = cascade.ToAgentModel(),
SystemPrompt = "Be concise.",
UserPrompt = "Explain failover cascades in one sentence."
});
Console.WriteLine(result.GetProperty("content").GetString());
import com.fasterxml.jackson.databind.JsonNode;
import io.github.ishharness.IshClient;
import io.github.ishharness.ModelCascade;
import io.github.ishharness.ModelProviderOptions;
import java.nio.file.Path;
import java.util.List;
public class ModelProvidersExample {
public static void main(String[] args) {
try (var client = new IshClient(Path.of(System.getenv("ISH_NATIVE_LIBRARY")))) {
var cascade =
ModelCascade.fromOptions(
List.of(
new ModelProviderOptions("openai_chat", "gpt-4o-mini"),
new ModelProviderOptions("anthropic", "claude-sonnet-4-6"),
new ModelProviderOptions("gemini", "gemini-2.5-flash")));
var request =
new IshClient.AgentRequest(
"gpt-4o-mini",
"Be concise.",
"Explain failover cascades in one sentence.")
.modelCascade(cascade);
JsonNode result = client.runAgent(request);
System.out.println(result.path("content").asText());
}
}
}
Provider Architecture
- Unified message history: User, assistant, system, and tool-call turns use one normalized payload contract across providers.
- Failover cascades:
ModelCascadeconfigures an ordered list of providers handled natively by Rust, with retry and fallback semantics on transient failures. - Host callbacks & deterministic tests: Every SDK supports offline/deterministic model providers (
MockModelin 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 identifier | Service | Credential |
|---|---|---|
openai_chat | OpenAI Chat Completions or a compatible endpoint | OPENAI_API_KEY |
openai_responses | OpenAI Responses API | OPENAI_API_KEY |
anthropic | Anthropic Messages API | ANTHROPIC_API_KEY |
gemini | Google Gemini GenerateContent API | GEMINI_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):
- Python
- TypeScript
- Rust
- Go
- C#
- 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())
import { Agent } from "ish-harness";
const agent = new Agent({
name: "tester",
model: {
generate(_req) {
return { content: "Fixed test response" };
},
},
instructions: "Be concise.",
});
const result = await agent.run("Check pipeline");
console.log(result.content);
use std::sync::Arc;
use ish_harness::data_plane::types::ModelResponse;
use ish_harness::{Agent, MockModel};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let response = ModelResponse {
content: Some("Fixed test response".to_string()),
tool_calls: vec![],
prompt_tokens: 0,
cached_prompt_tokens: 0,
cache_write_tokens: 0,
completion_tokens: 0,
reasoning_tokens: 0,
total_tokens: 0,
latency_ms: 0.0,
provider: None,
model: None,
estimated_cost_usd: None,
cost_rate_provenance: None,
};
let model = Arc::new(MockModel::new(vec![response]));
let agent = Agent::builder(model).name("tester").build()?;
let result = agent.run("Check pipeline").await?;
assert_eq!(result.content, "Fixed test response");
Ok(())
}
package main
import (
"context"
"fmt"
ish "github.com/ish-harness/ish-harness/sdks/go"
)
func main() {
client, err := ish.NewClient()
if err != nil {
panic(err)
}
defer client.Close()
res, err := client.Run(context.Background(), ish.AgentRunRequest{
UserPrompt: "Check pipeline",
ModelCallback: func(ctx context.Context, req map[string]any) (map[string]any, error) {
return map[string]any{"content": "Fixed test response"}, nil
},
})
if err != nil {
panic(err)
}
fmt.Println(res["content"])
}
using System;
using System.Threading.Tasks;
using Ish.Harness;
using var client = new IshClient();
var result = client.Run(new AgentRunRequest
{
UserPrompt = "Check pipeline",
ModelCallback = (_, _) => ValueTask.FromResult<object?>(new
{
content = "Fixed test response"
})
});
Console.WriteLine(result.GetProperty("content").GetString());
import com.fasterxml.jackson.databind.JsonNode;
import io.github.ishharness.IshClient;
import java.nio.file.Path;
import java.util.Map;
public class OfflineModelExample {
public static void main(String[] args) {
try (var client = new IshClient(Path.of(System.getenv("ISH_NATIVE_LIBRARY")))) {
var request =
new IshClient.AgentRequest("mock", "Be concise.", "Check pipeline")
.modelProvider(req -> Map.of("content", "Fixed test response"));
JsonNode result = client.runAgent(request);
System.out.println(result.path("content").asText());
}
}
}
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
| Provider | Wire protocol | Environment variable | Default base_url |
|---|---|---|---|
openai | Chat Completions + response_format JSON Schema | OPENAI_API_KEY | https://api.openai.com/v1 |
gemini | Google generateContent + responseJsonSchema | GEMINI_API_KEY | https://generativelanguage.googleapis.com/v1beta |
jev | TypeSafe AI Jev decision API with structured output | JEV_API_KEY (or OPENAI_API_KEY) | https://api.typesafe.ai/v1 |
anthropic | Anthropic Messages + tool-forcing JSON output | ANTHROPIC_API_KEY | https://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.
- Python
- TypeScript
- Rust
- Go
- C#
- Java
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"])
import { DecisionsClient, IshClient } from "ish-harness";
const ish = new IshClient();
const decisions = new DecisionsClient(ish);
const result = decisions.decide({
input: "Should we deploy?",
questions: [
{ 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"] },
],
});
console.log(result);
ish.close();
use ish_harness::models::{DecisionQuestion, DecisionsClient};
let client = DecisionsClient::new("openai".into(), "gpt-4o-mini".into(), None, std::env::var("OPENAI_API_KEY")?);
let result = client.decide("Should we deploy?", &[
DecisionQuestion::Predicate { name: "safe".into(), instructions: "Is the build safe?".into() },
DecisionQuestion::Choice { name: "environment".into(), instructions: "Choose a target.".into(), choices: vec!["staging".into(), "production".into()] },
DecisionQuestion::Score { name: "confidence".into(), instructions: "Rate confidence.".into(), levels: vec!["low".into(), "medium".into(), "high".into()] },
]).await?;
println!("{:?}", result.answers);
client, _ := ish.NewClient()
defer client.Close()
decisions, _ := ish.NewDecisionsClient(client, nil)
result, err := decisions.Decide("Should we deploy?", []any{
map[string]any{"type":"predicate", "name":"safe", "instructions":"Is the build safe?"},
map[string]any{"type":"choice", "name":"environment", "instructions":"Choose a target.", "choices":[]string{"staging", "production"}},
map[string]any{"type":"score", "name":"confidence", "instructions":"Rate confidence.", "levels":[]string{"low", "medium", "high"}},
}, nil)
if err != nil { panic(err) }
fmt.Println(result["answers"])
using var ish = new IshClient();
var decisions = new DecisionsClient(ish);
using var questions = JsonDocument.Parse("""[{"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"]}]""");
var result = decisions.Decide("Should we deploy?", questions.RootElement);
Console.WriteLine(result.GetProperty("answers"));
try (var ish = new IshClient()) {
var decisions = new DecisionsClient(ish);
var questions = new ObjectMapper().readTree("""
[{"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"]}]
""");
var result = decisions.decide("Should we deploy?", questions);
System.out.println(result.path("answers"));
}