Skip to main content
For the complete documentation index for agents and LLMs, see llms.txt.

GitHubFileEditor

Edit, create, delete, or undo changes to files in GitHub repositories through the GitHub API—designed for AI agents that autonomously modify code.

Key Features​

  • Supports four operations: edit (replace content), create (new file), delete, and undo (revert the last commit).
  • Resolves a GITHUB_TOKEN secret at runtime, keeping credentials out of the pipeline YAML.
  • Accepts a default repository and branch at initialization; both can be overridden at run time.
  • For edit, verifies that the target string is unique before making any change, preventing accidental multi-site replacements.
  • For undo, confirms the last commit was made by the authenticated user before reverting.
  • Raises an exception or returns an error string on failure, depending on raise_on_failure.

Configuration​

  1. Store your GitHub personal access token as a secret named GITHUB_TOKEN. For instructions, see Create Secrets.
  2. Drag the GitHubFileEditor component onto the canvas from the Component Library.
  3. Click on the component to open the configuration panel.
  4. Set repo to the default repository in owner/repo format.
  5. Set branch to the default branch (for example, main).

Connections​

GitHubFileEditor receives a command string (one of edit, undo, create, or delete) and a payload dict with operation-specific parameters (path, original string, replacement, message, and so on). It outputs a result string describing the outcome. You can connect the output to a prompt builder or another component that evaluates the edit result.

Source Code​

To check this component's source code, open file_editor.py in the Haystack Core Integrations repository.

Usage Examples​

Basic Configuration​

GitHubFileEditor:
type: haystack_integrations.components.connectors.github.file_editor.GitHubFileEditor
init_parameters:
github_token:
type: env_var
env_vars:
- GITHUB_TOKEN
strict: true
repo: owner/my-repo
branch: main
raise_on_failure: true

Using the Component in a Pipeline​

This example shows a pipeline where an agent reads a repository, decides on a change, and then applies it.

# haystack-pipeline

components:
repo_viewer:
type: haystack_integrations.components.connectors.github.repo_viewer.GitHubRepoViewer
init_parameters:
github_token:
type: env_var
env_vars:
- GITHUB_TOKEN
strict: true
repo: owner/my-repo
branch: main

file_editor:
type: haystack_integrations.components.connectors.github.file_editor.GitHubFileEditor
init_parameters:
github_token:
type: env_var
env_vars:
- GITHUB_TOKEN
strict: true
repo: owner/my-repo
branch: main
raise_on_failure: true

inputs:
command:
- file_editor.command
payload:
- file_editor.payload
path:
- repo_viewer.path

outputs:
result: file_editor.result
documents: repo_viewer.documents

max_runs_per_component: 100

metadata: {}

Parameters​

Inputs​

ParameterTypeDefaultDescription
commandstr or CommandOperation to perform. One of edit, undo, create, or delete.
payloaddictCommand-specific parameters. For edit: path, original, replacement, message. For create: path, content, message. For delete: path, message. For undo: no extra keys needed.
repoOptional[str]NoneRepository in owner/repo format. Overrides the default set at initialization.
branchOptional[str]NoneBranch to operate on. Overrides the default set at initialization.

Outputs​

ParameterTypeDescription
resultstrA string describing the outcome of the operation (for example, Edit successful or an error message).

Init Parameters​

These are the parameters you can configure in Pipeline Builder:

ParameterTypeDefaultDescription
github_tokenSecretSecret.from_env_var("GITHUB_TOKEN")GitHub personal access token used for API authentication.
repoOptional[str]NoneDefault repository in owner/repo format.
branchstrmainDefault branch to operate on.
raise_on_failureboolTrueIf True, raises an exception on API errors. If False, returns an error string in result.