Flyte 2: Durable AI Runtime

Recover from infra and code failures, orchestrate dynamic workflows, scale to production.

Copied to clipboard!
$ pip install flyte 
$ flyte start devbox
    
Flyte UI ready at http://localhost:30080
Trusted by thousands of AI builders

Author in pure Python

Write or generate workflows in simple Python. No DSL, no YAML hell.

Copied to clipboard!
"""Run durable agents with full observability"""

import random

import flyte
from flyte.ai.agents import Agent

env = flyte.TaskEnvironment(
    name="openai_agents_tools",
    resources=flyte.Resources(cpu=1, memory="250Mi"),
    image=flyte.Image.from_debian_base().with_pip_packages(
        "flyte", "flyteplugins-openai", "openai-agents",
    ),
    secrets=flyte.Secret("OPENAI_API_KEY", as_env_var="OPENAI_API_KEY"),
)

@env.task
async def get_weather(city: str) -> dict[str, str | float]:
    data = {
        "new york": {"temperature_f": 68.4, "conditions": "partly cloudy"},
        "san francisco": {"temperature_f": 61.0, "conditions": "foggy"},
        "tokyo": {"temperature_f": 74.2, "conditions": "sunny"},
    }
    return data.get(city.lower(), {"temperature_f": 70.0, "conditions": "clear"})


agent = Agent(
    name="Weather agent",
    instructions="You are a helpful weather agent.",
    tools=[get_weather],
)

@env.task
async def main(request: str) -> str:
    result = await agent.run.aio(agent, input=request)
    return result.summary or result.error

#flyte run agent.py main --request "What is the weather in Tokyo, Japan?"
Copied to clipboard!
"""Run high-throughout inference for generative AI."""
  
import base64
import torch

import flyte
import flyte.io
import flyte.report

env = flyte.TaskEnvironment(
    name="stable-diffusion",
    image=(
        flyte.Image.from_debian_base()
        .with_commands(["pip install torch torchvision --index-url https://download.pytorch.org/whl/cu124"])
        .with_requirements("requirements.txt")
    ),
    resources=flyte.Resources(cpu=2, memory="8Gi", gpu=1),
)

@env.task(report=True)
async def generate(prompt: str, steps: int = 30) -> flyte.io.File:
    """Generate an image from a text prompt using Stable Diffusion."""
    from diffusers import AutoPipelineForText2Image

    device = "cuda" if torch.cuda.is_available() else "cpu"
    pipe = AutoPipelineForText2Image.from_pretrained(
        "stabilityai/sdxl-turbo",
        torch_dtype=torch.float16 if device == "cuda" else torch.float32,
        variant="fp16" if device == "cuda" else None,
    ).to(device)

    image = pipe(prompt, num_inference_steps=steps, guidance_scale=0.0).images[0]

    path = "/tmp/output.png"
    image.save(path)

    with open(path, "rb") as f:
        img_b64 = base64.b64encode(f.read()).decode()
    await flyte.report.replace.aio(
        f"<h2>Stable Diffusion</h2>"
        f"<p><b>Prompt:</b> {prompt}</p>"
        f'<img src="data:image/png;base64,{img_b64}" style="max-width:512px" />'
    )
    await flyte.report.flush.aio()

    return await flyte.io.File.from_local(path)

#flyte run stable_diffusion.py generate --prompt "a cat astronaut floating in space, digital art"
Copied to clipboard!
"""Run data ETL jobs at scale with modern frameworks."""
  
import duckdb
import pandas as pd

import flyte
import flyte.report

env = flyte.TaskEnvironment(
    name="duckdb-etl",
    image=flyte.Image.from_debian_base().with_pip_packages("duckdb", "pandas", "pyarrow"),
    resources=flyte.Resources(cpu=1, memory="1Gi"),
)

SAMPLE_CSV = "https://raw.githubusercontent.com/datasciencedojo/datasets/master/titanic.csv"

@env.task
async def extract() -> pd.DataFrame:
    """Load raw data from a CSV source."""
    df = duckdb.sql(f"SELECT * FROM read_csv_auto('{SAMPLE_CSV}')").df()
    print(f"Extracted {len(df)} rows")
    return df

@env.task
async def transform(raw: pd.DataFrame) -> pd.DataFrame:
    """Aggregate survival stats by passenger class using DuckDB SQL."""
    summary = duckdb.sql("""
        SELECT
            Pclass AS passenger_class,
            COUNT(*) AS total,
            SUM(Survived) AS survived,
            ROUND(AVG(Survived) * 100, 1) AS survival_rate,
            ROUND(AVG(Fare), 2) AS avg_fare
        FROM raw
        GROUP BY Pclass
        ORDER BY Pclass
    """).df()
    print(summary.to_string(index=False))
    return summary

@env.task(report=True)
async def pipeline() -> pd.DataFrame:
    """Extract → Transform pipeline."""
    raw = await extract()
    summary = await transform(raw)

    await flyte.report.replace.aio(
        f"<h2>DuckDB ETL Results</h2>"
        f"<p>Processed {len(raw)} rows into {len(summary)} groups</p>"
        f"<h3>Survival by Passenger Class</h3>"
        f"{summary.to_html(index=False)}"
    )
    await flyte.report.flush.aio()

    return summary

#flyte run duckdb_etl.py pipeline

Introducing Flyte 2

The most intuitive, developer-loved way to orchestrate durable AI workflows in open source.

Durable execution across infra and code failures

Unlike other tools, Flyte 2 is infra-aware and can automatically recover from infra failures like OOM, container pre-emptions, and node interruptions.

Orchestrate agent-native workflows that adapt at runtime

Execute workflows that branch, loop, and provision resources on the fly.

Inference, sandboxing, and a pro UI

Flyte 2 is designed for production scale. That means giving you the tools and devex to get there.

Make your AI, ML, and agentic workflows fly.

Build dynamic, self-healing workflows in open source. Our infra-aware platform orchestrates data, models, & compute.

Build in pure Python

Author dynamic, production workflows in pure Python. No DSL required

Recover from infra failures

Automatically recover from OOM kills, preempted nodes, and disappearing GPUs, no manual intervention

Recover from code failures

Retry and resume from failed tasks without rerunning the whole pipeline

Adapt at runtime

Branch, loop, and make decisions during execution, built for agents and dynamic pipelines

Autoscale compute

Scale infrastructure up and down automatically to match workload demand

Scale workloads

Run thousands of parallel tasks and distributed jobs without rewriting your pipeline

Integrations

Expand your workflows with powerful integrations.

Apache Spark

Run Spark jobs on ephemeral clusters.

BigQuery

Query a BigQuery table.

PyTorch Elastic v1

Pytorch-native multi-node distributed training.

Ray

Connect to Ray cluster to perform distributed model training and hyperparameter tuning.

Snowflake

Query a Snowflake service.

Weights & Biases v1

Best in class ML/AI experiment- and inference-time tracking.

Community

Ask questions, share ideas, and
get advice.