Refactor action registration to use a decorator for user-friendly descriptions
This commit is contained in:
@@ -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...",
|
||||
})
|
||||
@@ -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.news import NewsWrapper, Article
|
||||
from app.api.news import NewsApiWrapper, GoogleNewsWrapper, CryptoPanicWrapper, DuckDuckGoWrapper
|
||||
@@ -42,6 +42,7 @@ class NewsAPIsTool(NewsWrapper, Toolkit):
|
||||
],
|
||||
)
|
||||
|
||||
@friendly_action("📰 Cerco le notizie principali...")
|
||||
def get_top_headlines(self, limit: int = 100) -> list[Article]:
|
||||
"""
|
||||
Retrieves top headlines from the *first available* news provider.
|
||||
@@ -58,6 +59,7 @@ class NewsAPIsTool(NewsWrapper, Toolkit):
|
||||
"""
|
||||
return self.handler.try_call(lambda w: w.get_top_headlines(limit))
|
||||
|
||||
@friendly_action("🔎 Cerco notizie recenti sull'argomento...")
|
||||
def get_latest_news(self, query: str, limit: int = 100) -> list[Article]:
|
||||
"""
|
||||
Searches for the latest news on a specific topic from the *first available* provider.
|
||||
@@ -75,6 +77,7 @@ class NewsAPIsTool(NewsWrapper, Toolkit):
|
||||
"""
|
||||
return self.handler.try_call(lambda w: w.get_latest_news(query, limit))
|
||||
|
||||
@friendly_action("🗞️ Raccolgo le notizie principali da tutte le fonti...")
|
||||
def get_top_headlines_aggregated(self, limit: int = 100) -> dict[str, list[Article]]:
|
||||
"""
|
||||
Retrieves top headlines from *all available providers* and aggregates the results.
|
||||
@@ -94,6 +97,7 @@ class NewsAPIsTool(NewsWrapper, Toolkit):
|
||||
"""
|
||||
return self.handler.try_call_all(lambda w: w.get_top_headlines(limit))
|
||||
|
||||
@friendly_action("📚 Raccolgo notizie specifiche da tutte le fonti...")
|
||||
def get_latest_news_aggregated(self, query: str, limit: int = 100) -> dict[str, list[Article]]:
|
||||
"""
|
||||
Searches for news on a specific topic from *all available providers* and aggregates the results.
|
||||
@@ -113,10 +117,3 @@ class NewsAPIsTool(NewsWrapper, Toolkit):
|
||||
Exception: If all providers fail to return results.
|
||||
"""
|
||||
return self.handler.try_call_all(lambda w: w.get_latest_news(query, limit))
|
||||
|
||||
register_friendly_actions({
|
||||
"get_top_headlines": "📰 Cerco le notizie principali...",
|
||||
"get_latest_news": "🔎 Cerco notizie recenti su un argomento...",
|
||||
"get_top_headlines_aggregated": "🗞️ Raccolgo le notizie principali da tutte le fonti...",
|
||||
"get_latest_news_aggregated": "📚 Raccolgo notizie specifiche da tutte le fonti...",
|
||||
})
|
||||
@@ -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.social import SocialPost, SocialWrapper
|
||||
from app.api.social import *
|
||||
@@ -41,6 +41,7 @@ class SocialAPIsTool(SocialWrapper, Toolkit):
|
||||
],
|
||||
)
|
||||
|
||||
@friendly_action("📱 Cerco i post più popolari sui social...")
|
||||
def get_top_crypto_posts(self, limit: int = 5) -> list[SocialPost]:
|
||||
"""
|
||||
Retrieves top cryptocurrency-related posts from the *first available* social media provider.
|
||||
@@ -57,6 +58,7 @@ class SocialAPIsTool(SocialWrapper, Toolkit):
|
||||
"""
|
||||
return self.handler.try_call(lambda w: w.get_top_crypto_posts(limit))
|
||||
|
||||
@friendly_action("🌐 Raccolgo i post da tutte le piattaforme social...")
|
||||
def get_top_crypto_posts_aggregated(self, limit_per_wrapper: int = 5) -> dict[str, list[SocialPost]]:
|
||||
"""
|
||||
Retrieves top cryptocurrency-related posts from *all available providers* and aggregates the results.
|
||||
@@ -75,8 +77,3 @@ class SocialAPIsTool(SocialWrapper, Toolkit):
|
||||
Exception: If all providers fail to return results.
|
||||
"""
|
||||
return self.handler.try_call_all(lambda w: w.get_top_crypto_posts(limit_per_wrapper))
|
||||
|
||||
register_friendly_actions({
|
||||
"get_top_crypto_posts": "📱 Cerco i post più popolari sui social...",
|
||||
"get_top_crypto_posts_aggregated": "🌐 Raccolgo i post da tutte le piattaforme social...",
|
||||
})
|
||||
Reference in New Issue
Block a user