From 765fc0ac723325d1928a8acb94fa0f48f6e65fda Mon Sep 17 00:00:00 2001 From: trojanhorse47 Date: Thu, 30 Oct 2025 17:32:52 +0100 Subject: [PATCH] Decouple friendly tool descriptions via registry --- src/app/agents/action_registry.py | 9 ++++++++ src/app/agents/pipeline.py | 38 ++++++++----------------------- src/app/api/tools/market_tool.py | 10 ++++++++ src/app/api/tools/news_tool.py | 9 ++++++++ src/app/api/tools/social_tool.py | 7 ++++++ 5 files changed, 45 insertions(+), 28 deletions(-) create mode 100644 src/app/agents/action_registry.py diff --git a/src/app/agents/action_registry.py b/src/app/agents/action_registry.py new file mode 100644 index 0000000..f9a8e2b --- /dev/null +++ b/src/app/agents/action_registry.py @@ -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) \ No newline at end of file diff --git a/src/app/agents/pipeline.py b/src/app/agents/pipeline.py index 2ba03bb..038ac9b 100644 --- a/src/app/agents/pipeline.py +++ b/src/app/agents/pipeline.py @@ -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}...") \ No newline at end of file diff --git a/src/app/api/tools/market_tool.py b/src/app/api/tools/market_tool.py index 649f9d4..5ee7bf7 100644 --- a/src/app/api/tools/market_tool.py +++ b/src/app/api/tools/market_tool.py @@ -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...", +}) \ No newline at end of file diff --git a/src/app/api/tools/news_tool.py b/src/app/api/tools/news_tool.py index 88b5685..9fd6bed 100644 --- a/src/app/api/tools/news_tool.py +++ b/src/app/api/tools/news_tool.py @@ -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...", +}) \ No newline at end of file diff --git a/src/app/api/tools/social_tool.py b/src/app/api/tools/social_tool.py index 044c7c3..c6c2b1f 100644 --- a/src/app/api/tools/social_tool.py +++ b/src/app/api/tools/social_tool.py @@ -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...", +}) \ No newline at end of file