Skip to main content

Deploy to Environments

This guide shows you how to deploy variants to environments (development, staging, production) using the Agenta SDK.

Deploying to Environments

To deploy a variant to an environment, use the DeploymentManager.deploy method with the variant reference and environment_slug: The slug of the environment (development, staging, or production).

deployment = ag.DeploymentManager.deploy(
app_slug="my-app-slug",
variant_slug="my-variant-slug",
variant_version=None, # Deploys latest version if not specified
environment_slug="staging" # Options: development, staging, production
)

print(f"Deployed to {deployment['environment_slug']}")
warning
  • Deploying a variant without specifying a variant_version deploys the latest version.
  • Only predefined environments with slugs development, staging, and production are currently supported.

Sample Output:

Deployed variant to environment:
{
"app_id": "01963413-3d39-7650-80ce-3ad5d688da6c",
"app_slug": "completion",
"variant_id": "01968c11-6f7c-7773-b273-922c5807be7b",
"variant_slug": "my-variant-slug4",
"variant_version": 5,
"environment_id": "01968c14-c35d-7440-bcc8-9def594f017f",
"environment_slug": "staging",
"environment_version": 2,
"committed_at": "2025-05-01T07:26:08.935406+00:00",
"committed_by": "user@agenta.ai",
"committed_by_id": "0196247a-ec9d-7051-8880-d58279570aa1",
"deployed_at": "2025-05-01T13:41:33.149595+00:00",
"deployed_by": "user@agenta.ai",
"deployed_by_id": "0196247a-ec9d-7051-8880-d58279570aa1"
}

Rolling Back to a Previous Version

To rollback to a previous version, you can deploy a specific version of a variant to an environment:

# Deploy a specific version (rollback)
deployment = ag.DeploymentManager.deploy(
app_slug="my-app-slug",
variant_slug="my-variant-slug",
variant_version=3, # Specify the version you want to rollback to
environment_slug="production"
)

print(f"Rolled back to version {deployment['variant_version']}")

This effectively rolls back the environment to the specified version of the variant.

tip

You can view the full history of deployments and versions in the Agenta UI under the Registry and Deployments pages.