Added Prompt for tools #68

Merged
Simo93-rgb merged 5 commits from 64-prompt-for-tools into main 2025-10-31 00:13:02 +01:00
6 changed files with 33 additions and 65 deletions
Showing only changes of commit df65d36f4e - Show all commits

View File

@@ -0,0 +1,21 @@
from pathlib import Path
__INSTRUCTIONS_PATH = Path(__file__).parent
def __load_tool_instruction(file_name: str) -> str:
file_path = __INSTRUCTIONS_PATH / file_name
return file_path.read_text(encoding='utf-8').strip()
MARKET_TOOL_INSTRUCTIONS = __load_tool_instruction("market_instructions.md")
NEWS_TOOL_INSTRUCTIONS = __load_tool_instruction("news_instructions.md")
SOCIAL_TOOL_INSTRUCTIONS = __load_tool_instruction("social_instructions.md")
PLAN_MEMORY_TOOL_INSTRUCTIONS = __load_tool_instruction("plan_memory_instructions.md")
SYMBOLS_TOOL_INSTRUCTIONS = __load_tool_instruction("symbols_instructions.md")
__all__ = [
"MARKET_TOOL_INSTRUCTIONS",
"NEWS_TOOL_INSTRUCTIONS",
"SOCIAL_TOOL_INSTRUCTIONS",
"PLAN_MEMORY_TOOL_INSTRUCTIONS",
"SYMBOLS_TOOL_INSTRUCTIONS",
]

View File

@@ -1,5 +1,5 @@
from pathlib import Path
from agno.tools import Toolkit
from app.api.tools.instructions import MARKET_TOOL_INSTRUCTIONS
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
@@ -13,17 +13,6 @@ class MarketAPIsTool(MarketWrapper, Toolkit):
Providers can be configured in configs.yaml under api.market_providers.
copilot-pull-request-reviewer[bot] commented 2025-10-30 17:30:49 +01:00 (Migrated from github.com)
Review

The _load_instructions() method lacks error handling for missing instruction files. If the markdown file doesn't exist or is unreadable, this will raise an unhandled exception during toolkit initialization. Consider adding a try-except block with a fallback to a default instruction string or a more informative error message.

        try:
            return instructions_path.read_text(encoding="utf-8")
        except OSError:
            return "Market API instructions are unavailable."
The `_load_instructions()` method lacks error handling for missing instruction files. If the markdown file doesn't exist or is unreadable, this will raise an unhandled exception during toolkit initialization. Consider adding a try-except block with a fallback to a default instruction string or a more informative error message. ```suggestion try: return instructions_path.read_text(encoding="utf-8") except OSError: return "Market API instructions are unavailable." ```
Berack96 commented 2025-10-30 20:18:32 +01:00 (Migrated from github.com)
Review

Esiste già un metodo simile in __init__.py dentro agents/prompt.
Bastava richiamare quello o crearne uno universale da mettere da qualche parte, non replicarlo per ogni tool.

Esiste già un metodo simile in `__init__.py` dentro agents/prompt. Bastava richiamare quello o crearne uno universale da mettere da qualche parte, non replicarlo per ogni tool.
"""
@staticmethod
def _load_instructions() -> str:
"""
Load the toolkit instructions from the external text file.
Returns:
str: The content of the instructions file.
"""
instructions_path = Path(__file__).parent / "instructions" / "market_instructions.md"
return instructions_path.read_text(encoding="utf-8")
def __init__(self):
"""
Initialize the MarketAPIsTool with market API wrappers configured in configs.yaml.
@@ -41,6 +30,7 @@ class MarketAPIsTool(MarketWrapper, Toolkit):
Toolkit.__init__( # type: ignore
self,
name="Market APIs Toolkit",
instructions=MARKET_TOOL_INSTRUCTIONS,
tools=[
self.get_product,
self.get_products,
@@ -48,7 +38,6 @@ class MarketAPIsTool(MarketWrapper, Toolkit):
self.get_products_aggregated,
self.get_historical_prices_aggregated,
],
instructions=self._load_instructions(),
)
def get_product(self, asset_id: str) -> ProductInfo:

View File

@@ -1,5 +1,5 @@
from pathlib import Path
from agno.tools import Toolkit
from app.api.tools.instructions import NEWS_TOOL_INSTRUCTIONS
from app.api.wrapper_handler import WrapperHandler
from app.api.core.news import NewsWrapper, Article
from app.api.news import NewsApiWrapper, GoogleNewsWrapper, CryptoPanicWrapper, DuckDuckGoWrapper
@@ -16,17 +16,6 @@ class NewsAPIsTool(NewsWrapper, Toolkit):
If no wrapper succeeds, an exception is raised.
copilot-pull-request-reviewer[bot] commented 2025-10-30 17:30:48 +01:00 (Migrated from github.com)
Review

The _load_instructions() method lacks error handling for missing instruction files. If the markdown file doesn't exist or is unreadable, this will raise an unhandled exception during toolkit initialization. Consider adding a try-except block with a fallback to a default instruction string or a more informative error message.

        try:
            return instructions_path.read_text(encoding="utf-8")
        except Exception as e:
            # Fallback to a default instruction string if the file is missing or unreadable
            return (
                "News APIs Toolkit instructions could not be loaded. "
                "The instructions file is missing or unreadable. "
                "Please ensure 'news_instructions.md' exists in the 'instructions' directory."
            )
The `_load_instructions()` method lacks error handling for missing instruction files. If the markdown file doesn't exist or is unreadable, this will raise an unhandled exception during toolkit initialization. Consider adding a try-except block with a fallback to a default instruction string or a more informative error message. ```suggestion try: return instructions_path.read_text(encoding="utf-8") except Exception as e: # Fallback to a default instruction string if the file is missing or unreadable return ( "News APIs Toolkit instructions could not be loaded. " "The instructions file is missing or unreadable. " "Please ensure 'news_instructions.md' exists in the 'instructions' directory." ) ```
Berack96 commented 2025-10-30 20:18:45 +01:00 (Migrated from github.com)
Review

Esiste già un metodo simile in __init__.py dentro agents/prompt.
Bastava richiamare quello o crearne uno universale da mettere da qualche parte, non replicarlo per ogni tool.

Esiste già un metodo simile in `__init__.py` dentro agents/prompt. Bastava richiamare quello o crearne uno universale da mettere da qualche parte, non replicarlo per ogni tool.
"""
@staticmethod
def _load_instructions() -> str:
"""
Load the toolkit instructions from the external text file.
Returns:
str: The content of the instructions file.
"""
instructions_path = Path(__file__).parent / "instructions" / "news_instructions.md"
return instructions_path.read_text(encoding="utf-8")
def __init__(self):
"""
Initialize the NewsAPIsTool with news API wrappers configured in configs.yaml.
@@ -44,13 +33,13 @@ class NewsAPIsTool(NewsWrapper, Toolkit):
Toolkit.__init__( # type: ignore
self,
name="News APIs Toolkit",
instructions=NEWS_TOOL_INSTRUCTIONS,
tools=[
self.get_top_headlines,
self.get_latest_news,
self.get_top_headlines_aggregated,
self.get_latest_news_aggregated,
],
instructions=self._load_instructions(),
)
def get_top_headlines(self, limit: int = 100) -> list[Article]:

View File

@@ -1,6 +1,6 @@
from pathlib import Path
from agno.tools.toolkit import Toolkit
from typing import TypedDict, Literal
from app.api.tools.instructions import PLAN_MEMORY_TOOL_INSTRUCTIONS
@@ -11,21 +11,12 @@ class Task(TypedDict):
Berack96 commented 2025-10-30 20:18:48 +01:00 (Migrated from github.com)
Review

Esiste già un metodo simile in __init__.py dentro agents/prompt.
Bastava richiamare quello o crearne uno universale da mettere da qualche parte, non replicarlo per ogni tool.

Esiste già un metodo simile in `__init__.py` dentro agents/prompt. Bastava richiamare quello o crearne uno universale da mettere da qualche parte, non replicarlo per ogni tool.
class PlanMemoryTool(Toolkit):
@staticmethod
def _load_instructions() -> str:
"""
Load the toolkit instructions from the external markdown file.
Returns:
str: The content of the instructions file.
"""
instructions_path = Path(__file__).parent / "instructions" / "plan_memory_instructions.md"
return instructions_path.read_text(encoding="utf-8")
def __init__(self):
self.tasks: list[Task] = []
Toolkit.__init__(self, # type: ignore[call-arg]
instructions=self._load_instructions(),
name="Plan Memory Toolkit",
instructions=PLAN_MEMORY_TOOL_INSTRUCTIONS,
tools=[
self.add_tasks,
self.get_next_pending_task,

View File

@@ -1,5 +1,5 @@
from pathlib import Path
from agno.tools import Toolkit
from app.api.tools.instructions import SOCIAL_TOOL_INSTRUCTIONS
from app.api.wrapper_handler import WrapperHandler
from app.api.core.social import SocialPost, SocialWrapper
from app.api.social import *
@@ -17,17 +17,6 @@ class SocialAPIsTool(SocialWrapper, Toolkit):
If no wrapper succeeds, an exception is raised.
copilot-pull-request-reviewer[bot] commented 2025-10-30 17:30:48 +01:00 (Migrated from github.com)
Review

The _load_instructions() method lacks error handling for missing instruction files. If the markdown file doesn't exist or is unreadable, this will raise an unhandled exception during toolkit initialization. Consider adding a try-except block with a fallback to a default instruction string or a more informative error message.

        try:
            return instructions_path.read_text(encoding="utf-8")
        except Exception as e:
            # Fallback to a default instruction string or log the error
            return (
                "SocialAPIsTool instructions could not be loaded from file. "
                "Default instructions: Use the available tools to retrieve top cryptocurrency-related posts "
                "from supported social media providers. Configure providers in configs.yaml."
            )
The `_load_instructions()` method lacks error handling for missing instruction files. If the markdown file doesn't exist or is unreadable, this will raise an unhandled exception during toolkit initialization. Consider adding a try-except block with a fallback to a default instruction string or a more informative error message. ```suggestion try: return instructions_path.read_text(encoding="utf-8") except Exception as e: # Fallback to a default instruction string or log the error return ( "SocialAPIsTool instructions could not be loaded from file. " "Default instructions: Use the available tools to retrieve top cryptocurrency-related posts " "from supported social media providers. Configure providers in configs.yaml." ) ```
Berack96 commented 2025-10-30 20:18:53 +01:00 (Migrated from github.com)
Review

Esiste già un metodo simile in __init__.py dentro agents/prompt.
Bastava richiamare quello o crearne uno universale da mettere da qualche parte, non replicarlo per ogni tool.

Esiste già un metodo simile in `__init__.py` dentro agents/prompt. Bastava richiamare quello o crearne uno universale da mettere da qualche parte, non replicarlo per ogni tool.
"""
@staticmethod
def _load_instructions() -> str:
"""
Load the toolkit instructions from the external text file.
Returns:
str: The content of the instructions file.
"""
instructions_path = Path(__file__).parent / "instructions" / "social_instructions.md"
return instructions_path.read_text(encoding="utf-8")
def __init__(self):
"""
Initialize the SocialAPIsTool with social media API wrappers configured in configs.yaml.
@@ -44,12 +33,12 @@ class SocialAPIsTool(SocialWrapper, Toolkit):
Toolkit.__init__( # type: ignore
self,
name="Socials Toolkit",
name="Socials APIs Toolkit",
instructions=SOCIAL_TOOL_INSTRUCTIONS,
tools=[
self.get_top_crypto_posts,
self.get_top_crypto_posts_aggregated,
],
instructions=self._load_instructions(),
)
def get_top_crypto_posts(self, limit: int = 5) -> list[SocialPost]:

View File

@@ -4,8 +4,8 @@ import asyncio
import logging
import pandas as pd
from io import StringIO
from pathlib import Path
from agno.tools.toolkit import Toolkit
from app.api.tools.instructions import SYMBOLS_TOOL_INSTRUCTIONS
logging.basicConfig(level=logging.INFO)
logging = logging.getLogger("crypto_symbols")
@@ -19,23 +19,12 @@ class CryptoSymbolsTools(Toolkit):
Classe per ottenere i simboli delle criptovalute tramite Yahoo Finance.
copilot-pull-request-reviewer[bot] commented 2025-10-30 17:30:48 +01:00 (Migrated from github.com)
Review

The _load_instructions() method lacks error handling for missing instruction files. If the markdown file doesn't exist or is unreadable, this will raise an unhandled exception during toolkit initialization. Consider adding a try-except block with a fallback to a default instruction string or a more informative error message.

        try:
            return instructions_path.read_text(encoding="utf-8")
        except Exception as e:
            logging.error(f"Could not read instructions file at {instructions_path}: {e}")
            return (
                "Crypto Symbols Tool Instructions:\n"
                "This toolkit provides access to cryptocurrency symbols via Yahoo Finance.\n"
                "Use the available tools to list all symbols or search by name."
            )
The `_load_instructions()` method lacks error handling for missing instruction files. If the markdown file doesn't exist or is unreadable, this will raise an unhandled exception during toolkit initialization. Consider adding a try-except block with a fallback to a default instruction string or a more informative error message. ```suggestion try: return instructions_path.read_text(encoding="utf-8") except Exception as e: logging.error(f"Could not read instructions file at {instructions_path}: {e}") return ( "Crypto Symbols Tool Instructions:\n" "This toolkit provides access to cryptocurrency symbols via Yahoo Finance.\n" "Use the available tools to list all symbols or search by name." ) ```
Berack96 commented 2025-10-30 20:15:04 +01:00 (Migrated from github.com)
Review

It is as expected since the missing or corrupted instruction must be a blocking error

It is as expected since the missing or corrupted instruction must be a blocking error
Berack96 commented 2025-10-30 20:18:58 +01:00 (Migrated from github.com)
Review

Esiste già un metodo simile in __init__.py dentro agents/prompt.
Bastava richiamare quello o crearne uno universale da mettere da qualche parte, non replicarlo per ogni tool.

Esiste già un metodo simile in `__init__.py` dentro agents/prompt. Bastava richiamare quello o crearne uno universale da mettere da qualche parte, non replicarlo per ogni tool.
"""
@staticmethod
def _load_instructions() -> str:
"""
Load the toolkit instructions from the external markdown file.
Returns:
str: The content of the instructions file.
"""
instructions_path = Path(__file__).parent / "instructions" / "symbols_instructions.md"
return instructions_path.read_text(encoding="utf-8")
def __init__(self, cache_file: str = 'resources/cryptos.csv'):
self.cache_file = cache_file
self.final_table = pd.read_csv(self.cache_file) if os.path.exists(self.cache_file) else pd.DataFrame() # type: ignore
Toolkit.__init__(self, # type: ignore
name="Crypto Symbols Tool",
instructions=self._load_instructions(),
instructions=SYMBOLS_TOOL_INSTRUCTIONS,
tools=[
self.get_all_symbols,
self.get_symbols_by_name,