Github
toolkit contains tools that enable an LLM agent to interact with a github repository.
The tool is a wrapper for the PyGitHub library.
For detailed documentation of all GithubToolkit features and configurations head to the API reference.
Setup
At a high-level, we will:- Install the pygithub library
- Create a Github app
- Set your environmental variables
- Pass the tools to your agent with
toolkit.get_tools()
Installation
1. Install dependencies
This integration is implemented inlangchain-community
. We will also need the pygithub
dependency:
2. Create a Github App
Follow the instructions here to create and register a Github app. Make sure your app has the following repository permissions:- Commit statuses (read only)
- Contents (read and write)
- Issues (read and write)
- Metadata (read only)
- Pull requests (read and write)
3. Set Environment Variables
Before initializing your agent, the following environment variables need to be set:- GITHUB_APP_ID- A six digit number found in your app’s general settings
- GITHUB_APP_PRIVATE_KEY- The location of your app’s private key .pem file, or the full text of that file as a string.
- GITHUB_REPOSITORY- The name of the Github repository you want your bot to act upon. Must follow the format {username}/{repo-name}. Make sure the app has been added to this repository first!
- Optional: GITHUB_BRANCH- The branch where the bot will make its commits. Defaults to
repo.default_branch
. - Optional: GITHUB_BASE_BRANCH- The base branch of your repo upon which PRs will based from. Defaults to
repo.default_branch
.
Instantiation
Now we can instantiate our toolkit:Tools
View available tools:- Get Issues- fetches issues from the repository.
- Get Issue- fetches details about a specific issue.
- Comment on Issue- posts a comment on a specific issue.
- Create Pull Request- creates a pull request from the bot’s working branch to the base branch.
- Create File- creates a new file in the repository.
- Read File- reads a file from the repository.
- Update File- updates a file in the repository.
- Delete File- deletes a file from the repository.
Include release tools
By default, the toolkit does not include release-related tools. You can include them by settinginclude_release_tools=True
when initializing the toolkit:
include_release_tools=True
will include the following tools:
- Get Latest Release- fetches the latest release from the repository.
- Get Releases- fetches the latest 5 releases from the repository.
-
Get Release- fetches a specific release from the repository by tag name, e.g.
v1.0.0
.
Use within an agent
We will need a LLM or chat model:API reference
For detailed documentation of allGithubToolkit
features and configurations head to the API reference.