Skip to main content
Preview Feature: File download support is currently in preview.
Download multiple files from a desktop application:
workflow.py
from nen import Agent, Computer
from pydantic import BaseModel, Field


class Params(BaseModel):
    patient_name: str = Field(min_length=1)


class Result(BaseModel):
    downloaded: int = 0
    files: list[str] = []


def run(params: Params) -> Result:
    agent = Agent()
    computer = Computer()

    # Navigate to documents section
    agent.execute(f"Navigate to patient '{params.patient_name}' documents")

    if not agent.verify("Is the documents list visible?"):
        raise RuntimeError("Documents list not visible")

    # Discover available documents
    documents = agent.extract(
        "List all downloadable document names",
        schema={"type": "array", "items": {"type": "string"}}
    )

    print(f"Found {len(documents)} documents to download")

    # Download each document
    downloaded_files = []
    for doc in documents:
        agent.execute(f"Click on document '{doc}'")
        agent.execute("Click the download button")

        if not agent.verify("Is the download complete or save dialog shown?"):
            print(f"Warning: Download may have failed for {doc}")
            continue

        downloaded_files.append(doc)

    return Result(downloaded=len(downloaded_files), files=downloaded_files)

Expected output

When run() completes successfully, the console will contain lines like:
Found 3 documents to download
Warning: Download may have failed for lab-results.pdf
The first line is always printed once — run() calls print(f"Found {len(documents)} documents to download") right after extracting the document list. The Warning line is only printed for documents where agent.verify() returns False, so it may appear zero or more times depending on which downloads succeed. The function then returns a Result object:
Result(downloaded=2, files=["discharge-summary.pdf", "imaging-report.pdf"])
downloaded reflects only the documents that were successfully downloaded, and files contains their names. Documents for which agent.verify() returned False are excluded from both.