ctx.ai
Use ctx.ai in RunJS to trigger AI employee tasks. It works well in JSBlock, JSAction, and other interactions where a button, form, or business flow needs to hand work to a specific AI employee.
ctx.ai only triggers tasks. It does not return the execution result of the AI employee task. After the call, the task enters the AI employee conversation flow, and the result is handled by the AI employee session.
ctx.ai is provided by the AI plugin. If the AI plugin is not enabled, or the current RunJS environment has not loaded the corresponding client capability, ctx.ai may not exist. You can check ctx.ai?.triggerTask or ctx.ai?.triggerModelTask before calling it.
Methods
ctx.ai.triggerTask()
Trigger an AI employee task directly.
Common Task fields:
Add Page Block Context
message.workContext currently passes page blocks. Put the FlowModel uid of the target page block into it:
If you want to use the current JSBlock itself as context, use the current model uid:
Usually, message.workContext should be placed inside the message of a concrete task. triggerModelTask() reuses the task configured on the target AI employee action, so it also reads message.workContext from that task.
Specify Model
model specifies the model for a single task. If omitted, the AI employee's default model configuration is used. Passing null means no task-level model is specified.
Configure Skills / Tools
skillSettings specifies the skills and tools available to a single task. If omitted, the AI employee's own capability configuration is used.
To explicitly disable all skills or tools for this task, pass empty arrays and keep the version fields:
The following example asks viz to generate a handoff brief and opens the AI employee conversation panel:
If aiEmployee is a string, NocoBase matches accessible AI employees by username exactly. If no match is found, the task is not triggered and a warning is printed to the console.
ctx.ai.triggerModelTask()
Read a task from an AI employee action model on the page and trigger it.
This method reads the AI employee and task configuration from the target model. It is useful when the task has already been configured on an AI employee action on the page, and RunJS only needs to trigger it.
If the target model does not exist, has no AI employee configured, or the specified index has no task, no task is triggered and a warning is printed to the console.
Which Method to Use
Notes
triggerTask()andtriggerModelTask()are fire-and-forget. They do not return the execution result of the AI employee task.aiEmployeestrings only matchAIEmployee.usernameexactly. They do not match nicknames, job titles, or translated names.triggerModelTask()uses a0-basedtaskIndex.triggerModelTask()reads task configuration from the target AI employee action model. If the task needs work context, configuremessage.workContexton that task.
Related
- ctx.message: Show lightweight prompts before and after triggering tasks.
- ctx.render: Render buttons or forms in JSBlock.
- ctx.model: Get current FlowModel information.

