[Python] Agno Framework: Correct Unix Timestamp but Incorrect dd-mm-yyyy Conversion?

Discussão em 'Python' iniciado por Stack, Fevereiro 15, 2025.

  1. Stack

    Stack Membro Participativo

    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.

    Continue reading...

Compartilhe esta Página