跳到主要内容

openhands.events.action.files

FileReadAction Objects

@dataclass
class FileReadAction(Action)

Reads a file from a given path. Can be set to read specific lines using start and end Default lines 0:-1 (whole file)

view_range

ONLY used in OH_ACI mode

FileWriteAction Objects

@dataclass
class FileWriteAction(Action)

Writes a file to a given path. Can be set to write specific lines using start and end Default lines 0:-1 (whole file)

FileEditAction Objects

@dataclass
class FileEditAction(Action)

Edits a file using various commands including view, create, str_replace, insert, and undo_edit.

This class supports two main modes of operation:

  1. LLM-based editing (impl_source = FileEditSource.LLM_BASED_EDIT)
  2. ACI-based editing (impl_source = FileEditSource.OH_ACI)

Attributes:

  • path str - The path to the file being edited. Works for both LLM-based and OH_ACI editing. OH_ACI only arguments:

  • command str - The editing command to be performed (view, create, str_replace, insert, undo_edit, write).

  • file_text str - The content of the file to be created (used with 'create' command in OH_ACI mode).

  • old_str str - The string to be replaced (used with 'str_replace' command in OH_ACI mode).

  • new_str str - The string to replace old_str (used with 'str_replace' and 'insert' commands in OH_ACI mode).

  • insert_line int - The line number after which to insert new_str (used with 'insert' command in OH_ACI mode). LLM-based editing arguments:

  • content str - The content to be written or edited in the file (used in LLM-based editing and 'write' command).

  • start int - The starting line for editing (1-indexed, inclusive). Default is 1.

  • end int - The ending line for editing (1-indexed, inclusive). Default is -1 (end of file).

  • thought str - The reasoning behind the edit action.

  • command0 str - The type of action being performed (always ActionType.EDIT).

  • command1 bool - Indicates if the action can be executed (always True).

  • command2 ActionSecurityRisk | None - Indicates any security risks associated with the action.

  • command3 FileEditSource - The source of the implementation (LLM_BASED_EDIT or OH_ACI).

    Usage:

    • For LLM-based editing: Use path, content, start, and end attributes.
    • For ACI-based editing: Use path, command, and the appropriate attributes for the specific command.

Notes:

  • If start is set to -1 in LLM-based editing, the content will be appended to the file.
  • The 'write' command behaves similarly to LLM-based editing, using content, start, and end attributes.