Tasks

Define work for agents to complete

Tasks define specific work for agents to complete with clear objectives.

Diagram

Task Execution

👤 User

📋 Task

🤖 Agent

✅ Result

Quick Start

  1. Run a task through a team
    typescript
    import { Agent, Team } from 'praisonai';
    
    const team = new Team({
      agents: [new Agent({ instructions: 'You research and summarize topics' })],
      tasks: ['Research AI trends in 2024']
    });
    
    const results = await team.start();
    console.log(results[0]);
  2. With a Task object
    typescript
    import { Agent, Team } from 'praisonai';
    
    const analyst = new Agent({ instructions: 'You analyse data' });
    
    const team = new Team({
      agents: [analyst],
      tasks: [{
        name: 'analyse',
        description: 'Analyze sales data',
        expectedOutput: 'A summary with top 3 insights',
        agent: analyst
      }]
    });
    
    await team.start();

How a Task Runs

team.start() runs every task through the same pipeline, in this exact order.

Diagram

yes

no

hit

miss

Rerun gate

Dependency check

Start hooks

Resolve agent

handler?

Run handler

Assemble context

Memory + knowledge + images

Cache hit?

Complete

Run model with retries

Parse output + write memory

StepWhat happens
Rerun gateA re-queued completed task is skipped unless rerun (or execution.rerun) is set.
Dependency checkIf a dependsOn task failed, skipOnFailure marks this one degraded; otherwise it fails.
Start hooksTeam onTaskStart, then the task’s own hooks.onTaskStart.
Resolve agentWith no agent but an agentConfig, one is built at run time named <taskName>Agent.
handlerRuns instead of the model when provided.
ContextretainFullContext carries every earlier result; the default carries only the latest.
Memory + knowledgeRecalled and folded into the prompt.
ImagesPer-task images attach as multimodal image_url parts.
CacheA caching hit returns the stored answer and skips the retries.
RetriesretryDelay backs off min(delay * 2^attempt, 300) seconds.
OutputoutputPydantic / outputConfig.pydanticModel parse the answer and strip `json fences.
CompleteResult stored to memory, then team and task onTaskComplete hooks.

Task Options

Every option below changes what team.start() does.

Core

OptionTypeDefaultDescription
descriptionstring—What the task should accomplish.
expectedOutputstring"Complete the task successfully"Desired format of the result.
agentAgentnullAgent assigned to the task.
agentConfigobjectnullBuild an agent at run time when none is set.
dependsOn / contextTask[][]Tasks whose results feed this one.
handlerfunctionnullRun a function instead of the model.
hooks{ onTaskStart, onTaskComplete }nullPer-task lifecycle callbacks.
typescript
// task objects inside team.tasks
// handler runs instead of the model
{
  name: 'compute',
  description: 'add the numbers',
  handler: () => 'computed without an LLM'
}

// agentConfig builds `researchAgent` at run time
{
  name: 'research',
  description: 'research whales',
  agentConfig: { llm: 'gpt-4o-mini', instructions: 'be brief' }
}

Context, memory & knowledge

OptionTypeDefaultDescription
retainFullContextbooleanfalseCarry every earlier result, not just the latest.
memorystorenullRecall into the prompt and write the answer back.
failOnMemoryErrorbooleanfalseRe-throw memory failures instead of swallowing them.
config.memory_configobjectnullAuto-create a per-task memory store.
knowledge`string \string[] \base`nullFold matching knowledge into the prompt.
imagesstring[][]Attach pictures as multimodal parts.
typescript
// a task object inside team.tasks
{
  name: 'summarise',
  description: 'summarise whales',
  memory,                 // recalled into the prompt, answer written back
  retainFullContext: true,
  knowledge: 'penguins cannot fly'
}

Output

OptionTypeDefaultDescription
outputPydanticschemanullParse the answer into a typed object.
outputConfig{ pydanticModel }nullSame parsing through its own field.
typescript
// a task object inside team.tasks
{
  name: 'shape',
  description: 'shape it',
  outputPydantic: { type: 'object', properties: { title: { type: 'string' } } }
}

Execution & retries

OptionTypeDefaultDescription
asyncExecutionbooleanfalseBatch consecutive async tasks together.
cachingbooleanfalseServe a repeated prompt from cache.
rerunbooleanfalseRun again when the team reaches it a second time.
execution{ rerun }nullAlternate switch for rerun.
retryDelaynumber0Seconds to back off between attempts (doubles each retry).
skipOnFailurebooleanfalseRun even if a dependency failed.
typescript
// task objects inside team.tasks
{ name: 'alpha', description: 'alpha', asyncExecution: true }
{ name: 'quote', description: 'quote the price', caching: true, rerun: true }

Routing & loops

OptionTypeDefaultDescription
isStartbooleanfalseEntry point of a workflow graph.
nextTasksstring[][]Tasks to run after this one.
taskTypestring"task"'decision' drives the routing table.
routing / condition{ [decision]: string[] }nullRoute by the decision the model returned.
whenstringnullCondition gating thenTask / elseTask.
thenTask / elseTaskstringnullBranch targets.
loopOverstringnullVariable name of an array to fan out over.
loopVarstring"item"Placeholder each loop item binds to.
inputFilestringnullCSV file — one subtask per row.

Routing lives on Routing; loops live on Loops.

Human review

OptionTypeDefaultDescription
humanInputbooleanfalseRequire a person to approve the task’s output before the next task consumes it. See Human Review.
humanReviewPromptstring—Custom question the reviewer is asked.
typescript
// a task object inside team.tasks
{
  name: 'refund',
  description: 'draft a refund reply',
  humanInput: true,
  humanReviewPrompt: 'Is this legally safe to send?'
}

User Interaction Flow

Diagram
AgentTaskUserAgentTaskUserDefine taskAssign workExecuteCompleteResult

API Reference

TaskConfig

Task configuration options

Task

Task class documentation


Best Practices

Be specific in descriptions

“Write 500-word blog post about AI benefits” beats “Write about AI”.

Use handler for deterministic steps

A handler runs instead of the model — perfect for math, lookups, or calling your own code.

Chain tasks with dependsOn

Pass earlier tasks so their output feeds the next one.

Reach for caching on repeated prompts

caching: true skips the model entirely on a repeat.


Related