Human in the Loop Automation: Awaiting Human and Resume in the Runs API
Many workflows need human input at unpredictable moments. An agent might need to approve a purchase, choose an option from a dialog, or fix a corrupted file. The Coasty computer use runs API handles this with a human in the loop pattern. When the server detects that a task requires human attention, it sets the run state to awaiting_human. Your application can then pause the run, notify a human, and resume once they respond. This avoids brittle selectors and lets you automate tasks that cannot be fully scripted.
How awaiting_human and resume work
Create a run with the POST /v1/runs endpoint. Include machine_id, task, and cua_version. The optional on_awaiting_human parameter controls behavior when the run reaches awaiting_human. Set on_awaiting_human to pause to keep the run in that state without failing. The run stays in the queued, running, or awaiting_human state until you resume it. Use POST /v1/runs/{id}/resume to continue from the last agent step. Each agent step costs $0.05. The GET /v1/runs/{id}/events endpoint streams Server-Sent Events to track state changes. When the run succeeds, the state changes to succeeded. If it fails, it becomes failed.
import os
import requests
from requests.adapters import HTTPAdapter
from urllib3.util.retry import Retry
def create_run():
url = "https://coasty.ai/v1/runs"
api_key = os.getenv("COASTY_API_KEY")
headers = {"Authorization": f"Bearer {api_key}"}
machine_id = os.getenv("COASTY_MACHINE_ID")
payload = {
"machine_id": machine_id,
"task": "Open Chrome, navigate to example.com, and click the contact button.",
"cua_version": "v3",
"on_awaiting_human": "pause"
}
session = requests.Session()
retries = Retry(total=3, backoff_factor=1)
session.mount("https://", HTTPAdapter(max_retries=retries))
response = session.post(url, headers=headers, json=payload)
response.raise_for_status()
return response.json()
def get_run_events(run_id):
url = f"https://coasty.ai/v1/runs/{run_id}/events"
api_key = os.getenv("COASTY_API_KEY")
headers = {"Authorization": f"Bearer {api_key}"}
session = requests.Session()
retries = Retry(total=3, backoff_factor=1)
session.mount("https://", HTTPAdapter(max_retries=retries))
response = session.get(url, headers=headers, stream=True)
response.raise_for_status()
for line in response.iter_lines():
if line:
print(line.decode())
def resume_run(run_id):
url = f"https://coasty.ai/v1/runs/{run_id}/resume"
api_key = os.getenv("COASTY_API_KEY")
headers = {"Authorization": f"Bearer {api_key}"}
session = requests.Session()
retries = Retry(total=3, backoff_factor=1)
session.mount("https://", HTTPAdapter(max_retries=retries))
response = session.post(url, headers=headers)
response.raise_for_status()
return response.json()
if __name__ == "__main__":
run = create_run()
print("Run created.", run)
run_id = run["id"]
while True:
events = get_run_events(run_id)
# In a real client, process events to detect state changes.
# When state becomes awaiting_human, notify a human and pause.
# Then call resume_run(run_id) when the human responds.
breakKey fields and behavior
- ●on_awaiting_human options: pause, fail, cancel. Choose pause to keep the run in awaiting_human state.
- ●Agent step cost: $0.05 per step. Each predict or action call within a step is billed at this rate.
- ●State lifecycle: queued → running → awaiting_human → (paused) → running → succeeded or failed.
- ●Event stream: GET /v1/runs/{id}/events returns Server-Sent Events. Include Last-Event-ID to resume reading after a reconnect.
- ●Resume operation: POST /v1/runs/{id}/resume continues from the last agent step without resetting progress.
Set on_awaiting_human to pause and resume with POST /v1/runs/{id}/resume to keep the run in awaiting_human until a human responds.
Where this beats brittle automation
Traditional automation relies on stable selectors, XPath, or element IDs. When UI changes, these break. The Coasty computer use agent watches the screen, interprets instructions, and clicks or types like a human. It can handle dynamic content, pop‑ups, and dialogs that have no stable API. The human in the loop pattern adds the flexibility to approve actions, choose options, or intervene when something unexpected happens. This makes your automation resilient to UI changes and business logic that cannot be fully scripted.
Now you can build automation that pauses for human input. Use awaiting_human and resume to create reliable workflows for approval tasks, onboarding, and any process that needs judgment. Create a run with on_awaiting_human set to pause, monitor events, notify a human when the state changes, and resume when they respond. Each agent step costs $0.05. Get a key at https://coasty.ai/developers and start building human‑in‑the‑loop automation with the Coasty computer use API.