Hi, I am facing this issue when working with custom tools
Code Snippet:
class SearchCoinGeckoAPIInput(BaseModel):
query: str = Field(…, description=“Query string to search for coin information.”)
class CryptoTools(BaseTool):
name: str = “Search CoinGecko API”
description: str = “Searches CoinGecko Pro API for coin information using a query string.”
args_schema: Type[BaseModel] = SearchCoinGeckoAPIInput
coingecko_api_key: str = os.getenv("COINGECKO_API_KEY", "")
if not coingecko_api_key:
raise ValueError("COINGECKO_API_KEY is missing! Set it in environment variables.")
base_headers: Dict[str, str] = {
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36',
'x-cg-pro-api-key': coingecko_api_key
}
def _run(self, query: str) → str:
“”“Search CoinGecko Pro API for coin information using a query string.”“”
try:
url = f"https://pro-api.coingecko.com/api/v3/search?query={query}"
response = requests.get(url, headers=self.base_headers)
response.raise_for_status()
data = response.json()
coins = data.get('coins', [])
if not coins:
return {
"success": False,
"message": f"No results found for '{query}' on CoinGecko Pro"
}
best_match = coins[0]
return {
"success": True,
"coin_id": best_match.get('id'),
"name": best_match.get('name'),
"symbol": best_match.get('symbol', '').upper(),
"market_cap_rank": best_match.get('market_cap_rank')
}
except requests.exceptions.HTTPError as e:
return {
"success": False,
"message": f"HTTP error: {e.response.status_code} - {e.response.text}"
}
except requests.exceptions.RequestException as e:
return {
"success": False,
"message": f"Request error: {str(e)}"
}
except Exception as e:
return {
"success": False,
"message": f"Unexpected error: {str(e)}"
}
Even after extending the BaseTool class the error still remains unresolved.
Anyone who has faced similar issue, please guide.