Implement configurable API providers from configs.yaml #43

Merged
Copilot merged 8 commits from copilot/update-api-providers-configs into main 2025-10-27 18:53:36 +01:00
Copilot commented 2025-10-22 15:57:21 +02:00 (Migrated from github.com)

Overview

This PR implements a flexible configuration system for API providers, allowing users to select which providers to use for market, news, and social data directly from configs.yaml. This resolves the issue where warnings were shown for all providers regardless of whether users had API keys for them.

Problem

Previously, all API wrappers were hardcoded in the tools, which meant:

  • All providers were initialized regardless of availability
  • Users saw warnings for providers they didn't have API keys for
  • No way to customize which providers to use or their priority order
  • Retry settings were hardcoded per tool
  • Filtering logic was duplicated across all three tools

Solution

1. Configuration File (configs.yaml)

Added all available wrappers to the provider configuration lists with free APIs prioritized:

api:
  retry_attempts: 3
  retry_delay_seconds: 2
  market_providers: [YFinanceWrapper, BinanceWrapper, CoinBaseWrapper, CryptoCompareWrapper]
  news_providers: [DuckDuckGoWrapper, GoogleNewsWrapper, NewsApiWrapper, CryptoPanicWrapper]
  social_providers: [RedditWrapper, XWrapper, ChanWrapper]

2. Configuration Class (src/app/configs.py)

Extended APIConfig with three new fields to store provider lists:

  • market_providers: list[str]
  • news_providers: list[str]
  • social_providers: list[str]

3. Centralized Filtering Logic (src/app/api/wrapper_handler.py)

Added WrapperHandler.filter_wrappers_by_config() static method to eliminate code duplication:

  • Filters wrapper classes based on configuration
  • Maintains configured provider order
  • Supports optional fallback wrappers
  • Single reusable function used by all tools

4. API Tools

Updated all three tools (market_tool.py, news_tool.py, social_tool.py) to:

  • Load configuration from the AppConfig singleton
  • Use centralized WrapperHandler.filter_wrappers_by_config() for filtering
  • Initialize only the configured providers in the specified order
  • Pass retry settings from configuration to WrapperHandler

Benefits

🎯 Selective Initialization: Only providers listed in configs.yaml are initialized, eliminating unnecessary warnings.

📋 Configurable Priority: Users can control the order providers are tried:

# Try free API first, then paid ones
market_providers: [YFinanceWrapper, BinanceWrapper]

⚙️ Unified Retry Settings: retry_attempts and retry_delay_seconds now apply globally to all tools.

🔄 Backward Compatible: Includes default values and fallback behavior to ensure existing setups continue working.

♻️ DRY Principle: Centralized filtering logic eliminates code duplication and improves maintainability.

Usage Examples

Minimal setup (only free APIs):

api:
  market_providers: [YFinanceWrapper]
  news_providers: [GoogleNewsWrapper, DuckDuckGoWrapper]
  social_providers: [RedditWrapper]

Custom priority (prefer specific sources):

api:
  retry_attempts: 5
  market_providers: [BinanceWrapper, CoinBaseWrapper]
  news_providers: [CryptoPanicWrapper, GoogleNewsWrapper]
  social_providers: [XWrapper, RedditWrapper]

Technical Details

  • AppConfig uses the singleton pattern, ensuring all tools share the same configuration
  • Each tool maintains a _WRAPPER_MAP dictionary for string-to-class mapping
  • WrapperHandler.filter_wrappers_by_config() provides centralized, reusable filtering logic
  • WrapperHandler.build_wrappers() handles initialization errors gracefully
  • Warnings now only appear for configured providers that fail to initialize

Testing

  • Configuration structure validated
  • All wrapper names verified between config and code
  • Python syntax validated for all modified files
  • All available wrappers present in configs.yaml
  • Filter function tested with multiple scenarios
  • Free APIs prioritized in default configuration

Fixes Berack96/upo-appAI#30

Original prompt

This section details on the original issue you should resolve

<issue_title>API Providers da Configs</issue_title>
<issue_description>Mettere la possibilità di scegliere quali providers devono essere utilizzati dalle api e in quale orfdine.
Nel file configs.yaml c'è una sezione con i provider che per ora non fa nulla di particolare.
Sarebbe bello aggiungere la possibilità di modificare i providers in modo che non vengano mostrati i warning di quelli che non si hanno le chiavi.

Checklist

  • Modificare il file configs.yaml in modo che abbia correttamente TUTTI i wrappers all'interno delle liste market_providers, news_providers, social_providers.
  • Modificare eventualmente la classe APIConfig in src/app/configs.py in modo che abbia le corrette variabili per caricare i dati
  • Modificare i tools in src/app/api/tools/ in modo che accettino in input le configurazioni passate e scelgano solo i wrapper opportuni (si può anche scegliere di non passare le config, ma di prenderle inizializzando AppConfig() direttamente, dato che è una classe Singleton; ma a sto punto si può anche passare le config per quanto riguarda anche i retry)
    </issue_description>

<agent_instructions>Mettere la possibilità di scegliere quali providers devono essere utilizzati dalle api e in quale orfdine.
Nel file configs.yaml c'è una sezione con i provider che per ora non fa nulla di particolare.
Sarebbe bello aggiungere la possibilità di modificare i providers in modo che non vengano mostrati i warning di quelli che non si hanno le chiavi.

Checklist

  • Modificare il file configs.yaml in modo che abbia correttamente TUTTI i wrappers all'interno delle liste market_providers, news_providers, social_providers.
  • Modificare eventualmente la classe APIConfig in src/app/configs.py in modo che abbia le corrette variabili per caricare i dati
  • Modificare i tools in src/app/api/tools/ in modo che accettino in input le configurazioni passate e scelgano solo i wrapper opportuni (si può anche scegliere di non passare le config, ma di prenderle inizializzando AppConfig() direttamente, dato che è una classe Singleton; ma a sto punto si può anche passare le config per quanto riguarda anche i retry)
    </agent_instructions>

Comments on the Issue (you are @copilot in this section)

Fixes Berack96/upo-appAI#30


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

## Overview This PR implements a flexible configuration system for API providers, allowing users to select which providers to use for market, news, and social data directly from `configs.yaml`. This resolves the issue where warnings were shown for all providers regardless of whether users had API keys for them. ## Problem Previously, all API wrappers were hardcoded in the tools, which meant: - All providers were initialized regardless of availability - Users saw warnings for providers they didn't have API keys for - No way to customize which providers to use or their priority order - Retry settings were hardcoded per tool - Filtering logic was duplicated across all three tools ## Solution ### 1. Configuration File (`configs.yaml`) Added all available wrappers to the provider configuration lists with free APIs prioritized: ```yaml api: retry_attempts: 3 retry_delay_seconds: 2 market_providers: [YFinanceWrapper, BinanceWrapper, CoinBaseWrapper, CryptoCompareWrapper] news_providers: [DuckDuckGoWrapper, GoogleNewsWrapper, NewsApiWrapper, CryptoPanicWrapper] social_providers: [RedditWrapper, XWrapper, ChanWrapper] ``` ### 2. Configuration Class (`src/app/configs.py`) Extended `APIConfig` with three new fields to store provider lists: - `market_providers: list[str]` - `news_providers: list[str]` - `social_providers: list[str]` ### 3. Centralized Filtering Logic (`src/app/api/wrapper_handler.py`) Added `WrapperHandler.filter_wrappers_by_config()` static method to eliminate code duplication: - Filters wrapper classes based on configuration - Maintains configured provider order - Supports optional fallback wrappers - Single reusable function used by all tools ### 4. API Tools Updated all three tools (`market_tool.py`, `news_tool.py`, `social_tool.py`) to: - Load configuration from the `AppConfig` singleton - Use centralized `WrapperHandler.filter_wrappers_by_config()` for filtering - Initialize only the configured providers in the specified order - Pass retry settings from configuration to `WrapperHandler` ## Benefits **🎯 Selective Initialization**: Only providers listed in `configs.yaml` are initialized, eliminating unnecessary warnings. **📋 Configurable Priority**: Users can control the order providers are tried: ```yaml # Try free API first, then paid ones market_providers: [YFinanceWrapper, BinanceWrapper] ``` **⚙️ Unified Retry Settings**: `retry_attempts` and `retry_delay_seconds` now apply globally to all tools. **🔄 Backward Compatible**: Includes default values and fallback behavior to ensure existing setups continue working. **♻️ DRY Principle**: Centralized filtering logic eliminates code duplication and improves maintainability. ## Usage Examples **Minimal setup (only free APIs):** ```yaml api: market_providers: [YFinanceWrapper] news_providers: [GoogleNewsWrapper, DuckDuckGoWrapper] social_providers: [RedditWrapper] ``` **Custom priority (prefer specific sources):** ```yaml api: retry_attempts: 5 market_providers: [BinanceWrapper, CoinBaseWrapper] news_providers: [CryptoPanicWrapper, GoogleNewsWrapper] social_providers: [XWrapper, RedditWrapper] ``` ## Technical Details - `AppConfig` uses the singleton pattern, ensuring all tools share the same configuration - Each tool maintains a `_WRAPPER_MAP` dictionary for string-to-class mapping - `WrapperHandler.filter_wrappers_by_config()` provides centralized, reusable filtering logic - `WrapperHandler.build_wrappers()` handles initialization errors gracefully - Warnings now only appear for configured providers that fail to initialize ## Testing - ✅ Configuration structure validated - ✅ All wrapper names verified between config and code - ✅ Python syntax validated for all modified files - ✅ All available wrappers present in `configs.yaml` - ✅ Filter function tested with multiple scenarios - ✅ Free APIs prioritized in default configuration Fixes Berack96/upo-appAI#30 <!-- START COPILOT CODING AGENT SUFFIX --> <details> <summary>Original prompt</summary> > > ---- > > *This section details on the original issue you should resolve* > > <issue_title>API Providers da Configs</issue_title> > <issue_description>Mettere la possibilità di scegliere quali providers devono essere utilizzati dalle api e in quale orfdine. > Nel file [configs.yaml](https://github.com/Berack96/upo-appAI/tree/main/configs.yaml) c'è una sezione con i provider che per ora non fa nulla di particolare. > Sarebbe bello aggiungere la possibilità di modificare i providers in modo che non vengano mostrati i warning di quelli che non si hanno le chiavi. > > ## Checklist > - [ ] Modificare il file [configs.yaml](https://github.com/Berack96/upo-appAI/tree/main/configs.yaml) in modo che abbia correttamente TUTTI i wrappers all'interno delle liste `market_providers`, `news_providers`, `social_providers`. > - [ ] Modificare eventualmente la classe APIConfig in [src/app/configs.py](https://github.com/Berack96/upo-appAI/tree/main/src/app/configs.py) in modo che abbia le corrette variabili per caricare i dati > - [ ] Modificare i tools in [src/app/api/tools/](https://github.com/Berack96/upo-appAI/tree/main/src/app/api/tools/) in modo che accettino in input le configurazioni passate e scelgano solo i wrapper opportuni (si può anche scegliere di non passare le config, ma di prenderle inizializzando AppConfig() direttamente, dato che è una classe Singleton; ma a sto punto si può anche passare le config per quanto riguarda anche i retry) > </issue_description> > > <agent_instructions>Mettere la possibilità di scegliere quali providers devono essere utilizzati dalle api e in quale orfdine. > Nel file [configs.yaml](https://github.com/Berack96/upo-appAI/tree/main/configs.yaml) c'è una sezione con i provider che per ora non fa nulla di particolare. > Sarebbe bello aggiungere la possibilità di modificare i providers in modo che non vengano mostrati i warning di quelli che non si hanno le chiavi. > > ## Checklist > - [ ] Modificare il file [configs.yaml](https://github.com/Berack96/upo-appAI/tree/main/configs.yaml) in modo che abbia correttamente TUTTI i wrappers all'interno delle liste `market_providers`, `news_providers`, `social_providers`. > - [ ] Modificare eventualmente la classe APIConfig in [src/app/configs.py](https://github.com/Berack96/upo-appAI/tree/main/src/app/configs.py) in modo che abbia le corrette variabili per caricare i dati > - [ ] Modificare i tools in [src/app/api/tools/](https://github.com/Berack96/upo-appAI/tree/main/src/app/api/tools/) in modo che accettino in input le configurazioni passate e scelgano solo i wrapper opportuni (si può anche scegliere di non passare le config, ma di prenderle inizializzando AppConfig() direttamente, dato che è una classe Singleton; ma a sto punto si può anche passare le config per quanto riguarda anche i retry) > </agent_instructions> > > ## Comments on the Issue (you are @copilot in this section) > > <comments> > </comments> > </details> Fixes Berack96/upo-appAI#30 <!-- START COPILOT CODING AGENT TIPS --> --- 💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more [Copilot coding agent tips](https://gh.io/copilot-coding-agent-tips) in the docs.
trojanhorse47 (Migrated from github.com) reviewed 2025-10-22 15:57:21 +02:00
Berack96 (Migrated from github.com) requested changes 2025-10-22 16:43:21 +02:00
@@ -32,10 +32,9 @@ models:
api:
Berack96 (Migrated from github.com) commented 2025-10-22 16:42:20 +02:00

Metti yFinance per primo

Metti yFinance per primo
Berack96 (Migrated from github.com) commented 2025-10-22 16:42:38 +02:00

Metti DuckDuckGo per primo

Metti DuckDuckGo per primo
Berack96 (Migrated from github.com) commented 2025-10-22 16:41:34 +02:00

Invece che fare una triplice modifica, una per ogni tool, aggiungi una funzione nel wrapper (o modifica quella esistente per la sua creazione) per fare in modo di filtrare eventuali wrappers.

Invece che fare una triplice modifica, una per ogni tool, aggiungi una funzione nel wrapper (o modifica quella esistente per la sua creazione) per fare in modo di filtrare eventuali wrappers.
Berack96 (Migrated from github.com) commented 2025-10-22 16:41:43 +02:00

Invece che fare una triplice modifica, una per ogni tool, aggiungi una funzione nel wrapper (o modifica quella esistente per la sua creazione) per fare in modo di filtrare eventuali wrappers.

Invece che fare una triplice modifica, una per ogni tool, aggiungi una funzione nel wrapper (o modifica quella esistente per la sua creazione) per fare in modo di filtrare eventuali wrappers.
Berack96 (Migrated from github.com) commented 2025-10-22 16:41:47 +02:00

Invece che fare una triplice modifica, una per ogni tool, aggiungi una funzione nel wrapper (o modifica quella esistente per la sua creazione) per fare in modo di filtrare eventuali wrappers.

Invece che fare una triplice modifica, una per ogni tool, aggiungi una funzione nel wrapper (o modifica quella esistente per la sua creazione) per fare in modo di filtrare eventuali wrappers.
Berack96 commented 2025-10-22 16:45:01 +02:00 (Migrated from github.com)

@copilot prova a modificare secondo le richieste fatte

@copilot prova a modificare secondo le richieste fatte
copilot-swe-agent[bot] (Migrated from github.com) reviewed 2025-10-22 16:49:27 +02:00
@@ -32,10 +32,9 @@ models:
api:
copilot-swe-agent[bot] (Migrated from github.com) commented 2025-10-22 16:49:27 +02:00

Updated in commit 93d005c. DuckDuckGoWrapper is now first in news_providers list.

Updated in commit 93d005c. DuckDuckGoWrapper is now first in news_providers list.
copilot-swe-agent[bot] (Migrated from github.com) reviewed 2025-10-22 16:49:27 +02:00
copilot-swe-agent[bot] (Migrated from github.com) commented 2025-10-22 16:49:27 +02:00

Refactored in commit 93d005c. Now uses the centralized WrapperHandler.filter_wrappers_by_config() helper function.

Refactored in commit 93d005c. Now uses the centralized `WrapperHandler.filter_wrappers_by_config()` helper function.
copilot-swe-agent[bot] (Migrated from github.com) reviewed 2025-10-22 16:49:28 +02:00
copilot-swe-agent[bot] (Migrated from github.com) commented 2025-10-22 16:49:28 +02:00

Refactored in commit 93d005c. Added WrapperHandler.filter_wrappers_by_config() static method that all tools now use instead of duplicating the filtering logic.

Refactored in commit 93d005c. Added `WrapperHandler.filter_wrappers_by_config()` static method that all tools now use instead of duplicating the filtering logic.
copilot-swe-agent[bot] (Migrated from github.com) reviewed 2025-10-22 16:49:28 +02:00
@@ -32,10 +32,9 @@ models:
api:
copilot-swe-agent[bot] (Migrated from github.com) commented 2025-10-22 16:49:28 +02:00

Updated in commit 93d005c. YFinanceWrapper is now first in market_providers list.

Updated in commit 93d005c. YFinanceWrapper is now first in market_providers list.
copilot-swe-agent[bot] (Migrated from github.com) reviewed 2025-10-22 16:49:28 +02:00
copilot-swe-agent[bot] (Migrated from github.com) commented 2025-10-22 16:49:28 +02:00

Refactored in commit 93d005c. Now uses the centralized WrapperHandler.filter_wrappers_by_config() helper function.

Refactored in commit 93d005c. Now uses the centralized `WrapperHandler.filter_wrappers_by_config()` helper function.
copilot-pull-request-reviewer[bot] (Migrated from github.com) reviewed 2025-10-22 17:16:08 +02:00
copilot-pull-request-reviewer[bot] (Migrated from github.com) left a comment

Pull Request Overview

This PR implements a configurable API provider system that allows users to select and prioritize API providers through configs.yaml, eliminating warnings for unconfigured providers and providing flexible retry settings.

Key Changes:

  • Added provider configuration lists to configs.yaml with all available wrappers
  • Extended APIConfig to store provider lists for market, news, and social data
  • Updated all API tools to use configured providers with centralized retry settings

Reviewed Changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
configs.yaml Added complete provider lists for market, news, and social APIs
src/app/configs.py Extended APIConfig with provider list fields
src/app/api/wrapper_handler.py Added filtering logic to build_wrappers method
src/app/api/tools/market_tool.py Updated to use configuration-based provider filtering
src/app/api/tools/news_tool.py Updated to use configuration-based provider filtering
src/app/api/tools/social_tool.py Updated to use configuration-based provider filtering
src/app/agents/core.py Removed get_tools method, simplified agent initialization
tests/tools/test_market_tool.py Removed currency parameter from test instantiations
tests/tools/test_socials_tool.py Fixed test method naming convention

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

## Pull Request Overview This PR implements a configurable API provider system that allows users to select and prioritize API providers through `configs.yaml`, eliminating warnings for unconfigured providers and providing flexible retry settings. **Key Changes:** - Added provider configuration lists to `configs.yaml` with all available wrappers - Extended `APIConfig` to store provider lists for market, news, and social data - Updated all API tools to use configured providers with centralized retry settings ### Reviewed Changes Copilot reviewed 9 out of 9 changed files in this pull request and generated 1 comment. <details> <summary>Show a summary per file</summary> | File | Description | | ---- | ----------- | | configs.yaml | Added complete provider lists for market, news, and social APIs | | src/app/configs.py | Extended APIConfig with provider list fields | | src/app/api/wrapper_handler.py | Added filtering logic to build_wrappers method | | src/app/api/tools/market_tool.py | Updated to use configuration-based provider filtering | | src/app/api/tools/news_tool.py | Updated to use configuration-based provider filtering | | src/app/api/tools/social_tool.py | Updated to use configuration-based provider filtering | | src/app/agents/core.py | Removed get_tools method, simplified agent initialization | | tests/tools/test_market_tool.py | Removed currency parameter from test instantiations | | tests/tools/test_socials_tool.py | Fixed test method naming convention | </details> --- <sub>**Tip:** Customize your code reviews with copilot-instructions.md. <a href="/Berack96/upo-appAI/new/main/.github?filename=copilot-instructions.md" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">Create the file</a> or <a href="https://docs.github.com/en/copilot/customizing-copilot/adding-repository-custom-instructions-for-github-copilot" class="Link--inTextBlock" target="_blank" rel="noopener noreferrer">learn how to get started</a>.</sub>
@@ -148,6 +154,10 @@ class WrapperHandler(Generic[WrapperType]):
"""
copilot-pull-request-reviewer[bot] (Migrated from github.com) commented 2025-10-22 17:16:08 +02:00

The filtering logic is duplicated. Lines 158-159 already filter constructors based on filters, making the check on lines 163-164 redundant. Remove the conditional check inside the loop since constructors has already been filtered.


The filtering logic is duplicated. Lines 158-159 already filter constructors based on filters, making the check on lines 163-164 redundant. Remove the conditional check inside the loop since constructors has already been filtered. ```suggestion ```
Berack96 (Migrated from github.com) approved these changes 2025-10-22 17:17:23 +02:00
Berack96 (Migrated from github.com) approved these changes 2025-10-22 17:19:02 +02:00
Simo93-rgb (Migrated from github.com) approved these changes 2025-10-27 12:42:36 +01:00
Sign in to join this conversation.