Aller directement au contenu principal

openhands.events.observation.files

File-related observation classes for tracking file operations.

FileReadObservation Objects

@dataclass
class FileReadObservation(Observation)

This data class represents the content of a file.

message

@property
def message() -> str

Get a human-readable message describing the file read operation.

__str__

def __str__() -> str

Get a string representation of the file read observation.

FileWriteObservation Objects

@dataclass
class FileWriteObservation(Observation)

This data class represents a file write operation.

message

@property
def message() -> str

Get a human-readable message describing the file write operation.

__str__

def __str__() -> str

Get a string representation of the file write observation.

FileEditObservation Objects

@dataclass
class FileEditObservation(Observation)

This data class represents a file edit operation.

The observation includes both the old and new content of the file, and can generate a diff visualization showing the changes. The diff is computed lazily and cached to improve performance.

The .content property can either be:

  • Git diff in LLM-based editing mode
  • the rendered message sent to the LLM in OH_ACI mode (e.g., "The file /path/to/file.txt is created with the provided content.")

message

@property
def message() -> str

Get a human-readable message describing the file edit operation.

get_edit_groups

def get_edit_groups(n_context_lines: int = 2) -> list[dict[str, list[str]]]

Get the edit groups showing changes between old and new content.

Arguments:

  • n_context_lines - Number of context lines to show around each change.

Returns:

A list of edit groups, where each group contains before/after edits.

visualize_diff

def visualize_diff(n_context_lines: int = 2,
change_applied: bool = True) -> str

Visualize the diff of the file edit. Used in the LLM-based editing mode.

Instead of showing the diff line by line, this function shows each hunk of changes as a separate entity.

Arguments:

  • n_context_lines - Number of context lines to show before/after changes.
  • change_applied - Whether changes are applied. If false, shows as attempted edit.

Returns:

A string containing the formatted diff visualization.

__str__

def __str__() -> str

Get a string representation of the file edit observation.