---
title: Tracing AG2 | Databricks on AWS
source: https://docs.databricks.com/aws/en/mlflow3/genai/tracing/integrations/ag2
ingestedAt: "2026-06-18T08:16:50.942Z"
---

    import osfrom typing import Annotated, Literalfrom autogen import ConversableAgentimport mlflow# Enable auto-tracing for AG2mlflow.ag2.autolog()# Track to Databricks (optional if already configured)mlflow.set_tracking_uri("databricks")mlflow.set_experiment("/Shared/ag2-tracing-demo")# Define a simple multi-agent workflow using AG2 (AutoGen 0.2)config_list = [    {        "model": "gpt-4o-mini",        # Requires OPENAI_API_KEY in env for this example        "api_key": os.environ.get("OPENAI_API_KEY"),    }]Operator = Literal["+", "-", "*", "/"]def calculator(a: int, b: int, operator: Annotated[Operator, "operator"]) -> int:    if operator == "+":        return a + b    elif operator == "-":        return a - b    elif operator == "*":        return a * b    elif operator == "/":        return int(a / b)    else:        raise ValueError("Invalid operator")assistant = ConversableAgent(    name="Assistant",    system_message=(        "You are a helpful AI assistant. You can help with simple calculations. "        "Return 'TERMINATE' when the task is done."    ),    llm_config={"config_list": config_list},)user_proxy = ConversableAgent(    name="Tool Agent",    llm_config=False,    is_termination_msg=lambda msg: msg.get("content") is not None and "TERMINATE" in msg["content"],    human_input_mode="NEVER",)assistant.register_for_llm(name="calculator", description="A simple calculator")(calculator)user_proxy.register_for_execution(name="calculator")(calculator)response = user_proxy.initiate_chat(    assistant, message="What is (44231 + 13312 / (230 - 20)) * 4?")
