DEV Community

Arpan Dhara
Arpan Dhara

Posted on

Integrating AgentRouter with Tauric Research TradingAgents

If you're using Tauric Research's TradingAgents framework and want to add AgentRouter as a fully supported LLM provider, this guide will walk you through the complete integration.

The process is organized file-by-file, so you can open each file and make all of the required changes before moving to the next one.

TradingAgents Repository:
[https://github.com/TauricResearch/TradingAgents.git]


What We'll Do

In this tutorial, we'll:

  1. Register the AgentRouter API endpoint
  2. Configure the AgentRouter WAF-bypass headers
  3. Add AgentRouter's model catalog
  4. Configure the AgentRouter API key environment variable
  5. Bypass strict model-name validation
  6. Add AgentRouter to the TradingAgents CLI
  7. Configure the .env file
  8. Reinstall and restart TradingAgents

Let's get started.


Step 1 — Update openai_client.py

Open:

tradingagents/llm_clients/openai_client.py
Enter fullscreen mode Exit fullscreen mode

This file requires two changes:

  • Register the AgentRouter API endpoint
  • Configure the headers required by AgentRouter

The integration guide specifically places both changes in this file.


1A — Register the AgentRouter API Endpoint

Locate the:

OPENAI_COMPATIBLE_PROVIDERS
Enter fullscreen mode Exit fullscreen mode

dictionary.

Add AgentRouter alongside the existing OpenAI-compatible providers:

"openrouter": ProviderSpec(
    base_url="https://openrouter.ai/api/v1"
),
"agentrouter": ProviderSpec(
    base_url="https://agentrouter.org/v1"
),
Enter fullscreen mode Exit fullscreen mode

The important part here is the AgentRouter base URL:

https://agentrouter.org/v1
Enter fullscreen mode Exit fullscreen mode

This allows TradingAgents to communicate with AgentRouter through its OpenAI-compatible API interface.


1B — Configure AgentRouter WAF-Bypass Headers

Still in:

tradingagents/llm_clients/openai_client.py
Enter fullscreen mode Exit fullscreen mode

Locate the get_llm(self) method inside the OpenAIClient class.

Find the section that forwards user-provided keyword arguments:

# Forward user-provided kwargs
for key in _PASSTHROUGH_KWARGS:
    if key not in self.kwargs:
        continue
    if key == "reasoning_effort" and not _supports_reasoning_effort(self.model):
        continue
    llm_kwargs[key] = self.kwargs[key]
Enter fullscreen mode Exit fullscreen mode

Immediately after this section, add the AgentRouter-specific headers:

# Forward user-provided kwargs
for key in _PASSTHROUGH_KWARGS:
    if key not in self.kwargs:
        continue
    if key == "reasoning_effort" and not _supports_reasoning_effort(self.model):
        continue
    llm_kwargs[key] = self.kwargs[key]

# --- NEW CODE START: Add spoofed headers for AgentRouter ---
if self.provider == "agentrouter":
    llm_kwargs["default_headers"] = {
        "Originator": "codex_cli_rs",
        "User-Agent": "codex_cli_rs/0.114.0 (Windows 10.0.26100; x86_64)",
        "Version": "0.114.0",
    }

# --- NEW CODE END ---

# The subclass (provider quirks) comes from the registry spec.
return chat_cls(**llm_kwargs)
Enter fullscreen mode Exit fullscreen mode

These headers are part of the AgentRouter integration described in the guide.

Important: Make sure this code is placed inside the get_llm(self) method and before the final return chat_cls(**llm_kwargs).


Step 2 — Update model_catalog.py

Now open:

tradingagents/llm_clients/model_catalog.py
Enter fullscreen mode Exit fullscreen mode

This file controls the models that can be selected for each provider.


2A — Define AgentRouter Models

Near the top of the file, around the existing model definitions, add:

_AGENTROUTER_MODELS: dict[str, list[ModelOption]] = {
    "quick": [
        ("GPT-4o Mini", "openai/gpt-4o-mini"),
        ("Claude 3.5 Haiku", "anthropic/claude-3-haiku"),
        ("DeepSeek V3", "deepseek/deepseek-chat"),
        ("Custom model ID", "custom"),
    ],
    "deep": [
        ("GPT-4o", "openai/gpt-4o"),
        ("Claude 3.5 Sonnet", "anthropic/claude-3-5-sonnet"),
        ("DeepSeek R1", "deepseek/deepseek-reasoner"),
        ("Custom model ID", "custom"),
    ],
}
Enter fullscreen mode Exit fullscreen mode

The quick category contains lighter model choices, while deep contains the deeper/reasoning-oriented choices listed in the integration guide.


2B — Register the AgentRouter Model Catalog

Scroll down to:

MODEL_OPTIONS
Enter fullscreen mode Exit fullscreen mode

Add the AgentRouter mapping:

"bedrock": _CUSTOM_ONLY,
"agentrouter": _AGENTROUTER_MODELS,
Enter fullscreen mode Exit fullscreen mode

This connects the agentrouter provider with the model catalog you just created.


Step 3 — Update api_key_env.py

Open:

tradingagents/llm_clients/api_key_env.py
Enter fullscreen mode Exit fullscreen mode

Locate:

PROVIDER_API_KEY_ENV
Enter fullscreen mode Exit fullscreen mode

Add the AgentRouter environment variable:

"openrouter": "OPENROUTER_API_KEY",
"agentrouter": "AGENTROUTER_API_KEY",
Enter fullscreen mode Exit fullscreen mode

This tells TradingAgents to retrieve the AgentRouter API key from:

AGENTROUTER_API_KEY
Enter fullscreen mode Exit fullscreen mode

The integration guide specifies this exact provider-to-environment-variable mapping.


Step 4 — Update validators.py

Open:

tradingagents/llm_clients/validators.py
Enter fullscreen mode Exit fullscreen mode

TradingAgents normally performs strict validation of model names.

For AgentRouter, add the provider to:

_ANY_MODEL_PROVIDERS
Enter fullscreen mode Exit fullscreen mode

The resulting tuple should include agentrouter:

_ANY_MODEL_PROVIDERS = (
    "ollama",
    "openrouter",
    "openai_compatible",
    "mistral",
    "kimi",
    "groq",
    "nvidia",
    "bedrock",
    "agentrouter",
)
Enter fullscreen mode Exit fullscreen mode

This allows AgentRouter to work with model IDs without being restricted by the strict model-name validation.


Step 5 — Update cli/utils.py

Now open:

cli/utils.py
Enter fullscreen mode Exit fullscreen mode

Locate:

_llm_provider_table()
Enter fullscreen mode Exit fullscreen mode

This function contains the providers displayed in the interactive TradingAgents CLI.

Find the OpenRouter entry and add AgentRouter immediately after it:

("OpenRouter", "openrouter", "https://openrouter.ai/api/v1"),
("AgentRouter", "agentrouter", "https://agentrouter.org/v1"),
Enter fullscreen mode Exit fullscreen mode

After this change, AgentRouter should appear as a selectable provider when you launch the TradingAgents CLI.


Step 6 — Configure the .env File

Now open the .env file in the root directory of your TradingAgents project.

Add your AgentRouter API key:

AGENTROUTER_API_KEY=your_actual_agentrouter_key_here
Enter fullscreen mode Exit fullscreen mode

Replace:

your_actual_agentrouter_key_here
Enter fullscreen mode Exit fullscreen mode

with your actual AgentRouter API key.

Keep Your API Key Private

Do not commit your .env file or API key to GitHub.

Make sure your .gitignore contains:

.env
Enter fullscreen mode Exit fullscreen mode

Step 7 — Reinstall and Restart TradingAgents

Once you've completed all of the modifications, save your files.

Open your VS Code terminal and run:

pip install -e .
Enter fullscreen mode Exit fullscreen mode

This reinstalls the package in editable mode so the modified Python definitions are refreshed.

Then launch TradingAgents:

TradingAgents
Enter fullscreen mode Exit fullscreen mode

The integration guide specifically recommends restarting the CLI session after making the code changes so Python loads the modified code from disk.


Complete File Checklist

At this point, you should have modified the following files:

tradingagents/
├── llm_clients/
│   ├── openai_client.py
│   ├── model_catalog.py
│   ├── api_key_env.py
│   └── validators.py
│
└── cli/
    └── utils.py

.env
Enter fullscreen mode Exit fullscreen mode

Here's a quick summary of what changes in each file:

openai_client.py
    ├── AgentRouter API endpoint
    └── AgentRouter WAF-bypass headers

model_catalog.py
    └── AgentRouter model definitions

api_key_env.py
    └── AGENTROUTER_API_KEY mapping

validators.py
    └── AgentRouter model validation bypass

cli/utils.py
    └── AgentRouter CLI provider entry

.env
    └── Your AgentRouter API key
Enter fullscreen mode Exit fullscreen mode

Quick Verification Checklist

Before launching TradingAgents, verify that you have completed every step:

  • [ ] Added the AgentRouter API endpoint
  • [ ] Added the AgentRouter headers inside get_llm()
  • [ ] Added _AGENTROUTER_MODELS
  • [ ] Added "agentrouter" to MODEL_OPTIONS
  • [ ] Added AGENTROUTER_API_KEY to PROVIDER_API_KEY_ENV
  • [ ] Added "agentrouter" to _ANY_MODEL_PROVIDERS
  • [ ] Added AgentRouter to the CLI provider table
  • [ ] Added your AgentRouter API key to .env
  • [ ] Ran pip install -e .
  • [ ] Restarted the TradingAgents CLI

Conclusion

That's it!

AgentRouter is now registered as a provider in the TradingAgents framework, with:

  • OpenAI-compatible API support
  • AgentRouter-specific headers
  • Predefined model selections
  • Custom model support
  • Environment-based API key configuration
  • CLI provider selection

You can now launch TradingAgents and select AgentRouter from the interactive provider menu.

TradingAgents Repository:
[YOUR_TRADINGAGENTS_REPOSITORY_LINK]

If you're integrating another OpenAI-compatible provider into TradingAgents, the same general architecture can be useful: provider registration, model catalog configuration, API-key mapping, validation rules, and CLI registration.


Final Integration Flow

AgentRouter
     │
     ▼
API Endpoint Registration
     │
     ▼
OpenAIClient
     │
     ├── AgentRouter Headers
     │
     ▼
Model Catalog
     │
     ▼
API Key Environment Variable
     │
     ▼
Model Validation
     │
     ▼
TradingAgents CLI
     │
     ▼
AgentRouter LLM
Enter fullscreen mode Exit fullscreen mode

Happy trading! 🚀

Top comments (0)