> For the complete documentation index, see [llms.txt](https://whitepaper.aitech.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://whitepaper.aitech.io/agentforge/tools/github.md).

# github

[GitHub](https://github.com/) is the world’s leading code hosting platform that enables collaboration, version control, and automation for developers and teams.

With GitHub, you can:

* **Host repositories** — Store public or private code with Git versioning.
* **Manage pull requests** — Review and merge contributions efficiently.
* **Track issues and discussions** — Organize bugs, feature requests, and tasks.
* **Automate workflows** — Use GitHub Actions for CI/CD and task automation.
* **Collaborate securely** — Manage permissions, reviews, and API access for teams.

In Agent Forge, the GitHub integration allows your agents to interact directly with repositories — fetching commits, posting PR comments, retrieving repo metadata, and automating reviews.\
This bridges your AI workflows with your software projects for seamless collaboration.

### How to Get a GitHub Personal Access Token (PAT Classic)

Follow these steps to generate a **Personal Access Token (Classic)** which grants your agent access to the GitHub API:

{% stepper %}
{% step %}

#### Go to GitHub Settings

1. Log in to your [GitHub account](https://github.com/).
2. In the top-right corner, click your **profile icon → Settings**.
   {% endstep %}

{% step %}

#### Open Developer Settings

1. In the left sidebar, scroll down and click **Developer settings**.
2. Then select **Personal access tokens → Tokens (classic)**.
   {% endstep %}

{% step %}

#### Generate a New Token

1. Click **Generate new token → Generate new token (classic)**.
2. Enter a **token name** (e.g., *Agent Forge Integration*).
3. (Optional) Set an **expiration** — “No expiration” is fine for local setups, but you can choose a shorter duration for security.
4. Select **Scopes** (permissions). Common scopes include:
   * `repo` — full control of private repositories
   * `read:user` — read profile information
   * `user:email` — access verified email address
   * `workflow` — manage GitHub Actions workflows
     {% endstep %}

{% step %}

#### Generate and Save Your Token

1. Click **Generate token** at the bottom.
2. **Copy your token immediately** — you won’t see it again!\
   Example: `ghp_aBcD1234EfGhI567*******************`
3. Store it in a secure location (e.g., `.env` file, secret manager).
   {% endstep %}

{% step %}

#### Use in Agent Forge or API Calls

Paste your token into the `apiKey` or `apiToken` field when configuring GitHub tool blocks.

> **Security Tip:** Never share your PAT publicly or commit it to your repo. Treat it like a password.
> {% endstep %}
> {% endstepper %}

### Usage Instructions

The GitHub tools in Agent Forge let your agents:

* Fetch pull request data (titles, diffs, and commits)
* Comment on open PRs
* Retrieve repository metadata and statistics
* Get the latest commits across branches

### Tools

#### `github_pr`

Fetch pull request details (including diffs and files changed).

**Input**

| Parameter    | Type   | Required | Description                |
| ------------ | ------ | -------- | -------------------------- |
| `owner`      | string | Yes      | Repository owner           |
| `repo`       | string | Yes      | Repository name            |
| `pullNumber` | number | Yes      | Pull request number        |
| `apiKey`     | string | Yes      | GitHub PAT (classic) token |

**Output**

| Parameter  | Type   | Description       |
| ---------- | ------ | ----------------- |
| `content`  | string | Response content  |
| `metadata` | json   | Response metadata |

#### `github_comment`

Post comments on pull requests.

**Input**

| Parameter    | Type   | Required | Description                |
| ------------ | ------ | -------- | -------------------------- |
| `owner`      | string | Yes      | Repository owner           |
| `repo`       | string | Yes      | Repository name            |
| `pullNumber` | number | Yes      | PR number                  |
| `body`       | string | Yes      | Comment content            |
| `apiKey`     | string | Yes      | GitHub PAT (classic) token |

**Output**

| Parameter  | Type   | Description       |
| ---------- | ------ | ----------------- |
| `content`  | string | Response content  |
| `metadata` | json   | Response metadata |

#### `github_repo_info`

Retrieve repository metadata — stars, forks, language, and more.

**Input**

| Parameter | Type   | Required | Description                |
| --------- | ------ | -------- | -------------------------- |
| `owner`   | string | Yes      | Repository owner           |
| `repo`    | string | Yes      | Repository name            |
| `apiKey`  | string | Yes      | GitHub PAT (classic) token |

**Output**

| Parameter  | Type   | Description       |
| ---------- | ------ | ----------------- |
| `content`  | string | Repository data   |
| `metadata` | json   | Response metadata |

#### `github_latest_commit`

Get the latest commit details for a branch.

**Input**

| Parameter | Type   | Required | Description                    |
| --------- | ------ | -------- | ------------------------------ |
| `owner`   | string | Yes      | Repository owner               |
| `repo`    | string | Yes      | Repository name                |
| `branch`  | string | No       | Branch name (defaults to main) |
| `apiKey`  | string | Yes      | GitHub PAT (classic) token     |

**Output**

| Parameter  | Type   | Description       |
| ---------- | ------ | ----------------- |
| `content`  | string | Commit details    |
| `metadata` | json   | Response metadata |

### Notes

* **Category:** `tools`
* **Type:** `github`
* Works with **Personal Access Token (Classic)** or **fine-grained PATs** if configured properly.
* Requires `repo` scope for private repositories and `read:user` for profile queries.
* You can manage and revoke tokens anytime under **Settings → Developer Settings → Personal Access Tokens (classic)**.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://whitepaper.aitech.io/agentforge/tools/github.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
