Agent Model Resolution
How Agent() picks and routes an LLM when you omit llm= — from your environment
Agent() picks a model from your environment when you don’t pass llm=, then routes provider-prefixed defaults through litellm so a single provider key is enough to start.
As of PR #4795, the SDK Agent() constructor uses the same resolver as praisonai run — set one provider key and the Agent works with no llm=.
Quick Start
- Simplest — one provider key
Set a single provider credential and construct an Agent with no
llm=:python import os from praisonaiagents import Agent os.environ["OLLAMA_HOST"] = "http://localhost:11434" # No llm=, no OPENAI_API_KEY — the Agent picks ollama/llama3.2 # and routes through litellm. agent = Agent(instructions="Answer briefly.") agent.start("2+2") - Explicit provider-prefixed
Pass a
provider/modelstring to route through litellm:python from praisonaiagents import Agent agent = Agent(llm="anthropic/claude-3-5-sonnet-latest") agent.start("Write a haiku about the sea.") - Bare OpenAI model
A bare model name uses the native OpenAI client:
python from praisonaiagents import Agent agent = Agent(llm="gpt-4o") agent.start("Summarise the plot of Hamlet.")
How It Works
The Agent scans your environment for a credential when llm= is omitted, then forks on whether the resolved model carries a provider/ prefix.
The first provider whose credential is present wins, in the order below. OpenAI is first so existing OpenAI users keep their default. The actual id is the capability-ranked best-available model for that provider at run time; the models below are shown as representatives — check praisonai models list --provider <p> for the current pick.
| Credential env var | Default model class (ranked best-available at run time; prefix preserved) |
|---|---|
OPENAI_API_KEY | best OpenAI chat model (e.g. gpt-4o) |
ANTHROPIC_API_KEY | anthropic/<best> (e.g. anthropic/claude-3-5-sonnet-latest) |
GEMINI_API_KEY | gemini/<best> (e.g. gemini/gemini-1.5-pro) |
GOOGLE_API_KEY | google/<best> (e.g. google/gemini-1.5-pro) |
GROQ_API_KEY | groq/<best> (e.g. groq/llama-3.3-70b-versatile) |
COHERE_API_KEY | cohere/<best> (e.g. cohere/command-r) |
OLLAMA_HOST | ollama/<best> (e.g. ollama/llama3.2) |
Resolution Table
The class an Agent uses depends on the shape of the resolved model — a provider/ prefix routes through litellm, a bare name uses the native OpenAI client.
llm= | Environment | Resolved model | Routed through |
|---|---|---|---|
| omitted | OPENAI_API_KEY only | ranked best OpenAI chat model | Native OpenAI client |
| omitted | OLLAMA_HOST only | ollama/<best> | litellm (100+ providers) |
| omitted | ANTHROPIC_API_KEY only | anthropic/<best> | litellm (100+ providers) |
"gpt-4o" | any | gpt-4o | Native OpenAI client |
"anthropic/claude-3-5-sonnet-latest" | any | as given | litellm (100+ providers) |
{"temperature": 0.5} (no model key) | any | default | Native OpenAI client |
Before PR #4795, six of the seven env-var defaults resolved the right model name but were then sent to the native OpenAI client — the Agent raised ValueError: OPENAI_API_KEY environment variable is required. Only the bare OpenAI default worked. The fix routes any provider-prefixed default through litellm, matching praisonai run.
Common Patterns
I only have a Groq key
import os
from praisonaiagents import Agent
os.environ["GROQ_API_KEY"] = "gsk-..."
# Picks groq/llama-3.3-70b-versatile, routed through litellm.
agent = Agent(instructions="Answer fast.")
agent.start("Name three prime numbers.")I have an Ollama server running
import os
from praisonaiagents import Agent
os.environ["OLLAMA_HOST"] = "http://localhost:11434"
# Picks ollama/llama3.2, routed through litellm — no cloud key needed.
agent = Agent(instructions="Answer locally.")
agent.start("Explain black holes to a 5-year-old.")Best Practices
Prefer explicit llm= in production
Auto-detection is ideal for a first run. In production, pass llm="provider/model" so the model can’t change when you add or remove a provider key.
Keep OPENAI_MODEL_NAME bare unless you mean the override
OPENAI_MODEL_NAME wins over credential detection. A bare value like gpt-4o uses the OpenAI client; a provider/model value like ollama/llama3.2 now routes through litellm instead.
The SDK reads the same env vars as praisonai run
Agent() and praisonai run share one resolver. A single provider key gives a working Agent in Python and a working command on the CLI.