Skip to main content
LLM Config lets you set the model, API endpoint, and fallback chain so your agent always has a working model.
from praisonaiagents import Agent
from praisonaiagents.config import LLMConfig

agent = Agent(
    name="Assistant",
    instructions="You are a helpful assistant.",
    llm_config=LLMConfig(
        model="gpt-4o",
        fallback_models=["claude-3-5-sonnet-20241022", "gpt-4o-mini"],
    ),
)

result = agent.start("Explain quantum computing simply")
print(result)
The user sends a prompt; the agent tries the primary model and transparently falls back if the provider fails.

Quick Start

1

Primary Model Only

Set just the model to get started:
from praisonaiagents import Agent
from praisonaiagents.config import LLMConfig

agent = Agent(
    name="Assistant",
    instructions="You are a helpful assistant.",
    llm_config=LLMConfig(model="gpt-4o")
)

agent.start("What is the speed of light?")
2

With Fallback Chain

Add fallback models for reliability — if the primary fails, the agent automatically tries the next:
from praisonaiagents import Agent
from praisonaiagents.config import LLMConfig

agent = Agent(
    name="ResilientAssistant",
    instructions="You are a helpful assistant.",
    llm_config=LLMConfig(
        model="gpt-4o",
        fallback_models=["claude-3-5-sonnet-20241022", "gpt-4o-mini"],
    ),
)
agent.start("Summarize today's top AI research papers.")
3

With LiteLLM Provider Prefix

from praisonaiagents import Agent
from praisonaiagents.config import LLMConfig

agent = Agent(
    instructions="You are a helpful assistant.",
    llm_config=LLMConfig(
        model="anthropic/claude-3-5-sonnet-20241022",
        fallback_models=["openai/gpt-4o", "openai/gpt-4o-mini"],
    ),
)
agent.start("Write a technical blog post about microservices.")

How It Works

PhaseWhat happens
1. PrimaryAgent calls the configured model first
2. FallbackOn failure, tries each model in fallback_models in order
3. ResponseFirst successful response is returned

Configuration Options

LLMConfig SDK Reference

Full parameter reference for LLMConfig
OptionTypeDefaultDescription
modelstr(required)Primary model to use
fallback_modelslist[str] | NoneNoneOrdered fallback models
base_urlstr | NoneNoneAPI endpoint override
api_keystr | NoneNoneAPI key (defaults to env vars)
authdict | NoneNoneAdditional auth headers

Common Patterns

Pattern 1 — Self-hosted model via custom endpoint

from praisonaiagents import Agent
from praisonaiagents.config import LLMConfig

agent = Agent(
    instructions="You are a helpful assistant.",
    llm_config=LLMConfig(
        model="llama3.2",
        base_url="http://localhost:11434/v1",
        api_key="ollama",
    ),
)
response = agent.start("What is the capital of France?")
print(response)

Pattern 2 — Multi-provider fallback for resilience

from praisonaiagents import Agent
from praisonaiagents.config import LLMConfig

agent = Agent(
    name="PrivateModelAgent",
    instructions="You are a helpful assistant.",
    llm_config=LLMConfig(
        model="my-custom-model",
        base_url="https://my-llm-gateway.example.com/v1",
        api_key="sk-my-private-key",
        auth={"X-Organization-ID": "org-123"},
    )
)
Self-hosted model via Ollama:
from praisonaiagents import Agent
from praisonaiagents.config import LLMConfig

agent = Agent(
    name="LocalAgent",
    instructions="You are a helpful assistant.",
    llm_config=LLMConfig(
        model="ollama/llama3.2",
        base_url="http://localhost:11434",
    )
)

Pattern 3 — Multi-provider fallback for business continuity

from praisonaiagents import Agent
from praisonaiagents.config import LLMConfig

agent = Agent(
    name="ResilientAgent",
    instructions="You are a reliable assistant for critical tasks.",
    llm_config=LLMConfig(
        model="openai/gpt-4o",
        fallback_models=[
            "anthropic/claude-3-5-sonnet-20241022",
            "openai/gpt-4o-mini",
        ],
    ),
)
agent.start("Generate a business continuity plan for our e-commerce platform.")

Best Practices

Even one fallback prevents your agent from failing completely during rate limits or outages. Use a smaller, cheaper model as the fallback — it costs less and is often available when the primary isn’t.
Never hardcode api_key in your code. Leave it as None and set OPENAI_API_KEY, ANTHROPIC_API_KEY, etc. in your environment instead. LLMConfig picks them up automatically via LiteLLM.
Prefix models with the provider name (anthropic/, openai/, ollama/) to avoid ambiguity when using multiple providers in a fallback chain.
Deliberately trigger a failure (e.g., invalid primary model name) and verify your fallback fires correctly before going to production.

LLM Gateways

Route requests through a unified LLM gateway

LLM Endpoint Config

Fine-tune endpoint parameters per model

LLM Error Classification

How errors trigger fallback in the chain

Failover

Automatic failover strategies for reliability