Tasks

Tasks

Tasks are actions that your agents can perform on a schedule or on-demand.

Creating a task

To create a task, we can use the built-in ability and added it to our agent.

// Create a new task const conversation = await cbk.conversation.complete(null, { inlineSkillset: { abilities: [ { name: "Create Task", description: "Create a task using details provided", instruction: `template: task/create`, }, ], }, text:"Can you create a task that reminds me to drink water everyday?" });

typescript

Updating a task

To update a task, you can use the updateTask ability with the task ID and the properties you want to modify. This allows you to change the task name, schedule, or enabled status. The example below demonstrates how to update an existing task with a new name and schedule:

// Update an existing task const conversation = await cbk.conversation.complete(null, { inlineSkillset: { abilities: [ { name: "Update Task", description: "Update an existing task or to-do item", instruction: `template: task/update`, }, ], }, text: "Update my water reminder to run every 30 min.", });

typescript

Deleting a task

To delete a task, you can use the deleteTask ability with the task ID. This removes the task from the system and stops any scheduled executions. The example below shows how to delete an existing task:

// Delete a task const conversation = await cbk.conversation.complete(null, { inlineSkillset: { abilities: [ { name: "Delete Task", description: "Delete an existing task", instruction: `template: task/delete`, }, ], }, text: "Delete my water reminder task.", });

typescript

Running a Task

To run a task immediately without waiting for its scheduled time, you can use the runTask ability. This is useful for testing tasks or when you need to execute a task on-demand. The example below shows how to trigger an immediate task execution:

// Run a task immediately const conversation = await cbk.conversation.complete(null, { inlineSkillset: { abilities: [ { name: "Run Task", description: "Perform a single run of a task using the provided task ID", instruction: `template: task/run`, }, ], }, text: "Do I have to drink water soon?", });

typescript

Best Practices

  • Always validate schedule expressions before creating tasks
  • Include error handling for task operations
  • Monitor task execution status and logs
  • Use meaningful task names for easy identification
  • Keep task templates modular and reusable