Tool #15
@@ -71,17 +71,16 @@ class MarketAgent(Agent):
|
||||
results = []
|
||||
products: List[ProductInfo] = []
|
||||
|
||||
for sym in symbols:
|
||||
try:
|
||||
product = self.toolkit.get_current_price(sym) # supponiamo ritorni un ProductInfo o simile
|
||||
if isinstance(product, list):
|
||||
products.extend(product)
|
||||
else:
|
||||
products.append(product)
|
||||
|
||||
results.append(f"{sym}: {product.price if hasattr(product, 'price') else product}")
|
||||
products.extend(self.toolkit.get_current_prices(symbols)) # supponiamo ritorni un ProductInfo o simile
|
||||
# Usa list comprehension per iterare symbols e products insieme
|
||||
results.extend([
|
||||
f"{symbol}: ${product.price:.2f}" if hasattr(product,
|
||||
'price') and product.price else f"{symbol}: N/A"
|
||||
for symbol, product in zip(symbols, products)
|
||||
])
|
||||
except Exception as e:
|
||||
results.append(f"{sym}: errore ({e})")
|
||||
results.extend(f"Errore: impossibile recuperare i dati di mercato\n {e}")
|
||||
|
||||
# 4. Preparo output leggibile + metadati strutturati
|
||||
output_text = "📊 Dati di mercato:\n" + "\n".join(results)
|
||||
|
||||
@@ -16,15 +16,15 @@ class MarketToolkit(Toolkit):
|
||||
name="Market Toolkit",
|
||||
tools=[
|
||||
self.get_historical_data,
|
||||
self.get_current_price,
|
||||
self.get_current_prices,
|
||||
],
|
||||
)
|
||||
|
||||
def get_historical_data(self, symbol: str):
|
||||
return self.market_api.get_historical_prices(symbol)
|
||||
|
||||
def get_current_price(self, symbol: str):
|
||||
return self.market_api.get_products(symbol)
|
||||
def get_current_prices(self, symbols: list):
|
||||
return self.market_api.get_products(symbols)
|
||||
|
||||
def prepare_inputs():
|
||||
pass
|
||||
|
||||
Reference in New Issue
Block a user