how to assign a task using a custom function

how to assign a task using a custom function

Hi there,

I am using a custom function to assign leads in a round-robin manner. Now I have a workflow that creates and assigns a "Contact Lead" task to the lead owner. But now that I am using a custom function to assign a lead, this workflow assigns this task to the lead creator. Now I want to add this functionality to the existing code. Now that we have the template for this task in the Tasks section, how can I fill in all the details and assign this task to the correct owner? Attaching screenshot of the task for reference: