GitHubIssueCommenterTool
A Tool that allows Agents and ToolInvokers to post comments to GitHub issues.
| Mandatory init variables | "github_token": GitHub personal access token. Can be set with GITHUB_TOKEN env var. | 
| API reference | Tools | 
| GitHub link | https://github.com/deepset-ai/haystack-core-integrations/tree/main/integrations/github | 
Overview
GitHubIssueCommenterTool wraps the GitHubIssueCommenter 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
nameis optional and defaults to "issue_commenter". Specifies the name of the tool.descriptionis optional and provides context to the LLM about what the tool does.github_tokenis mandatory and must be a GitHub personal access token for API authentication. The default setting uses the environment variableGITHUB_TOKEN.raise_on_failureis optional and defaults toTrue. If False, errors are returned instead of raising exceptions.retry_attemptsis optional and defaults to2. Number of retry attempts for failed requests.
Usage
Install the GitHub integration to use the GitHubIssueCommenterTool:
pip install github-haystack
Repository Placeholder
To run the following code snippets, you need to replace the
owner/repowith your own GitHub repository name.
On its own
Basic usage to comment on an issue:
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)
{'success': True}
With an Agent
You can use GitHubIssueCommenterTool with the Agent component. The Agent will automatically invoke the tool when needed to post comments on GitHub issues.
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)
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!
Updated 5 months ago
