import time
import requests
API = "https://agent.usedari.com"
HEADERS = {"X-API-Key": "YOUR_API_KEY"}
# 1. Start job with HITL
resp = requests.post(
f"{API}/jobs/my-org/insurance_form/start",
headers=HEADERS,
json={
"form_data": {"name": "Jane Smith", "state": "CA"},
"human_in_the_loop": True,
},
)
job_id = resp.json()["job_id"]
# 2. Poll for questions
while True:
status = requests.get(
f"{API}/jobs/my-org/insurance_form/status",
headers=HEADERS,
params={"job_id": job_id},
).json()
if status["status"] == "waiting_for_input":
data = next(
e["data"] for e in reversed(status["events"])
if e["event_type"] == "question"
)
answers = []
for q in data["questions"]:
print(f"Agent asks: {q['question']}")
if q.get("options"):
for i, opt in enumerate(q["options"]):
print(f" {i + 1}. {opt}")
ans = input("Your answer: ")
answers.append({
"question_id": q["question_id"],
"answer": ans,
})
# 3. Submit answers
requests.post(
f"{API}/jobs/my-org/insurance_form/answer",
headers=HEADERS,
params={"job_id": job_id},
json={
"batch_id": data["batch_id"],
"answers": answers,
},
)
continue
if status["status"] in ("completed", "failed", "stopped"):
print(f"Job finished: {status['status']}")
break
time.sleep(3)