Skip to main content

Overview

Switch models per-call without recreating the agent. Useful for cost optimization or capability matching.

Quick Start

from praisonaiagents import Agent

agent = Agent(
    name="FlexBot",
    instructions="Helper",
    llm={"model": "gpt-4o-mini", "configurable": True}
)

# Default model
response = agent.chat("Hello")

# Override model per-call
response = agent.chat("Complex task", config={"model": "gpt-4o"})

# Override temperature
response = agent.chat("Creative task", config={"temperature": 0.9})

Config Options

KeyDescription
modelOverride model name
temperatureOverride temperature
providerOverride provider (openai, anthropic)

Permanent Model Switching

Use switch_model() to permanently change the agent’s model while preserving conversation history:
from praisonaiagents import Agent

agent = Agent(
    name="FlexBot",
    instructions="Helper",
    llm="gpt-4o-mini"
)

# Chat with initial model
agent.chat("Hello")

# Permanently switch to a different model
agent.switch_model("gpt-4o")

# All subsequent calls use the new model
agent.chat("Complex task")  # Uses gpt-4o

# Conversation history is preserved
print(len(agent._chat_history))  # Shows previous messages

Thread Safety

Config overrides are per-call and do not mutate agent defaults. Safe for concurrent use.