Aha.. that is the question

.
Well, you're in luck. It used to be more difficult in the days, but now it's quite simple.
First, you need to go into \STEAM\steamapps\common\assettocorsa\system\cfg and edit the file called assetto_corsa.ini.
Code:
[AC_APPS]
ENABLE_DEV_APPS=1
Once this is done, go into the game, onto your track, with any car.
1/ Open the in-game app (it will be visible now) named
AI. It looks like this
:
View attachment 681
2/ When ready, press "
start recording" button (the button under will change to recording)
3/ And start driving

. No need to go insanely fast, but more important is to have a nice flowing line. Whenever you complete a lap while recording, the line is updated (<< thanks to NightEye for the tip).
4/ Drive a least two laps! Save and exit whenever you think you've got a good line. Here's how:
5/ Hit ESC for the menu and click "Exit".
(edit - if this doesnt work: Press the "recording" to stop the recording process. Press Save ai.)
Now AC can be unresponsive for some time, depending on track length. After that you should now have a "fast_lane.ai.candidate" file under YOURTRACK\ai\ folder (or YOURTRACK\layout\ai\ ).
7/ Rename the file to "fast_lane.ai".
Also make a copy of it to "\data\ideal_line.ai" (or make a second one)
(prefered ideal line shown in game and used for ai fuel calcs)
8/ Done - you should now have a working AI

.
***
Optionally, you also need to record a pit_lane.ai path. Procedure is similar, but with 2 differences:
1/ press the "start pits", instead of the normal "start recording" used previously

2/ start at the last turn before pit entry, and end it after pit exit once you've joined the racing line (the idea is to make sort of a "deviation" from the main racing line).
If all this doesnt work: check position of AC_TIME... gates and make sure you don't run over invalid track surfaces while recording.