/ docs-website / docs / tools / ready-made-tools / githubissuecommentertool.mdx
githubissuecommentertool.mdx
  1  ---
  2  title: "GitHubIssueCommenterTool"
  3  id: githubissuecommentertool
  4  slug: "/githubissuecommentertool"
  5  description: "A Tool that allows Agents and ToolInvokers to post comments to GitHub issues."
  6  ---
  7  
  8  # GitHubIssueCommenterTool
  9  
 10  A Tool that allows Agents and ToolInvokers to post comments to GitHub issues.
 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  `GitHubIssueCommenterTool` wraps the [`GitHubIssueCommenter`](../../pipeline-components/connectors/githubissuecommenter.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 comment text, then posts the comment to the specified issue using the GitHub API. This requires authentication since posting comments is an authenticated operation.
 27  
 28  ### Parameters
 29  
 30  - `name` is _optional_ and defaults to "issue_commenter". 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 for API authentication. 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  - `retry_attempts` is _optional_ and defaults to `2`. Number of retry attempts for failed requests.
 35  
 36  ## Usage
 37  
 38  Install the GitHub integration to use the `GitHubIssueCommenterTool`:
 39  
 40  ```shell
 41  pip install github-haystack
 42  ```
 43  
 44  :::info[Repository Placeholder]
 45  
 46  To run the following code snippets, you need to replace the `owner/repo` with your own GitHub repository name.
 47  :::
 48  
 49  ### On its own
 50  
 51  Basic usage to comment on an issue:
 52  
 53  ```python
 54  from haystack_integrations.tools.github import GitHubIssueCommenterTool
 55  
 56  tool = GitHubIssueCommenterTool()
 57  result = tool.invoke(
 58      url="https://github.com/owner/repo/issues/123",
 59      comment="Thanks for reporting this issue! We'll look into it.",
 60  )
 61  
 62  print(result)
 63  ```
 64  
 65  ```bash
 66  {'success': True}
 67  ```
 68  
 69  ### With an Agent
 70  
 71  You can use `GitHubIssueCommenterTool` with the [Agent](../../pipeline-components/agents-1/agent.mdx) component. The Agent will automatically invoke the tool when needed to post comments on GitHub issues.
 72  
 73  ```python
 74  from haystack.components.generators.chat import OpenAIChatGenerator
 75  from haystack.dataclasses import ChatMessage
 76  from haystack.components.agents import Agent
 77  from haystack_integrations.tools.github import GitHubIssueCommenterTool
 78  
 79  comment_tool = GitHubIssueCommenterTool(name="github_issue_commenter")
 80  
 81  agent = Agent(
 82      chat_generator=OpenAIChatGenerator(),
 83      tools=[comment_tool],
 84      exit_conditions=["text"],
 85  )
 86  
 87  response = agent.run(
 88      messages=[
 89          ChatMessage.from_user(
 90              "Please post a helpful comment on this GitHub issue: https://github.com/owner/repo/issues/123 acknowledging the bug report and mentioning that we're investigating",
 91          ),
 92      ],
 93  )
 94  
 95  print(response["last_message"].text)
 96  ```
 97  
 98  ```bash
 99  I have posted the comment on the GitHub issue, acknowledging the bug report and mentioning that the team is investigating the problem. If you need anything else, feel free to ask!
100  ```