Files
deepset-ai--haystack/docs-website/versioned_docs/version-2.20/tools/ready-made-tools/githubissuecommentertool.mdx
T
wehub-resource-sync c56bef871b
CodeQL / Analyze (python) (push) Has been cancelled
Update Platform Components Table / update (push) Has been cancelled
Docker image release / Build base image (push) Has been cancelled
Sync docs with Docusaurus / sync (push) Has been cancelled
Tests / Check if changed (push) Has been cancelled
Tests / format (push) Has been cancelled
Tests / check-imports (push) Has been cancelled
Tests / Unit / macos-latest (push) Has been cancelled
Tests / Unit / ubuntu-latest (push) Has been cancelled
Tests / Unit / windows-latest (push) Has been cancelled
Tests / mypy (push) Has been cancelled
Tests / Integration / ubuntu-latest (push) Has been cancelled
Tests / Integration / macos-latest (push) Has been cancelled
Tests / Integration / windows-latest (push) Has been cancelled
Tests / notify-slack-on-failure (push) Has been cancelled
Tests / Mark tests as completed (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 13:22:28 +08:00

102 lines
3.5 KiB
Plaintext

---
title: "GitHubIssueCommenterTool"
id: githubissuecommentertool
slug: "/githubissuecommentertool"
description: "A Tool that allows Agents and ToolInvokers to post comments to GitHub issues."
---
# GitHubIssueCommenterTool
A Tool that allows Agents and ToolInvokers to post comments to GitHub issues.
<div className="key-value-table">
| | |
| --- | --- |
| **Mandatory init variables** | `github_token`: GitHub personal access token. Can be set with `GITHUB_TOKEN` env var. |
| **API reference** | [Tools](/reference/tools-api) |
| **GitHub link** | https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/github |
</div>
## Overview
`GitHubIssueCommenterTool` wraps the [`GitHubIssueCommenter`](../../pipeline-components/connectors/githubissuecommenter.mdx) component, providing a tool interface for use in agent workflows and tool-based pipelines.
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.
### Parameters
- `name` is _optional_ and defaults to "issue_commenter". Specifies the name of the tool.
- `description` is _optional_ and provides context to the LLM about what the tool does.
- `github_token` is _mandatory_ and must be a GitHub personal access token for API authentication. The default setting uses the environment variable `GITHUB_TOKEN`.
- `raise_on_failure` is _optional_ and defaults to `True`. If False, errors are returned instead of raising exceptions.
- `retry_attempts` is _optional_ and defaults to `2`. Number of retry attempts for failed requests.
## Usage
Install the GitHub integration to use the `GitHubIssueCommenterTool`:
```shell
pip install github-haystack
```
:::info[Repository Placeholder]
To run the following code snippets, you need to replace the `owner/repo` with your own GitHub repository name.
:::
### On its own
Basic usage to comment on an issue:
```python
from haystack_integrations.tools.github import GitHubIssueCommenterTool
tool = GitHubIssueCommenterTool()
result = tool.invoke(
url="https://github.com/owner/repo/issues/123",
comment="Thanks for reporting this issue! We'll look into it.",
)
print(result)
```
```bash
{'success': True}
```
### With an Agent
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.
```python
from haystack.components.generators.chat import OpenAIChatGenerator
from haystack.dataclasses import ChatMessage
from haystack.components.agents import Agent
from haystack_integrations.tools.github import GitHubIssueCommenterTool
comment_tool = GitHubIssueCommenterTool(name="github_issue_commenter")
agent = Agent(
chat_generator=OpenAIChatGenerator(),
tools=[comment_tool],
exit_conditions=["text"],
)
agent.warm_up()
response = agent.run(
messages=[
ChatMessage.from_user(
"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",
),
],
)
print(response["last_message"].text)
```
```bash
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!
```