/ docs-website / docs / tools / ready-made-tools / githubprcreatortool.mdx
githubprcreatortool.mdx
  1  ---
  2  title: "GitHubPRCreatorTool"
  3  id: githubprcreatortool
  4  slug: "/githubprcreatortool"
  5  description: "A Tool that allows Agents and ToolInvokers to create pull requests from a fork back to the original repository."
  6  ---
  7  
  8  # GitHubPRCreatorTool
  9  
 10  A Tool that allows Agents and ToolInvokers to create pull requests from a fork back to the original repository.
 11  
 12  <div className="key-value-table">
 13  
 14  |  |  |
 15  | --- | --- |
 16  | **Mandatory init variables** | `github_token`: GitHub personal access token. Can be set with `GITHUB_TOKEN` env var.    |
 17  | **API reference**            | [Tools](/reference/tools-api)                                                            |
 18  | **GitHub link**              | https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/github |
 19  
 20  </div>
 21  
 22  ## Overview
 23  
 24  `GitHubPRCreatorTool` wraps the [`GitHubPRCreator`](../../pipeline-components/connectors/githubprcreator.mdx) component, providing a tool interface for use in agent workflows and tool-based pipelines.
 25  
 26  The tool takes a GitHub issue URL and creates a pull request from your fork to the original repository, automatically linking it to the specified issue. It's designed to work with existing forks and assumes you have already made changes in a branch.
 27  
 28  ### Parameters
 29  
 30  - `name` is _optional_ and defaults to "pr_creator". Specifies the name of the tool.
 31  - `description` is _optional_ and provides context to the LLM about what the tool does.
 32  - `github_token` is _mandatory_ and must be a GitHub personal access token from the fork owner. The default setting uses the environment variable `GITHUB_TOKEN`.
 33  - `raise_on_failure` is _optional_ and defaults to `True`. If False, errors are returned instead of raising exceptions.
 34  
 35  ## Usage
 36  
 37  Install the GitHub integration to use the `GitHubPRCreatorTool`:
 38  
 39  ```shell
 40  pip install github-haystack
 41  ```
 42  
 43  :::info[Repository Placeholder]
 44  
 45  To run the following code snippets, you need to replace the `owner/repo` with your own GitHub repository name.
 46  :::
 47  
 48  ### On its own
 49  
 50  Basic usage to create a pull request:
 51  
 52  ```python
 53  from haystack_integrations.tools.github import GitHubPRCreatorTool
 54  
 55  tool = GitHubPRCreatorTool()
 56  result = tool.invoke(
 57      issue_url="https://github.com/owner/repo/issues/123",
 58      title="Fix issue #123",
 59      body="This PR addresses issue #123 by implementing the requested changes.",
 60      branch="fix-123",  # Branch in your fork with the changes
 61      base="main",  # Branch in original repo to merge into
 62  )
 63  
 64  print(result)
 65  ```
 66  
 67  ```bash
 68  {'result': 'Pull request #16 created successfully and linked to issue #4'}
 69  ```
 70  
 71  ### With an Agent
 72  
 73  You can use `GitHubPRCreatorTool` with the [Agent](../../pipeline-components/agents-1/agent.mdx) component. The Agent will automatically invoke the tool when needed to create pull requests.
 74  
 75  ```python
 76  from haystack.components.generators.chat import OpenAIChatGenerator
 77  from haystack.dataclasses import ChatMessage
 78  from haystack.components.agents import Agent
 79  from haystack_integrations.tools.github import GitHubPRCreatorTool
 80  
 81  pr_tool = GitHubPRCreatorTool(name="github_pr_creator")
 82  
 83  agent = Agent(
 84      chat_generator=OpenAIChatGenerator(),
 85      tools=[pr_tool],
 86      exit_conditions=["text"],
 87  )
 88  
 89  response = agent.run(
 90      messages=[
 91          ChatMessage.from_user(
 92              "Create a pull request for issue https://github.com/owner/repo/issues/4 with title 'Fix authentication bug' and empty body using my fix-4 branch and main as target branch",
 93          ),
 94      ],
 95  )
 96  
 97  print(response["last_message"].text)
 98  ```
 99  
100  ```bash
101  The pull request titled "Fix authentication bug" has been created successfully and linked to issue [#123](https://github.com/owner/repo/issues/4).
102  ```