Refactor action registration to use a decorator for user-friendly descriptions

This commit is contained in:
trojanhorse47
2025-10-31 13:55:59 +01:00
parent 2803263bed
commit 0598e58708
7 changed files with 48 additions and 38 deletions

View File

@@ -1,6 +1,6 @@
from agno.tools import Toolkit
from app.agents.action_registry import register_friendly_actions
from app.agents.action_registry import friendly_action
from app.api.wrapper_handler import WrapperHandler
from app.api.core.markets import MarketWrapper, Price, ProductInfo
from app.api.markets import BinanceWrapper, CoinBaseWrapper, CryptoCompareWrapper, YFinanceWrapper
@@ -40,6 +40,7 @@ class MarketAPIsTool(MarketWrapper, Toolkit):
],
)
@friendly_action("🔍 Recupero le informazioni sul prodotto richiesto...")
def get_product(self, asset_id: str) -> ProductInfo:
"""
Gets product information for a *single* asset from the *first available* provider.
@@ -56,6 +57,7 @@ class MarketAPIsTool(MarketWrapper, Toolkit):
"""
return self.handler.try_call(lambda w: w.get_product(asset_id))
@friendly_action("📦 Recupero i dati su più asset...")
def get_products(self, asset_ids: list[str]) -> list[ProductInfo]:
"""
Gets product information for a *list* of assets from the *first available* provider.
@@ -72,6 +74,7 @@ class MarketAPIsTool(MarketWrapper, Toolkit):
"""
return self.handler.try_call(lambda w: w.get_products(asset_ids))
@friendly_action("📊 Recupero i dati storici dei prezzi...")
def get_historical_prices(self, asset_id: str, limit: int = 100) -> list[Price]:
"""
Gets historical price data for a *single* asset from the *first available* provider.
@@ -89,6 +92,7 @@ class MarketAPIsTool(MarketWrapper, Toolkit):
"""
return self.handler.try_call(lambda w: w.get_historical_prices(asset_id, limit))
@friendly_action("🧩 Aggrego le informazioni da più fonti...")
def get_products_aggregated(self, asset_ids: list[str]) -> list[ProductInfo]:
"""
Gets product information for multiple assets from *all available providers* and *aggregates* the results.
@@ -109,6 +113,7 @@ class MarketAPIsTool(MarketWrapper, Toolkit):
all_products = self.handler.try_call_all(lambda w: w.get_products(asset_ids))
return ProductInfo.aggregate(all_products)
@friendly_action("📈 Creo uno storico aggregato dei prezzi...")
def get_historical_prices_aggregated(self, asset_id: str = "BTC", limit: int = 100) -> list[Price]:
"""
Gets historical price data for a single asset from *all available providers* and *aggregates* the results.
@@ -129,11 +134,3 @@ class MarketAPIsTool(MarketWrapper, Toolkit):
"""
all_prices = self.handler.try_call_all(lambda w: w.get_historical_prices(asset_id, limit))
return Price.aggregate(all_prices)
register_friendly_actions({
"get_product": "🔍 Recupero le informazioni sul prodotto richiesto...",
"get_products": "📦 Recupero i dati su più asset...",
"get_historical_prices": "📊 Recupero i dati storici dei prezzi...",
"get_products_aggregated": "🧩 Aggrego le informazioni da più fonti...",
"get_historical_prices_aggregated": "📈 Creo uno storico aggregato dei prezzi...",
})