Engineering

Human in the Loop Automation with Awaiting_Human and Resume in the Runs API

Rachel Kim||5 min
+T

Most automation gets stuck when it hits a UI change, a missing password prompt, or an unexpected error. You cannot predict every edge case with selectors and assertions alone. The Coasty Runs API solves this with a built-in pause that stops an agent when it needs human attention and lets you resume it later. This feature, controlled by on_awaiting_human and resume, is how you build robust human-in-the-loop automation that feels like a live assistant.

How the Awaiting_Human Flow Works

When a Coasty agent encounters a situation that requires human input, it sets the run state to awaiting_human. The default on_awaiting_human is pause, which stops the agent and returns a status of awaiting_human. You can then inspect the run, get its events, and decide how to proceed. To resume, you call POST /v1/runs/{id}/resume with no body. The agent continues from the last successfully executed step, reusing its screen history and trajectory memory. This loop of pause, check, and resume creates a reliable human-in-the-loop pipeline.

python
import os
import requests
import json

def start_run():
    url = "https://coasty.ai/v1/runs"
    api_key = os.getenv("COASTY_API_KEY")
    headers = {"X-API-Key": api_key}
    payload = {
        "machine_id": "your-provisioned-machine-id",
        "task": "Log in to a website and download a file.",
        "cua_version": "v3",
        "on_awaiting_human": "pause"
    }
    resp = requests.post(url, headers=headers, json=payload)
    resp.raise_for_status()
    return resp.json()

def check_run_status(run_id):
    url = f"https://coasty.ai/v1/runs/{run_id}"
    api_key = os.getenv("COASTY_API_KEY")
    headers = {"X-API-Key": api_key}
    resp = requests.get(url, headers=headers)
    resp.raise_for_status()
    return resp.json()

def resume_run(run_id):
    url = f"https://coasty.ai/v1/runs/{run_id}/resume"
    api_key = os.getenv("COASTY_API_KEY")
    headers = {"X-API-Key": api_key}
    resp = requests.post(url, headers=headers)
    resp.raise_for_status()
    return resp.json()

if __name__ == "__main__":
    run = start_run()
    print("Run started.", run)
    run_id = run["id"]
    status = check_run_status(run_id)["status"]
    while status not in ["succeeded", "failed", "cancelled", "timed_out"]:
        if status == "awaiting_human":
            print("Agent paused. Review events or approve.")
            # In practice, inspect events and decide
            resume_run(run_id)
            print("Resumed run.")
        status = check_run_status(run_id)["status"]
    print("Run ended.", status)

Key Fields and States

  • on_awaiting_human accepts pause, fail, or cancel. Use pause to keep the run alive for later human review.
  • Status values include queued, running, awaiting_human, succeeded, failed, cancelled, and timed_out.
  • POST /v1/runs/{id}/resume requires only the run ID and continues execution from the last successful step.
  • Each agent step costs $0.05, billed from your prepaid USD wallet (1 credit = $0.01).
  • You can stream events with GET /v1/runs/{id}/events using Server-Sent Events and reconnect with Last-Event-ID.

The one-line flow is: start run → poll status → resume when awaiting_human → repeat until terminal state.

Where This Beats Brittle Automation

Traditional automation relies on stable selectors and APIs that rarely change. When a UI element moves, a password prompt appears, or an error message changes, the script fails. The Coasty computer use API observes the actual screen and acts like a human user. By pausing on ambiguous states, you let a human decide the correct path. After approval, the agent picks up exactly where it left off. This approach reduces false positives and eliminates the need for brittle selectors and exhaustive test cases.

Use awaiting_human and resume to build automation that pauses for approval and continues autonomously. Combine it with retries and workflows to handle errors gracefully. The Runs API gives you full control over the agent lifecycle while keeping costs predictable. Start building human-in-the-loop automation with Coasty's computer use API. Get your API key at https://coasty.ai/developers.

Want to see this in action?

View Case Studies
Try Coasty Free