How to Implement AI Agents with Multi-Provider LLM Support in FinceptTerminal

FinceptTerminal provides a plug-and-play architecture that lets you implement AI agents with multi-provider LLM support using a centralized registry and dynamic factory pattern, allowing seamless switching between OpenAI, Anthropic, and 40+ other providers without modifying agent code.

FinceptTerminal is an open-source financial terminal that implements AI agents with multi-provider LLM support through a sophisticated three-layer architecture. This design allows developers to switch between OpenAI's GPT models, Anthropic's Claude, and dozens of other LLM providers by simply updating a configuration setting, without touching the underlying agent implementation.

Architecture Overview

The multi-provider implementation consists of three distinct layers that separate configuration from execution:

Layer Responsibility Key Implementation
Provider Registry Central catalog of every supported provider, their Python class, default model, and required environment variable for API keys ModelsRegistry
Dynamic Model Factory Reads active LLM configuration from the frontend SQLite database and lazily creates concrete model instances with automatic fallback to OpenAI-compatible interfaces ModelFactory
Agent Builder Supplies a thin wrapper that agents call to obtain their language model, hiding all provider-specific details and allowing agents to be written once and reused with any provider create_model_from_config

This architecture ensures that agents remain provider-agnostic while the system handles the complexity of different API clients and authentication mechanisms.

The Provider Registry

The ModelsRegistry class serves as the single source of truth for all supported LLM providers. It maintains a comprehensive catalog that maps provider names to their implementation classes, available models, and required environment variables.

ModelsRegistry Implementation

Located in fincept-qt/scripts/agents/finagent_core/registries/models_registry.py, the registry defines entries for both OpenAI and Anthropic:

class ModelsRegistry:
    MODEL_CATALOG = {
        "openai": {
            "class": "agno.models.openai.OpenAIChat",
            "models": ["gpt-4o", "gpt-4-turbo", "gpt-3.5-turbo", "o1"],
            "api_key_env": "OPENAI_API_KEY",
            "default_model": "gpt-4o-mini",
        },
        "anthropic": {
            "class": "agno.models.anthropic.Claude",
            "models": [
                "claude-sonnet-4-5-20250514",
                "claude-opus-4-5",
                "claude-3-5-sonnet-20241022",
                "claude-3-haiku-20240307",
            ],
            "api_key_env": "ANTHROPIC_API_KEY",
            "default_model": "claude-sonnet-4-5-20250514",
        },
        # … 38 additional providers …

    }

Adding a new provider requires only inserting a new dictionary entry with the class path, model IDs, and API key environment variable name.

The Dynamic Model Factory

The ModelFactory class handles the runtime instantiation of LLM clients based on the active configuration stored in the frontend SQLite database (frontend.db).

Provider-Specific Creation Logic

The factory's _create_model method in fincept-qt/scripts/agents/hedgeFundAgents/renaissance_technologies_hedge_fund_agent/utils/model_factory.py contains explicit branching for major providers:

def _create_model(self, config: ModelConfig):
    provider = config.provider.lower()

    if provider == "openai":
        return self._create_openai_model(config)
    elif provider == "anthropic":
        return self._create_anthropic_model(config)
    elif provider in ["google", "gemini"]:
        return self._create_google_model(config)
    elif provider == "groq":
        return self._create_groq_model(config)
    elif provider == "ollama":
        return self._create_ollama_model(config)
    else:
        # OpenAI-compatible fallback for custom endpoints

        logger.info(f"Using OpenAI-compatible interface for provider: {provider}")
        return self._create_openai_like_model(config)

When the provider is "anthropic", the factory creates an instance of agno.models.anthropic.Claude using the model ID and API key specified in the configuration.

Fallback Mechanisms

The factory implements a robust fallback strategy for providers that expose OpenAI-compatible endpoints. If a specific provider SDK cannot be imported or is not explicitly handled, the code automatically falls back to an OpenAILike client that works with any /v1/chat/completions compatible endpoint. This ensures that Anthropic, OpenAI, or custom API endpoints can be swapped without breaking agent execution.

The factory also caches database queries to avoid repeated lookups when multiple agents request models in quick succession.

Agent-Level Integration

Agents remain completely agnostic to the underlying LLM provider by using the create_model_from_config convenience wrapper.

The create_model_from_config Wrapper

Located in fincept-qt/scripts/agents/hedgeFundAgents/renaissance_technologies_hedge_fund_agent/utils/model_factory.py (lines 60-84), this helper function eliminates boilerplate:

def create_model_from_config(config_dict: Optional[Dict[str, Any]] = None):
    factory = get_model_factory()
    return factory.create_model(config_dict)

All agent implementations, such as those in base_agent.py, retrieve their model using this single entry point:

model = create_model_from_config({
    "temperature": cfg.models.temperature,
    "max_tokens": cfg.models.max_tokens,
})

Because this helper hides all provider-specific instantiation logic, the same agent code works seamlessly with OpenAI, Anthropic, or any other provider configured in the database.

Practical Implementation Examples

Switching to Anthropic via UI Configuration

To implement AI agents with Anthropic Claude support without modifying code:

  1. Update the frontend.db SQLite database (or use the Fincept Terminal UI) to set the active configuration:
Column Value
provider anthropic
model_id claude-3-5-sonnet-20241022
api_key your-anthropic-api-key
temperature 0.6
max_tokens 4096
  1. Ensure the ANTHROPIC_API_KEY environment variable is set as a fallback.

  2. Run the agent. The factory automatically instantiates agno.models.anthropic.Claude based on the configuration.

Programmatic Provider Override

For testing or specific use cases, override the provider programmatically:

from fincept.qt.scripts.agents.hedgeFundAgents.renaissance_technologies_hedge_fund_agent.utils.model_factory import create_model_from_config

# Force Anthropic Claude for a single execution

model = create_model_from_config({
    "provider": "anthropic",
    "model_id": "claude-3-opus-20240229",
    "api_key": "sk-ant-...",
    "temperature": 0.4,
    "max_tokens": 2000,
})

This bypasses the database configuration for that specific model instance while maintaining the same interface.

Creating a Multi-Provider Capable Agent

When building new agents, inherit from the base classes to automatically gain multi-provider support:

from fincept.qt.scripts.agents.hedgeFundAgents.renaissance_technologies_hedge_fund_agent.base import AgentFactory, get_agent_factory

# Obtain the global factory

factory = get_agent_factory()

# Create an agent instance

my_agent = factory.get_or_create(persona=my_persona)

# Execute - works with any configured provider

response = my_agent.run("Analyze the impact of inflation on equity markets.")
print(response)

The AgentFactory internally calls create_model_from_config, ensuring the agent works with OpenAI, Anthropic, or any provider listed in the ModelsRegistry.

Summary

FinceptTerminal's multi-provider architecture enables you to implement AI agents with multi-provider LLM support through three core components:

This design allows you to switch between OpenAI and Anthropic models by updating the frontend.db configuration or passing a dictionary override, without requiring any changes to your agent implementation code.

Frequently Asked Questions

How do I add a new LLM provider to FinceptTerminal?

Adding a new provider requires updating the MODEL_CATALOG dictionary in fincept-qt/scripts/agents/finagent_core/registries/models_registry.py. You must specify the provider key, the full Python class path (e.g., agno.models.openai.OpenAIChat), available model IDs, the default model, and the environment variable name for the API key. If the provider uses an OpenAI-compatible endpoint, no additional factory code is needed as the system will automatically fall back to the OpenAILike client.

Can I use different providers for different agents simultaneously?

Yes. While the system maintains a default configuration in the SQLite frontend.db, you can override the provider on a per-agent basis by passing a config_dict to create_model_from_config. For example, you can instantiate one agent with OpenAI GPT-4 and another with Anthropic Claude in the same application session by specifying different "provider" and "model_id" values in their respective configuration dictionaries.

What happens if the Anthropic API key is missing?

If the ANTHROPIC_API_KEY environment variable is not set and no API key is provided in the configuration dictionary, the ModelFactory will attempt to instantiate the Anthropic client without authentication. This will raise an authentication error when the agent attempts to generate a response. The system does not automatically fall back to a different provider; you must either set the environment variable, update the database configuration to use a different provider, or pass a valid API key in the override dictionary.

How does the system handle provider-specific parameters like temperature?

The create_model_from_config function accepts standard parameters including temperature, max_tokens, top_p, and timeout in the configuration dictionary. These parameters are passed directly to the underlying provider client during instantiation. While different providers may have slightly different parameter names or valid ranges, the factory normalizes these through the Agno framework's unified interface, ensuring that agents can specify these values once and have them translated appropriately for whichever provider is active.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →