Manas
Manas

Reputation: 9

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

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:

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.

Upvotes: 0

Views: 69

Answers (1)

Manthan Gupta
Manthan Gupta

Reputation: 71

I totally get where you're coming from! When it comes to LLMs and math, one of the big challenges is how they process numbers as tokens. A number like "1,234,567" might be broken down into smaller parts ("1", ",", "234", etc.), which makes it harder for the model to treat it as a single value. Plus, since LLMs are designed to predict the next token rather than perform precise calculations, they’re not really optimized for mathematical accuracy.

If you need 100% accuracy, I’d really recommend handling the math manually instead of relying on the agent. I know it’s an extra step, but it’ll save you from any potential errors down the line. Let me know if I can help brainstorm a better approach!

Upvotes: 0

Related Questions