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