Runtime Options
As mentioned in Task Registration page tasks can be configured with different options during registration.
However, in some cases, task options need to be determined at runtime depending on the request parameters (e.g. items count, AI model, etc...).
To support this you can override the TaskExecutor::options method and resolve TaskOptions dynamically.
@Executor("example-task")
export class ExampleExecutor implements TaskExecutor {
async options(exampleCommand: ExampleCommand): Promise<TaskOptions> {
const toolId = exampleCommand.model === 'model1' ?
'model1_tool_id' : 'default_toolId';
const totalUsageAmount = countTotalToolUsageAmount();
return {
monetization: {
toolId
},
usageAmount: totalUsageAmount,
}
}
}
note
To enable the above implementation, make sure the task has enablePreflight set to true.
note
When a task is invoked as a charged sub-task (its caller has enableSubTaskCredits: true or passes chargeCredits: true), options() is called regardless of enablePreflight, and any toolId / usageAmount it returns will be used.