mirror of
https://github.com/deepset-ai/haystack.git
synced 2026-02-02 13:03:34 +00:00
* Update documentation and remove unused assets. Enhanced the 'agents' and 'components' sections with clearer descriptions and examples. Removed obsolete images and updated links for better navigation. Adjusted formatting for consistency across various documentation pages. * remove dependency * address comments * delete more empty pages * broken link * unduplicate headings * alphabetical components nav
94 lines
3.4 KiB
Plaintext
94 lines
3.4 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.
|
|
|
|
| | |
|
|
| --- | --- |
|
|
| **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 |
|
|
|
|
## 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!
|
|
``` |