/ docs-website / versioned_docs / version-2.18 / 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  |                              |                                                                                          |
13  | ---------------------------- | ---------------------------------------------------------------------------------------- |
14  | **Mandatory init variables** | "github_token": GitHub personal access token. Can be set with `GITHUB_TOKEN` env var.    |
15  | **API reference**            | [Tools](/reference/tools-api)                                                            |
16  | **GitHub link**              | https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/github |
17  
18  ## Overview
19  
20  `GitHubIssueCommenterTool` wraps the [`GitHubIssueCommenter`](../../pipeline-components/connectors/githubissuecommenter.mdx) component, providing a tool interface for use in agent workflows and tool-based pipelines.
21  
22  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.
23  
24  ### Parameters
25  
26  - `name` is _optional_ and defaults to "issue_commenter". Specifies the name of the tool.
27  - `description` is _optional_ and provides context to the LLM about what the tool does.
28  - `github_token` is _mandatory_ and must be a GitHub personal access token for API authentication. The default setting uses the environment variable `GITHUB_TOKEN`.
29  - `raise_on_failure` is _optional_ and defaults to `True`. If False, errors are returned instead of raising exceptions.
30  - `retry_attempts` is _optional_ and defaults to `2`. Number of retry attempts for failed requests.
31  
32  ## Usage
33  
34  Install the GitHub integration to use the `GitHubIssueCommenterTool`:
35  
36  ```shell
37  pip install github-haystack
38  ```
39  
40  :::note
41  Repository Placeholder
42  
43  To run the following code snippets, you need to replace the `owner/repo` with your own GitHub repository name.
44  :::
45  
46  ### On its own
47  
48  Basic usage to comment on an issue:
49  
50  ```python
51  from haystack_integrations.tools.github import GitHubIssueCommenterTool
52  
53  tool = GitHubIssueCommenterTool()
54  result = tool.invoke(
55      url="https://github.com/owner/repo/issues/123",
56      comment="Thanks for reporting this issue! We'll look into it.",
57  )
58  
59  print(result)
60  ```
61  
62  ```bash
63  {'success': True}
64  ```
65  
66  ### With an Agent
67  
68  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.
69  
70  ```python
71  from haystack.components.generators.chat import OpenAIChatGenerator
72  from haystack.dataclasses import ChatMessage
73  from haystack.components.agents import Agent
74  from haystack_integrations.tools.github import GitHubIssueCommenterTool
75  
76  comment_tool = GitHubIssueCommenterTool(name="github_issue_commenter")
77  
78  agent = Agent(
79      chat_generator=OpenAIChatGenerator(),
80      tools=[comment_tool],
81      exit_conditions=["text"],
82  )
83  
84  agent.warm_up()
85  response = agent.run(
86      messages=[
87          ChatMessage.from_user(
88              "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",
89          ),
90      ],
91  )
92  
93  print(response["last_message"].text)
94  ```
95  
96  ```bash
97  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!
98  ```