from typing import Dict
from typing import Any
from typing import Set


def scalar_training_metrics_names(exp: Dict[str, Any]) -> Set[str]:
    """
    Given an experiment history, return the names of training metrics
    that are associated with scalar, numeric values.

    This function assumes that all batches in an experiment return
    consistent training metric names and types. Therefore, the first
    non-null batch metrics dictionary is used to extract names.
    """
    for trial in exp["trials"]:
        for step in trial["steps"]:
            metrics = step.get("metrics")
            if not metrics:
                continue
            return set(metrics.get("avg_metrics", {}).keys())

    return set()