Create, manage, and track discrete units of work for agents
Tasks enable agents to break down complex objectives into manageable units of work, track progress, and coordinate execution across multiple steps and agents.
The Tasks primitive provides a structured way to define, assign, execute, and monitor discrete units of work. Unlike workflows which define processes, tasks represent individual actionable items that can be tracked, prioritized, and completed independently or as part of larger objectives.Tasks are essential for:
Work Breakdown: Decompose complex goals into manageable chunks
Progress Tracking: Monitor completion status and progress
Prioritization: Organize work by importance and urgency
Delegation: Assign tasks to specific agents or humans
Dependencies: Define task relationships and execution order
Accountability: Track who did what and when
Task Creation
Agents can create tasks autonomously or from user requests
import { Agentbase } from '@agentbase/sdk';const agentbase = new Agentbase({ apiKey: process.env.AGENTBASE_API_KEY});// Agent creates tasks autonomouslyconst result = await agentbase.runAgent({ message: "Plan the launch of our new product next month", capabilities: { tasks: { enabled: true } }, system: `Break down the product launch into specific tasks. For each task: - Clear, actionable description - Appropriate priority - Estimated duration - Required resources - Dependencies on other tasks`});// Agent creates structured task listconsole.log('Tasks created:', result.tasks);
// Assign task and let agent complete itconst result = await agentbase.runAgent({ message: "Complete task: Write blog post about new features", taskId: task.id, capabilities: { tasks: { enabled: true, autoUpdate: true // Automatically update task status } }});// Agent works on task and updates statusconsole.log('Task status:', result.task.status);console.log('Task result:', result.task.result);
const projectAgent = await agentbase.runAgent({ message: "Plan the development of our mobile app", capabilities: { tasks: { enabled: true } }, system: `Create a comprehensive task breakdown for mobile app development. Include tasks for: - Requirements gathering - Design (UI/UX) - Frontend development - Backend API development - Testing (unit, integration, E2E) - Deployment - Documentation For each task: - Assign to appropriate team/agent - Set realistic estimates - Define dependencies - Specify acceptance criteria`});// Agent creates structured project plan with tasks
const contentTasks = await agentbase.runAgent({ message: "Create tasks for this month's blog content", capabilities: { tasks: { enabled: true } }, system: `Create tasks for 4 blog posts this month. For each post: 1. Research topic (priority: high) 2. Draft content (depends on research) 3. Create graphics (depends on draft) 4. SEO optimization (depends on draft) 5. Editorial review (depends on all above) 6. Publish (depends on review approval) Stagger due dates throughout the month.`});
const standupAgent = await agentbase.runAgent({ message: "Generate my standup update", capabilities: { tasks: { enabled: true } }, system: `Create standup update based on my tasks: Yesterday: - List completed tasks - Note any blockers Today: - List in-progress tasks - Highlight priorities Blockers: - List any blocked tasks - Identify what's needed to unblock Format as concise standup message.`});
// Good: Specific, single-purpose tasksawait agentbase.createTask({ title: "Write introduction section", description: "Draft the introduction for the blog post (200-300 words)"});await agentbase.createTask({ title: "Create featured image", description: "Design featured image for blog post (1200x630px)"});// Avoid: Overly broad tasksawait agentbase.createTask({ title: "Complete blog post", description: "Do everything for the blog post"});
Review Tasks Regularly: Set up periodic reviews of task lists to update priorities and remove obsolete tasks.
Prioritize Effectively
Copy
system: `Prioritize tasks using:Critical: System down, security breach, data lossHigh: Blocking other work, customer-facing issuesMedium: Important but not urgentLow: Nice to have, future improvementsConsider:- Business impact- Dependencies- Deadlines- Resource availability`
Handle Blocked Tasks
Copy
// Mark task as blockedawait agentbase.updateTask(taskId, { status: "blocked", blockReason: "Waiting for design approval", blockedBy: designTaskId, blockedUntil: "2024-02-10"});// Automatically unblock when dependency completes
Track Time and Progress
Copy
// Update progress regularlyawait agentbase.updateTask(taskId, { progress: 0.75, timeSpent: 6, // hours notes: "API implementation complete, working on tests"});
Archive Completed Tasks
Copy
// Periodically archive old completed tasksasync function archiveOldTasks() { const oldTasks = await agentbase.getTasks({ status: "completed", completedBefore: "2024-01-01" // Older than 30 days }); for (const task of oldTasks) { await agentbase.archiveTask(task.id); }}
// Assign based on expertiseconst task = await agentbase.createTask({ title: "Optimize database queries", assignee: "database_specialist_agent", ccUsers: ["team_lead", "backend_team"]});// Or let agent decidemessage: "Assign this task to the best team member",system: "Consider workload, expertise, and availability"