Decouple friendly tool descriptions via registry

This commit is contained in:
trojanhorse47
2025-10-30 17:32:52 +01:00
parent 46fac8bbac
commit 765fc0ac72
5 changed files with 45 additions and 28 deletions

View File

@@ -0,0 +1,9 @@
# Registro popolato da tutti i file Toolkit presenti all'avvio.
ACTION_DESCRIPTIONS: dict[str, str] = {}
def register_friendly_actions(actions: dict[str, str]):
"""
Aggiunge le descrizioni di un Toolkit al registro globale.
"""
global ACTION_DESCRIPTIONS
ACTION_DESCRIPTIONS.update(actions)

View File

@@ -8,11 +8,21 @@ from agno.run.workflow import WorkflowRunEvent
from agno.workflow.types import StepInput, StepOutput
from agno.workflow.step import Step
from agno.workflow.workflow import Workflow
from app.agents.action_registry import ACTION_DESCRIPTIONS
from app.agents.core import *
logging = logging.getLogger("pipeline")
def _get_user_friendly_action(tool_name: str) -> str:
"""
Restituisce un messaggio leggibile e descrittivo per l'utente
leggendo dal registro globale.
"""
# Usa il dizionario ACTION_DESCRIPTIONS importato
return ACTION_DESCRIPTIONS.get(tool_name, f"⚙️ Eseguo l'operazione: {tool_name}...")
class PipelineEvent(str, Enum):
QUERY_CHECK = "Query Check"
@@ -201,31 +211,3 @@ class Pipeline:
else:
logging.error(f"No output from workflow: {content}")
yield "Nessun output dal workflow, qualcosa è andato storto."
# Funzione di utilità per messaggi user-friendly
def _get_user_friendly_action(tool_name: str) -> str:
"""
Restituisce un messaggio leggibile e descrittivo per l'utente
in base al nome dello strumento o funzione invocata.
"""
descriptions = {
# --- MarketAPIsTool ---
"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...",
# --- NewsAPIsTool (Aggiunto) ---
"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...",
# --- SocialAPIsTool (Aggiunto) ---
"get_top_crypto_posts": "📱 Cerco i post più popolari sui social...",
"get_top_crypto_posts_aggregated": "🌐 Raccolgo i post da tutte le piattaforme social...",
}
# Messaggio di fallback generico
return descriptions.get(tool_name, f"⚙️ Eseguo l'operazione: {tool_name}...")

View File

@@ -1,4 +1,6 @@
from agno.tools import Toolkit
from app.agents.action_registry import register_friendly_actions
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
@@ -127,3 +129,11 @@ 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...",
})

View File

@@ -1,4 +1,6 @@
from agno.tools import Toolkit
from app.agents.action_registry import register_friendly_actions
from app.api.wrapper_handler import WrapperHandler
from app.api.core.news import NewsWrapper, Article
from app.api.news import NewsApiWrapper, GoogleNewsWrapper, CryptoPanicWrapper, DuckDuckGoWrapper
@@ -111,3 +113,10 @@ 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...",
})

View File

@@ -1,4 +1,6 @@
from agno.tools import Toolkit
from app.agents.action_registry import register_friendly_actions
from app.api.wrapper_handler import WrapperHandler
from app.api.core.social import SocialPost, SocialWrapper
from app.api.social import *
@@ -73,3 +75,8 @@ 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...",
})