GitHubPRCreatorTool
GitHubPRCreatorTool
Agent가 포크에서 원본 저장소로 pull request를 생성할 수 있게 해 주는 Tool이에요.
출처: 문서
본문
GitHubPRCreatorTool은 GitHubPRCreator 구성 요소를 감싸서, 에이전트 워크플로와 tool 기반 파이프라인에서 쓸 수 있는 tool 인터페이스를 제공해요. GitHub 이슈 URL을 받아 포크에서 원본 저장소로 pull request를 생성하고, 지정된 이슈에 자동으로 연결해요. 기존 포크를 대상으로 설계되었으며, 브랜치에 이미 변경 사항을 만들었다고 가정해요.
Parameters
name— 선택. 기본값"pr_creator". tool의 이름.description— 선택. tool이 무엇을 하는지 LLM에 알려주는 설명.github_token— 필수. 포크 소유자의 GitHub 개인 액세스 토큰. 기본은GITHUB_TOKEN환경 변수 사용.raise_on_failure— 선택. 기본값True.False면 예외를 던지는 대신 에러를 반환.
Usage
pip install github-haystack
저장소 플레이스홀더: 아래 코드 스니펫을 실행하려면 owner/repo를 자신의 GitHub 저장소 이름으로 바꿔야 해요.
On its own
pull request를 생성하는 기본 사용법:
from haystack_integrations.tools.github import GitHubPRCreatorTool
tool = GitHubPRCreatorTool()
result = tool.invoke(
issue_url="https://github.com/owner/repo/issues/123",
title="Fix issue #123",
body="This PR addresses issue #123 by implementing the requested changes.",
branch="fix-123", # Branch in your fork with the changes
base="main", # Branch in original repo to merge into
)
print(result)
{'result': 'Pull request #16 created successfully and linked to issue #4'}
With an Agent
GitHubPRCreatorTool을 Agent 구성 요소와 함께 사용할 수 있어요. Agent는 pull request를 생성할 필요가 있을 때 자동으로 tool을 호출해요.
from haystack.components.generators.chat import OpenAIChatGenerator
from haystack.dataclasses import ChatMessage
from haystack.components.agents import Agent
from haystack_integrations.tools.github import GitHubPRCreatorTool
pr_tool = GitHubPRCreatorTool(name="github_pr_creator")
agent = Agent(
chat_generator=OpenAIChatGenerator(),
tools=[pr_tool],
exit_conditions=["text"],
)
response = agent.run(
messages=[
ChatMessage.from_user(
"Create a pull request for issue https://github.com/owner/repo/issues/4 with title 'Fix authentication bug' and empty body using my fix-4 branch and main as target branch"
),
],
)
print(response["last_message"].text)
The pull request titled "Fix authentication bug" has been created successfully and linked to issue [#123](https://github.com/owner/repo/issues/4).