MLflow Via Autolog
Enable mlflow.agno.autolog() against a local MLflow tracking server to capture traces from a YFinance stock agent.
Demonstrates tracing an Agno agent with MLflow's built-in autolog integration.
"""
MLflow Via Autolog
==================
Demonstrates tracing an Agno agent with MLflow's built-in autolog integration.
Requirements:
pip install mlflow agno
Start MLflow:
mlflow server --host 127.0.0.1 --port 5000
Then open http://127.0.0.1:5000 to view traces.
NOTE: You can also configure the tracking URI and experiment via environment
variables instead of calling the Python APIs:
export MLFLOW_TRACKING_URI="http://127.0.0.1:5000"
export MLFLOW_EXPERIMENT_NAME="Agno Agent"
"""
import mlflow
from agno.agent import Agent
from agno.models.openai import OpenAIChat
from agno.tools.yfinance import YFinanceTools
# ---------------------------------------------------------------------------
# Setup — must be called BEFORE mlflow.agno.autolog()
# ---------------------------------------------------------------------------
# Point MLflow at a running tracking server
mlflow.set_tracking_uri("http://127.0.0.1:5000")
mlflow.set_experiment("Agno Agent")
# Enable MLflow tracing for Agno
mlflow.agno.autolog()
# ---------------------------------------------------------------------------
# Create Agent
# ---------------------------------------------------------------------------
agent = Agent(
model=OpenAIChat(id="gpt-5-mini"),
tools=[YFinanceTools()],
instructions="Use tables to display data. Don't include any other text.",
markdown=True,
)
agent.print_response("What is the stock price of Apple?", stream=False)Run the Example
Set up your virtual environment
uv venv --python 3.12
source .venv/bin/activateInstall dependencies
uv pip install -U agno mlflow openai yfinanceExport your OpenAI API key
export OPENAI_API_KEY="your_openai_api_key_here"Start MLflow
Start the local MLflow receiver on port 5000 and leave it running in a separate terminal:
mlflow server --host 127.0.0.1 --port 5000Run the example
Save the code above as mlflow_via_autolog.py, then run:
python mlflow_via_autolog.pyFull source: cookbook/observability/mlflow_via_autolog.py