最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

python - Agno Framework: Correct Unix Timestamp but Incorrect dd-mm-yyyy Conversion? - Stack Overflow

programmeradmin3浏览0评论

I am using the Agno Framework to fetch historical stock data from Yahoo Finance. My agent correctly retrieves Unix timestamps in milliseconds, but when converting them to dd-mm-yyyy format, it returns incorrect dates.

Example:

  • Correct Unix Timestamp (milliseconds): 1738040400000
  • Expected Date (dd-mm-yyyy): 28-01-2025

I’m using Agent A in Agno with YFinanceTools to get OHLCV data. Here’s my agent setup:

tracked_stocks = ["NVDA"]

agent_a = Agent(
    model=OpenAIChat(id=OPENAI_MODEL_NAME, api_key=OPENAI_API_KEY, base_url=API_BASE_URL),
    tools=[YFinanceTools(stock_price=True, historical_prices=True)],  
    show_tool_calls=True,
    name="Market Data Fetcher",
    description="Fetches the latest 30 days of OHLCV stock data.",
    instructions=[
        "Retrieve the recent 30 days of OHLCV (Open, High, Low, Close, Volume) for the given stock symbol.",
        "Return the data as a structured JSON object: {date, open, high, low, close, volume}.",
    ]
)

Tried different conversion methods in Python:

from datetime import datetime

unix_timestamp = 1738040400000  # Example from Yahoo Finance
correct_date = datetime.utcfromtimestamp(unix_timestamp / 1000).strftime('%d-%m-%Y')
print("Converted Date:", correct_date)

✅ This works correctly outside of Agno, returning “28-01-2025”.

❌ But inside the Agno framework, the model still outputs a wrong date.

I explicitly instructed the agent:

"Convert the date from Unix timestamp (milliseconds) to dd-mm-yyyy format using: datetime.utcfromtimestamp(timestamp / 1000).strftime('%d-%m-%Y')."

Still gives the wrong date.

发布评论

评论列表(0)

  1. 暂无评论