Llama Tool Use

Fetch stock prices with YFinance tools from a Llama 4 Maverick agent in sync and async modes.

tool_use.py
"""Run `uv pip install agno llama-api-client yfinance` to install dependencies."""

import asyncio

from agno.agent import Agent
from agno.models.meta import Llama
from agno.tools.yfinance import YFinanceTools

# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------

agent = Agent(
    model=Llama(id="Llama-4-Maverick-17B-128E-Instruct-FP8"),
    tools=[YFinanceTools()],
)

# ---------------------------------------------------------------------------
# Run Agent
# ---------------------------------------------------------------------------
if __name__ == "__main__":
    # --- Sync ---
    agent.print_response("What is the price of AAPL stock?")

    # --- Sync + Streaming ---
    agent.print_response("Tell me the price of AAPL stock", stream=True)

    # --- Async ---
    asyncio.run(agent.aprint_response("Whats the price of AAPL stock?"))

    # --- Async + Streaming ---
    asyncio.run(agent.aprint_response("Whats the price of AAPL stock?", stream=True))

Run the Example

Set up your virtual environment

uv venv --python 3.12
source .venv/bin/activate

Install dependencies

uv pip install -U agno llama-api-client yfinance

Export your Meta Llama API key

export LLAMA_API_KEY="your_llama_api_key_here"

Run the example

Save the code above as tool_use.py, then run:

python tool_use.py

Full source: cookbook/90_models/meta/llama/tool_use.py