跳到主要内容

openhands.controller.state.task

Task Objects

class Task()

__init__

def __init__(parent: 'Task',
goal: str,
state: str = OPEN_STATE,
subtasks=None)

Initializes a new instance of the Task class.

Arguments:

  • parent - The parent task, or None if it is the root task.
  • goal - The goal of the task.
  • state - The initial state of the task.
  • subtasks - A list of subtasks associated with this task.

to_string

def to_string(indent='')

Returns a string representation of the task and its subtasks.

Arguments:

  • indent - The indentation string for formatting the output.

Returns:

A string representation of the task and its subtasks.

to_dict

def to_dict()

Returns a dictionary representation of the task.

Returns:

A dictionary containing the task's attributes.

set_state

def set_state(state)

Sets the state of the task and its subtasks.

Args: state: The new state of the task.

Raises:

  • TaskInvalidStateError - If the provided state is invalid.

get_current_task

def get_current_task() -> 'Task | None'

Retrieves the current task in progress.

Returns:

The current task in progress, or None if no task is in progress.

RootTask Objects

class RootTask(Task)

Serves as the root node in a tree of tasks. Because we want the top-level of the root_task to be a list of tasks (1, 2, 3, etc.), the "root node" of the data structure is kind of invisible--it just holds references to the top-level tasks.

Attributes:

  • id - Kept blank for root_task
  • goal - Kept blank for root_task
  • parent - None for root_task
  • subtasks - The top-level list of tasks associated with the root_task.
  • state - The state of the root_task.

__str__

def __str__()

Returns a string representation of the root_task.

Returns:

A string representation of the root_task.

get_task_by_id

def get_task_by_id(id: str) -> Task

Retrieves a task by its ID.

Arguments:

  • id - The ID of the task.

Returns:

The task with the specified ID.

Raises:

  • AgentMalformedActionError - If the provided task ID is invalid or does not exist.

add_subtask

def add_subtask(parent_id: str, goal: str, subtasks: list | None = None)

Adds a subtask to a parent task.

Arguments:

  • parent_id - The ID of the parent task.
  • goal - The goal of the subtask.
  • subtasks - A list of subtasks associated with the new subtask.

set_subtask_state

def set_subtask_state(id: str, state: str)

Sets the state of a subtask.

Arguments:

  • id - The ID of the subtask.
  • state - The new state of the subtask.