Skip to content

🀯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

27.6 KB
Raw Blame
import type { BuiltinToolManifest } from '@lobechat/types';

import { TASK_STATUSES, UNFINISHED_TASK_STATUSES } from './constants';
import { DEFAULT_LIST_TASK_LIMIT } from './listTasks';
import { systemPrompt } from './systemRole';
import { TaskApiName } from './types';

export const TaskIdentifier = 'lobe-task';

export const TaskManifest: BuiltinToolManifest = {
  api: [
    // ==================== Task CRUD ====================
    {
      description:
        'Create a new task. Optionally attach it as a subtask by specifying parentIdentifier.',
      name: TaskApiName.createTask,
      parameters: {
        properties: {
          instruction: {
            description: 'Detailed instruction for what the task should accomplish.',
            type: 'string',
          },
          assigneeAgentId: {
            description:
              'Optional agent ID to assign the task to. In task management context, omit it to create an unassigned task.',
            type: 'string',
          },
          assigneeUserId: {
            description:
              "Optional workspace member (user ID) to set as the task's human owner. Coexists with assigneeAgentId β€” the agent executes the task, the member owns the outcome. Resolve the ID with listWorkspaceMembers first; never guess it.",
            type: 'string',
          },
          labels: {
            description:
              'Optional existing task label names to attach (e.g. ["Bug", "Frontend"]; a grouped label may be written "Type/Bug"). Only use labels that already exist β€” unknown names fail with suggestions and nothing is created. A task carries at most one label per label group.',
            items: { type: 'string' },
            type: 'array',
          },
          model: {
            description:
              'Optional model ID this task runs with (e.g. "deepseek-chat"), instead of the assignee agent\'s default. Only set it when the user asks for a specific model. Omit to pin the assignee agent\'s current model.',
            type: 'string',
          },
          name: {
            description: 'A short, descriptive name for the task.',
            type: 'string',
          },
          parentIdentifier: {
            description:
              'Identifier of the parent task (e.g. "T-1"). If provided, the new task becomes a subtask. Accepts identifiers or ids returned by previous results; prefer stable ids.',
            type: 'string',
          },
          priority: {
            description: 'Priority level: 0=none, 1=urgent, 2=high, 3=normal, 4=low. Default is 0.',
            type: 'number',
          },
          provider: {
            description:
              'Provider ID for `model` (e.g. "lobehub", "openai"). Pass it together with model when known; omit to let the server resolve it from the assignee agent.',
            type: 'string',
          },
          sortOrder: {
            description:
              'Sort order within parent task. Lower values appear first. Use to control display order (e.g. chapter 1=0, chapter 2=1, etc.).',
            type: 'number',
          },
        },
        required: ['name', 'instruction'],
        type: 'object',
      },
      work: {
        action: 'create',
        resourceType: 'task',
      },
    },
    {
      description:
        'Create multiple tasks in a single call. Prefer this over multiple createTask calls when planning a batch of related tasks (e.g. all subtasks under one parent, or all chapters of an outline). Each item supports the same fields as createTask. Items are created sequentially in array order; failures on individual items do not abort the batch.',
      name: TaskApiName.createTasks,
      parameters: {
        properties: {
          tasks: {
            description:
              'Array of tasks to create. Each item is the same shape as the createTask parameters (name + instruction required, other fields optional).',
            items: {
              properties: {
                instruction: {
                  description: 'Detailed instruction for what the task should accomplish.',
                  type: 'string',
                },
                assigneeAgentId: {
                  description:
                    'Optional agent ID to assign the task to. In task management context, omit it to create an unassigned task.',
                  type: 'string',
                },
                assigneeUserId: {
                  description:
                    "Optional workspace member (user ID) to set as the task's human owner (coexists with assigneeAgentId). Resolve the ID with listWorkspaceMembers first.",
                  type: 'string',
                },
                labels: {
                  description:
                    'Optional existing task label names to attach (same rules as createTask.labels).',
                  items: { type: 'string' },
                  type: 'array',
                },
                model: {
                  description:
                    'Optional model ID this task runs with (e.g. "deepseek-chat"), instead of the assignee agent\'s default. Only set it when the user asks for a specific model. Omit to pin the assignee agent\'s current model.',
                  type: 'string',
                },
                name: {
                  description: 'A short, descriptive name for the task.',
                  type: 'string',
                },
                parentIdentifier: {
                  description:
                    'Identifier of the parent task (e.g. "T-1"). If provided, the new task becomes a subtask. Accepts identifiers or ids returned by previous results; prefer stable ids.',
                  type: 'string',
                },
                priority: {
                  description:
                    'Priority level: 0=none, 1=urgent, 2=high, 3=normal, 4=low. Default is 0.',
                  type: 'number',
                },
                provider: {
                  description:
                    'Provider ID for `model` (e.g. "lobehub", "openai"). Pass it together with model when known; omit to let the server resolve it from the assignee agent.',
                  type: 'string',
                },
                sortOrder: {
                  description:
                    'Sort order within parent task. Lower values appear first. Use to control display order.',
                  type: 'number',
                },
              },
              required: ['name', 'instruction'],
              type: 'object',
            },
            type: 'array',
          },
        },
        required: ['tasks'],
        type: 'object',
      },
      work: {
        action: 'create',
        resourceType: 'task',
      },
    },
    {
      description:
        'List tasks. Without any filters, returns top-level unfinished tasks. In agent conversations it defaults to the current agent; in task manager context it spans all agents. If you provide any filter, omitted filters are not applied implicitly.',
      name: TaskApiName.listTasks,
      parameters: {
        properties: {
          assigneeAgentId: {
            description:
              'Restrict to tasks assigned to this agent. When omitted, no assignee filter is applied unless listTasks is called without any filters in an agent conversation, which defaults to the current agent.',
            type: 'string',
          },
          labels: {
            description:
              'Only tasks carrying any of these existing label names. A label group name (e.g. "Type") matches any label in that group.',
            items: { type: 'string' },
            type: 'array',
          },
          limit: { description: `Max 1-100. Default ${DEFAULT_LIST_TASK_LIMIT}.`, type: 'number' },
          offset: { description: 'Pagination offset.', type: 'number' },
          parentIdentifier: {
            description:
              'List subtasks of this parent (e.g. "T-1"). When omitted, no parent filter is applied unless listTasks is called without any filters, which defaults to top-level tasks. Accepts identifiers or ids returned by previous results; prefer stable ids.',
            type: 'string',
          },
          priorities: {
            description: 'Filter by priority values. 0=none, 1=urgent, 2=high, 3=normal, 4=low.',
            items: { enum: [0, 1, 2, 3, 4], type: 'number' },
            type: 'array',
          },
          statuses: {
            description: `Filter by statuses. When omitted, no status filter is applied unless listTasks is called without any filters, which defaults to [${UNFINISHED_TASK_STATUSES.map((s) => `"${s}"`).join(', ')}].`,
            items: {
              enum: [...TASK_STATUSES],
              type: 'string',
            },
            type: 'array',
          },
        },
        required: [],
        type: 'object',
      },
    },
    {
      description:
        'List the workspace members a task can be assigned to, with their user IDs, emails and, where available, linked IM identities (Discord/Slack/Telegram handles and platform user ids). Call this before setting assigneeUserId on createTask / createTasks / editTask so a person named by the user ("assign this to Alice", "assign to @neko", a `<@platformUserId>` mention) is resolved to a real ID instead of guessed β€” prefer an exact im/email match over name similarity. Pass `query` to narrow a large directory; the result is capped by `limit`, so refine the query rather than paging. Outside a workspace only the current user is returned.',
      name: TaskApiName.listWorkspaceMembers,
      parameters: {
        properties: {
          limit: {
            description: 'Maximum number of members to return (default 50, max 100).',
            type: 'number',
          },
          query: {
            description:
              'Case-insensitive filter matched against display name, @handle, email, linked IM identity, or an exact user ID. Native mentions may be passed as-is (`<@U123>`, `<@!4521>`). Omit to list the whole (capped) directory.',
            type: 'string',
          },
        },
        required: [],
        type: 'object',
      },
    },
    {
      description:
        'View details of a specific task. If identifier is omitted, this only works when there is a current task context.',
      name: TaskApiName.viewTask,
      parameters: {
        properties: {
          identifier: {
            description:
              'The task identifier to view (e.g. "T-1"). If omitted, the current task is used only when a current task context exists. Accepts identifiers or ids returned by previous results; prefer stable ids.',
            type: 'string',
          },
        },
        required: [],
        type: 'object',
      },
    },
    // ==================== Task Comments ====================
    {
      description:
        'Add a comment to a task. If identifier is omitted, this only works when there is a current task context. Use comments to record decisions, progress, or feedback that should appear in task activities.',
      name: TaskApiName.addTaskComment,
      parameters: {
        properties: {
          content: {
            description:
              'Comment content to add to the task (markdown). To notify a workspace member who needs to act, mention them with <mention name="Name" id="user_xxx" />, resolving the id with listWorkspaceMembers first (never guess it); a plain "@Name" is only text.',
            type: 'string',
          },
          identifier: {
            description:
              'The task identifier to comment on (e.g. "T-1"). If omitted, the current task is used only when a current task context exists. Accepts identifiers or ids returned by previous results; prefer stable ids.',
            type: 'string',
          },
        },
        required: ['content'],
        type: 'object',
      },
    },
    {
      description:
        'Update an existing task comment by commentId. Use viewTask to inspect task activities and find comment ids.',
      name: TaskApiName.updateTaskComment,
      parameters: {
        properties: {
          commentId: {
            description: 'The task comment id to update.',
            type: 'string',
          },
          content: {
            description:
              'Updated comment content (markdown). Newly added <mention name="Name" id="user_xxx" /> tags notify those members; resolve ids with listWorkspaceMembers.',
            type: 'string',
          },
        },
        required: ['commentId', 'content'],
        type: 'object',
      },
    },
    {
      description:
        'Delete an existing task comment by commentId. Use viewTask to inspect task activities and find comment ids.',
      name: TaskApiName.deleteTaskComment,
      parameters: {
        properties: {
          commentId: {
            description: 'The task comment id to delete.',
            type: 'string',
          },
        },
        required: ['commentId'],
        type: 'object',
      },
    },
    {
      description:
        "Edit a task's fields (name, description, instruction, priority, model/provider), assignee (agent or workspace member), parent, labels, or dependencies (batched). Status changes go through updateTaskStatus; schedule configuration goes through setTaskSchedule.",
      name: TaskApiName.editTask,
      parameters: {
        properties: {
          addDependencies: {
            description:
              'Identifiers of tasks this task should block on (e.g. ["T-2", "T-3"]). Accepts identifiers or ids returned by previous results; prefer stable ids.',
            items: { type: 'string' },
            type: 'array',
          },
          addLabels: {
            description:
              'Existing task label names to add (e.g. ["Bug"]; "Type/Bug" also works). Adding a label from a label group replaces the task\'s current label of that group. Unknown names fail with suggestions; labels are never created.',
            items: { type: 'string' },
            type: 'array',
          },
          assigneeAgentId: {
            description:
              'Assign the task to this agent ID (the executing agent; independent of the human owner). Pass null to clear the agent assignee.',
            type: ['string', 'null'],
          },
          assigneeUserId: {
            description:
              "Set this workspace member (user ID) as the task's human owner. Independent of assigneeAgentId β€” both can be set, and touching one never clears the other. Resolve the ID with listWorkspaceMembers first; never guess it. Pass null to clear the human owner.",
            type: ['string', 'null'],
          },
          description: {
            description:
              'Human-readable description (displayed in UI). Separate from instruction, which guides the agent.',
            type: 'string',
          },
          identifier: {
            description:
              'The identifier of the task to edit. Accepts identifiers or ids returned by previous results; prefer stable ids.',
            type: 'string',
          },
          instruction: {
            description: 'Updated instruction for the task.',
            type: 'string',
          },
          model: {
            description:
              "Model ID this task should run with from now on. Pass null to clear the override so the next run uses the assignee agent's model. Pass provider alongside when known; a model without provider has its provider resolved from the assignee agent.",
            type: ['string', 'null'],
          },
          name: {
            description: 'Updated name for the task.',
            type: 'string',
          },
          parentIdentifier: {
            description:
              'Set the parent task by identifier (e.g. "T-1"). Pass null to move this task to top level. Omit to keep the current parent. Accepts identifiers or ids returned by previous results; prefer stable ids.',
            type: ['string', 'null'],
          },
          priority: {
            description: 'Updated priority level: 0=none, 1=urgent, 2=high, 3=normal, 4=low.',
            type: 'number',
          },
          provider: {
            description:
              'Provider ID for the task model (e.g. "lobehub", "openai"). Pass null to clear it.',
            type: ['string', 'null'],
          },
          removeDependencies: {
            description:
              'Identifiers of existing dependencies to remove. Accepts identifiers or ids returned by previous results; prefer stable ids.',
            items: { type: 'string' },
            type: 'array',
          },
          removeLabels: {
            description: 'Task label names to remove from the task.',
            items: { type: 'string' },
            type: 'array',
          },
        },
        required: ['identifier'],
        type: 'object',
      },
      work: {
        action: 'update',
        resourceType: 'task',
      },
    },
    {
      description:
        'Trigger an actual run of a task β€” this kicks off the assigned agent in a new (or continued) topic. Use this to START tasks; do NOT use updateTaskStatus(running) to start a task, that only flips the status flag without actually executing anything. The task must already have an assigneeAgentId; if not, edit the task to assign one first. If the task already has a live run, this fails with a CONFLICT error naming the operation behind that run, its status and the next step; a run whose operation ended long ago is cleaned up and no longer blocks. Running a scheduled task by hand works as a test tick: it does not count toward maxExecutions, and the task returns to scheduled afterwards.',
      name: TaskApiName.runTask,
      parameters: {
        properties: {
          continueTopicId: {
            description:
              'Optional id of an existing topic to continue. When omitted, a new topic is created.',
            type: 'string',
          },
          identifier: {
            description:
              'The task identifier to run (e.g. "T-1"). Accepts identifiers or ids returned by previous results; prefer stable ids.',
            type: 'string',
          },
          model: {
            description:
              "A task stays on the model pinned when it was created; changing the agent's model later does not move it. Set this only when the user names the model to use; never pick one yourself. It replaces the pin once the run starts, so later runs stay on it.",
            type: 'string',
          },
          prompt: {
            description:
              'Optional extra prompt prepended to the task instruction for this run only.',
            type: 'string',
          },
          provider: {
            description:
              "Provider of model. Requires model. When omitted, the assignee agent's provider is used without checking that it serves model.",
            type: 'string',
          },
        },
        required: ['identifier'],
        type: 'object',
      },
    },
    {
      description:
        'Trigger runs for multiple tasks in a single call. Prefer this over multiple runTask calls when starting a batch of related subtasks (e.g. all subtasks you just created under one parent). Each task is started sequentially in array order; failures on individual tasks do not abort the batch.',
      name: TaskApiName.runTasks,
      parameters: {
        properties: {
          identifiers: {
            description:
              'Identifiers of tasks to run, in execution order (e.g. ["T-1", "T-2"]). Accepts identifiers or ids returned by previous results; prefer stable ids.',
            items: { type: 'string' },
            type: 'array',
          },
          model: {
            description:
              "Applied to every task in the batch. A task stays on the model pinned when it was created; changing the agent's model later does not move it. Set this only when the user names the model to use; never pick one yourself. It replaces the pin once the run starts, so later runs stay on it.",
            type: 'string',
          },
          provider: {
            description:
              "Provider of model. Requires model. When omitted, the assignee agent's provider is used without checking that it serves model.",
            type: 'string',
          },
        },
        required: ['identifiers'],
        type: 'object',
      },
    },
    {
      description:
        'Configure (or clear) the recurring schedule of a task. Use this to turn a task into a periodically running one, switch between cron (`schedule`) and fixed-interval (`heartbeat`) automation, or disable automation entirely. Pass automationMode=null to stop the task from auto-running. For schedule mode, supply schedulePattern (cron) and scheduleTimezone (IANA). For heartbeat mode, supply heartbeatInterval (seconds). maxExecutions caps how many scheduled runs may fire (null = unlimited). Status changes still go through updateTaskStatus; this tool only touches schedule configuration.',
      name: TaskApiName.setTaskSchedule,
      parameters: {
        properties: {
          automationMode: {
            description:
              'Enables periodic execution. "schedule" fires on the cron `schedulePattern`; "heartbeat" ticks every `heartbeatInterval` seconds. Pass null to disable automation entirely.',
            enum: ['heartbeat', 'schedule', null],
            type: ['string', 'null'],
          },
          heartbeatInterval: {
            description:
              'Periodic execution interval in seconds (heartbeat mode). Pass 0 to clear the interval. Minimum 600s (10 minutes); the server rejects positive values below 600.',
            type: 'number',
          },
          identifier: {
            description:
              'The identifier of the task to configure (e.g. "T-1"). Accepts identifiers or ids returned by previous results; prefer stable ids.',
            type: 'string',
          },
          maxExecutions: {
            description:
              'Cap on the number of scheduled executions for this task. Pass null to remove the cap (run indefinitely).',
            type: ['number', 'null'],
          },
          schedulePattern: {
            description:
              'Standard 5-field cron expression "minute hour day-of-month month day-of-week" for scheduled mode, e.g. "0 9 * * *" (every day at 09:00), "30 9 * * 1-5" (weekdays at 09:30) or "0 10 27 9 *" (Sep 27 at 10:00; pair with maxExecutions=1 for a one-off). Invalid patterns are rejected; on success the result lists the next run times β€” check them against what the user asked for. Pass null to clear the pattern.',
            type: ['string', 'null'],
          },
          scheduleTimezone: {
            description:
              'IANA timezone for the cron expression, e.g. "Asia/Shanghai" or "America/New_York". Pass null to clear; defaults to UTC when unset.',
            type: ['string', 'null'],
          },
        },
        required: ['identifier'],
        type: 'object',
      },
      work: {
        action: 'update',
        resourceType: 'task',
      },
    },
    {
      description:
        'Configure (or clear) a task\'s delivery-acceptance (verify) gate β€” the evidence-driven check that runs when the task\'s topic completes, so the assigned agent\'s "done" is verified by a separate reviewer instead of blindly trusted. STRONGLY RECOMMENDED whenever you dispatch an executable task to another agent (assigneeAgentId set): turn the gate on with enabled=true and state a one-sentence `requirement` describing what "done" means; the server synthesizes acceptance criteria from it. Pass verifyRubricId to reuse a saved rubric, or verifyCriteriaIds for explicit criteria. Pass null to any field to clear it; omitted fields are left untouched.',
      name: TaskApiName.setTaskVerify,
      parameters: {
        properties: {
          enabled: {
            description:
              'Whether the verify gate runs when the task completes. Pass true to require verification, false to disable, null to clear.',
            type: ['boolean', 'null'],
          },
          identifier: {
            description:
              'The identifier of the task to configure (e.g. "T-1"). Accepts identifiers or ids returned by previous results; prefer stable ids.',
            type: 'string',
          },
          maxIterations: {
            description:
              'Cap on verify repair / re-run iterations (1-10). Pass null to clear (uses the default).',
            type: ['number', 'null'],
          },
          requirement: {
            description:
              'One-sentence acceptance requirement describing what "done" means for this task (e.g. "All unit tests pass and the new endpoint returns 200"). The server synthesizes acceptance criteria from it when no explicit criteria are given. Pass null to clear.',
            type: ['string', 'null'],
          },
          verifierAgentId: {
            description:
              'Agent ID that executes the verify run. Omit to use the built-in verify agent. Pass null to clear an existing value.',
            type: ['string', 'null'],
          },
          verifyCriteriaIds: {
            description:
              'Explicit acceptance criteria ids to check against. Pass null to clear; omit when relying on requirement-synthesized criteria.',
            items: { type: 'string' },
            type: ['array', 'null'],
          },
          verifyRubricId: {
            description:
              'Reuse a saved rubric template by id instead of ad-hoc criteria. Pass null to clear.',
            type: ['string', 'null'],
          },
        },
        required: ['identifier'],
        type: 'object',
      },
      work: {
        action: 'update',
        resourceType: 'task',
      },
    },
    {
      description:
        "Update a task's status. Use to mark tasks as completed, canceled, paused, resumed, or failed. To START a task (transition into running), use runTask β€” it actually launches the agent. updateTaskStatus only flips the status flag without execution. If identifier is omitted, this only works when there is a current task context.",
      name: TaskApiName.updateTaskStatus,
      parameters: {
        properties: {
          error: {
            description: 'Failure reason to store on the task. Only valid when status is "failed".',
            type: 'string',
          },
          identifier: {
            description:
              'The task identifier (e.g. "T-1"). If omitted, the current task is used only when a current task context exists. Accepts identifiers or ids returned by previous results; prefer stable ids.',
            type: 'string',
          },
          status: {
            description:
              'New status for the task. Use error only when setting the status to failed.',
            enum: [...TASK_STATUSES],
            type: 'string',
          },
        },
        required: ['status'],
        type: 'object',
      },
    },
    {
      description:
        'Delete a task by identifier. The task moves to the recycle bin together with its topics, and the user can restore it within 30 days; it is removed for good when the bin is emptied or the retention window ends. Subtasks are NOT cascaded β€” they stay in the list. A dependency on the deleted task stops blocking its dependents.',
      name: TaskApiName.deleteTask,
      parameters: {
        properties: {
          identifier: {
            description:
              'The identifier of the task to delete (e.g. "T-1"). Accepts identifiers or ids returned by previous results; prefer stable ids.',
            type: 'string',
          },
        },
        required: ['identifier'],
        type: 'object',
      },
      work: {
        action: 'delete',
        resourceType: 'task',
      },
    },
  ],
  identifier: TaskIdentifier,
  meta: {
    avatar: '\uD83D\uDCCB',
    description: 'Create, list, edit, comment on, and delete tasks with dependencies',
    title: 'Task Tools',
  },
  systemRole: systemPrompt,

  type: 'builtin',
};