This is the multi-page printable view of this section. Click here to print.

Return to the regular view of this page.

Automations

The W&B Automations API enables programmatic creation and management of automated workflows that respond to events in your ML pipeline. Configure actions to trigger when specific conditions are met, such as model performance thresholds or artifact creation.

Overview

Automations in W&B (wandb.automations) provide event-driven workflow automation for ML operations. Define triggers based on run metrics, artifact events, or other conditions, and specify actions such as sending notifications or webhooks. Automations execute automatically when their trigger conditions are satisfied, enabling responsive ML pipelines without manual intervention.

Available Components

Core Classes

Class Description
Automation Represents a saved automation instance with its configuration.
NewAutomation Builder class for creating new automations.

Events (Triggers)

Event Description
OnRunMetric Trigger when a run metric satisfies a defined condition (threshold, change, etc.).
OnCreateArtifact Trigger when a new artifact is created in a collection.
OnLinkArtifact Trigger when an artifact is linked to a registry.
OnAddArtifactAlias Trigger when an alias is added to an artifact.

Actions

Action Description
SendNotification Send notifications via Slack or other integrated channels.
SendWebhook Send HTTP webhook requests to external services.
DoNothing Placeholder action for testing automation configurations.

Filters

Filter Description
MetricThresholdFilter Filter runs based on metric value comparisons against thresholds.
MetricChangeFilter Filter runs based on metric value changes over time.

Common Use Cases

Model Performance Monitoring

  • Alert when model accuracy drops below a threshold
  • Notify team when training loss plateaus
  • Trigger retraining pipelines based on performance metrics

Artifact Management

  • Send notifications when new model versions are created
  • Trigger deployment workflows when artifacts are tagged
  • Automate downstream processing when datasets are updated

Experiment Tracking

  • Alert on failed or crashed runs
  • Notify when long-running experiments complete
  • Send daily summaries of experiment metrics

Integration Workflows

  • Update external tracking systems via webhooks
  • Sync model registry with deployment platforms
  • Trigger CI/CD pipelines based on W&B events

Configuration

Setting Up Integrations

# Configure Slack integration
from wandb.automations import SlackIntegration

slack = SlackIntegration(
    webhook_url="https://hooks.slack.com/services/..."
)

# Use in notification action
notification = SendNotification.from_integration(
    integration=slack,
    title="ML Alert",
    text="Training completed",
    level="INFO"
)

Filter Operators

Metric filters support standard comparison operators:

  • ">": Greater than
  • "<": Less than
  • ">=": Greater than or equal
  • "<=": Less than or equal
  • "==": Equal to
  • "!=": Not equal to

Aggregation Options

For metric filters with windows:

  • "min": Minimum value in window
  • "max": Maximum value in window
  • "mean": Average value in window
  • "sum": Sum of values in window

Usage Notes

  • Automations require appropriate permissions in the target project or organization
  • Rate limits apply to action executions (notifications, webhooks)
  • Filters are evaluated on the W&B backend, not locally
  • Disabled automations remain saved but do not trigger
  • Test automations with DoNothing action before deploying

Example Usage

import wandb
from wandb.automations import OnRunMetric, SendNotification, MetricThresholdFilter

# Initialize W&B
wandb.login()

# Create an automation that alerts when accuracy exceeds 0.95
automation = OnRunMetric(
    filter=MetricThresholdFilter(
        name="accuracy",
        cmp=">",
        threshold=0.95
    ),
    scope="entity/project"
).then(
    SendNotification(
        title="High Accuracy Achieved",
        message="Model accuracy exceeded 95%",
        severity="INFO"
    )
)

# Save the automation
automation.save(name="accuracy-alert", enabled=True)

# Create an automation for artifact creation
artifact_automation = OnCreateArtifact(
    scope="entity/project/artifact-collection"
).then(
    SendWebhook.from_integration(
        integration=webhook_integration,
        payload={"event": "new_artifact", "collection": "models"}
    )
)

# Save with description
artifact_automation.save(
    name="model-webhook",
    description="Notify external service on new model creation",
    enabled=True
)

# Query existing automations
from wandb.apis.public import Api
api = Api()
automations = api.project("entity/project").automations()

for auto in automations:
    print(f"Automation: {auto.name}")
    print(f"Enabled: {auto.enabled}")
    print(f"Event: {auto.event}")

1 - Automation

A local instance of a saved W&B automation.

Attributes:

  • action (Union): The action that will execute when this automation is triggered.
  • description (Optional): An optional description of this automation.
  • enabled (bool): Whether this automation is enabled. Only enabled automations will trigger.
  • event (SavedEvent): The event that will trigger this automation.
  • name (str): The name of this automation.
  • scope (Union): The scope in which the triggering event must occur.

2 - DoNothing

Defines an automation action that intentionally does nothing.

Attributes:

  • action_type (Literal): The kind of action to be triggered.
  • no_op (bool): Placeholder field which exists only to satisfy backend schema requirements. There should never be a need to set this field explicitly, as its value is ignored.

3 - MetricChangeFilter

Defines a filter that compares a change in a run metric against a user-defined threshold.

The change is calculated over “tumbling” windows, i.e. the difference between the current window and the non-overlapping prior window.

Attributes:

  • agg (Optional): Aggregate operation, if any, to apply over the window size.
  • change_dir (ChangeDir): No description provided.
  • change_type (ChangeType): No description provided.
  • name (str): Name of the observed metric.
  • prior_window (int): Size of the prior window over which the metric is aggregated (ignored if agg is None). If omitted, defaults to the size of the current window.
  • threshold (Union): Threshold value to compare against.
  • window (int): Size of the window over which the metric is aggregated (ignored if agg is None).

4 - MetricThresholdFilter

Defines a filter that compares a run metric against a user-defined threshold value.

Attributes:

  • agg (Optional): Aggregate operation, if any, to apply over the window size.
  • cmp (Literal): Comparison operator used to compare the metric value (left) vs. the threshold value (right).
  • name (str): Name of the observed metric.
  • threshold (Union): Threshold value to compare against.
  • window (int): Size of the window over which the metric is aggregated (ignored if agg is None).

5 - NewAutomation

A new automation to be created.

Attributes:

  • action (Optional): The action that will execute when this automation is triggered.
  • description (Optional): An optional description of this automation.
  • enabled (Optional): Whether this automation is enabled. Only enabled automations will trigger.
  • event (Optional): The event that will trigger this automation.
  • name (Optional): The name of this automation.

6 - OnAddArtifactAlias

A new alias is assigned to an artifact.

Attributes:

  • event_type (Literal): No description provided.
  • filter (Union): Additional condition(s), if any, that must be met for this event to trigger an automation.
  • scope (Union): The scope of the event.

method then

then(self, action: 'InputAction') -> 'NewAutomation'

Define a new Automation in which this event triggers the given action.

7 - OnCreateArtifact

A new artifact is created.

Attributes:

  • event_type (Literal): No description provided.
  • filter (Union): Additional condition(s), if any, that must be met for this event to trigger an automation.
  • scope (Union): The scope of the event: only artifact collections are valid scopes for this event.

method then

then(self, action: 'InputAction') -> 'NewAutomation'

Define a new Automation in which this event triggers the given action.

8 - OnLinkArtifact

A new artifact is linked to a collection.

Attributes:

  • event_type (Literal): No description provided.
  • filter (Union): Additional condition(s), if any, that must be met for this event to trigger an automation.
  • scope (Union): The scope of the event.

method then

then(self, action: 'InputAction') -> 'NewAutomation'

Define a new Automation in which this event triggers the given action.

9 - OnRunMetric

A run metric satisfies a user-defined condition.

Attributes:

  • event_type (Literal): No description provided.
  • filter (RunMetricFilter): Run and/or metric condition(s) that must be satisfied for this event to trigger an automation.
  • scope (ProjectScope): The scope of the event: only projects are valid scopes for this event.

method then

then(self, action: 'InputAction') -> 'NewAutomation'

Define a new Automation in which this event triggers the given action.

10 - SendNotification

Defines an automation action that sends a (Slack) notification.

Attributes:

  • action_type (Literal): The kind of action to be triggered.
  • message (str): The message body of the sent notification.
  • severity (AlertSeverity): The severity (INFO, WARN, ERROR) of the sent notification.
  • title (str): The title of the sent notification.

method from_integration

from_integration(cls, integration: 'SlackIntegration', *, title: 'str' = '', text: 'str' = '', level: 'AlertSeverity' = <AlertSeverity.INFO: 'INFO'>) -> 'Self'

Define a notification action that sends to the given (Slack) integration.

11 - SendWebhook

Defines an automation action that sends a webhook request.

Attributes:

  • action_type (Literal): The kind of action to be triggered.
  • request_payload (Optional): The payload, possibly with template variables, to send in the webhook request.

method from_integration

from_integration(cls, integration: 'WebhookIntegration', *, payload: 'Optional[SerializedToJson[dict[str, Any]]]' = None) -> 'Self'

Define a webhook action that sends to the given (webhook) integration.