SESSION_JSON=$(curl --fail-with-body -sS "$BASE_URL/api/v1/agent-sessions" \
-H "X-API-Key: $AGENTSCOPE_API_KEY" -H 'Content-Type: application/json' \
-H 'Idempotency-Key: scheduled-research-session-001' \
--data "$(jq -n --arg id "$AGENT_ID" '{target:{type:"agent",id:$id}}')")
SESSION_ID=$(printf '%s' "$SESSION_JSON" | jq -er '.id')
SESSION_URL="$BASE_URL/api/v1/agent-sessions/$SESSION_ID"
TURN_JSON=$(curl --fail-with-body -sS "$SESSION_URL/turns" \
-H "X-API-Key: $AGENTSCOPE_API_KEY" -H 'Content-Type: application/json' \
-H 'Idempotency-Key: scheduled-research-task-001' \
--data "$(jq '{message:(.message // (.input | tojson))}' input.json)")
TURN_ID=$(printf '%s' "$TURN_JSON" | jq -er '.id')
curl --fail-with-body -sS "$SESSION_URL/turns/$TURN_ID" \
-H "X-API-Key: $AGENTSCOPE_API_KEY"