For more detailed usage information, please refer to our cookbook: Task Generation Cookbook

What is a Task in CAMEL?

A task in CAMEL is a structured assignment that can be given to one or more agents. Tasks are higher-level than prompts and managed by modules like the Planner and Workforce. Key ideas:

  • Tasks can be collaborative, requiring multiple agents.
  • Tasks can be decomposed into subtasks or evolved over time.

Task Attributes

AttributeTypeDescription
contentstringA clear and concise description of the task at hand.
idstringA unique string identifier for the task.
stateEnumThe task states: “OPEN”, “RUNNING”, “DONE”, “FAILED”, “DELETED”.
typestringThe type of a task. (TODO)
parentTaskThe parent task.
subtasksA list of TaskSubtasks related to the original Task.
resultstringThe Task result.

Task Methods

MethodTypeDescription
from_messageclassmethodLoad Task from Message.
to_messageclassmethodConvert Task to Message.
resetinstanceReset Task to initial state.
update_resultinstanceSet task result and mark the task as DONE.
set_idinstanceSet task id.
set_stateinstanceRecursively set the state of the task and its subtasks.
add_subtaskinstanceAdd a child task.
remove_subtaskinstanceDelete a subtask by id.
get_running_taskinstanceGet a RUNNING task.
to_stringinstanceConvert task to a string.
get_resultinstanceGet task result as a string.
decomposeinstanceDecompose a task to a list of subtasks.
composeinstanceCompose task result by subtasks.
get_depthinstanceGet task depth; root depth is 1.

Getting Started: Creating Tasks

Defining a task is simple: specify its content and a unique ID.

from camel.tasks import Task

task = Task(
    content="Weng earns $12 an hour for babysitting. Yesterday, she just did 51 minutes of babysitting. How much did she earn?",
    id="0",
)

Hierarchical Tasks Example

You can build nested, hierarchical tasks using subtasks. Here’s an example:

# Creating the root task
root_task = Task(content="Prepare a meal", id="0")

# Creating subtasks for the root task
sub_task_1 = Task(content="Shop for ingredients", id="1")
sub_task_2 = Task(content="Cook the meal", id="2")
sub_task_3 = Task(content="Set the table", id="3")

# Creating subtasks under "Cook the meal"
sub_task_2_1 = Task(content="Chop vegetables", id="2.1")
sub_task_2_2 = Task(content="Cook rice", id="2.2")

# Adding subtasks to their respective parent tasks
root_task.add_subtask(sub_task_1)
root_task.add_subtask(sub_task_2)
root_task.add_subtask(sub_task_3)

sub_task_2.add_subtask(sub_task_2_1)
sub_task_2.add_subtask(sub_task_2_2)

# Printing the hierarchical task structure
print(root_task.to_string())

Decomposing and Composing a Task

You can break down (decompose) a task into smaller subtasks, or compose the results from subtasks. Typically, you define an agent, prompt template, and response parser.

from camel.agents import ChatAgent
from camel.tasks import Task
from camel.tasks.task_prompt import (
    TASK_COMPOSE_PROMPT,
    TASK_DECOMPOSE_PROMPT,
)
from camel.messages import BaseMessage

sys_msg = BaseMessage.make_assistant_message(
    role_name="Assistant", content="You're a helpful assistant"
)
# Set up an agent
agent = ChatAgent(system_message=sys_msg)

task = Task(
    content="Weng earns $12 an hour for babysitting. Yesterday, she just did 51 minutes of babysitting. How much did she earn?",
    id="0",
)

new_tasks = task.decompose(agent=agent)
for t in new_tasks:
    print(t.to_string())
# Compose task result by the sub-tasks.
task.compose(agent=agent, template=TASK_COMPOSE_PROMPT)
print(task.result)

TaskManager

TaskManager Overview

The TaskManager class helps you manage, sort, and evolve tasks—handling dependencies and progression automatically.

MethodTypeDescription
topological_sortinstanceSort a list of tasks topologically.
set_tasks_dependenceinstanceSet relationship between root task and other tasks (serial or parallel).
evolveinstanceEvolve a task to a new task; used for data generation.
from camel.tasks import (
    Task,
    TaskManager,
)
from camel.agents import ChatAgent

sys_msg = "You're a helpful assistant"
agent = ChatAgent(system_message=sys_msg)

task = Task(
    content="Weng earns $12 an hour for babysitting. Yesterday, she just did 51 minutes of babysitting. How much did she earn?",
    id="0",
)
print(task.to_string())
task_manager = TaskManager(task)
evolved_task = task_manager.evolve(task, agent=agent)
print(evolved_task.to_string())

Conclusion

CAMEL offers a powerful, structured approach to task management. With support for task decomposition, composition, and deep hierarchies, you can automate everything from simple workflows to complex, multi-agent projects. Efficient, collaborative, and easy to integrate—this is next-level task orchestration for AI.