Skip to content

Commit 7b1fbbe

Browse files
committed
add git tool
1 parent f9f2488 commit 7b1fbbe

File tree

3 files changed

+50
-2
lines changed

3 files changed

+50
-2
lines changed

patchwork/common/tools/git_tool.py

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
from __future__ import annotations
2+
3+
import os
4+
import subprocess
5+
6+
from patchwork.common.tools.tool import Tool
7+
8+
9+
class GitTool(Tool, tool_name="git_tool", abc_register=False):
10+
def __init__(self, path: str):
11+
super().__init__()
12+
self.path = path
13+
14+
@property
15+
def json_schema(self) -> dict:
16+
return {
17+
"name": "git_tool",
18+
"description": """\
19+
Access to the Git CLI, the command is also `git` all args provided are used as is
20+
""",
21+
"input_schema": {
22+
"type": "object",
23+
"properties": {
24+
"args": {
25+
"type": "array",
26+
"items": {"type": "string"},
27+
"description": "The args to run `git` command with.",
28+
}
29+
},
30+
"required": ["args"],
31+
},
32+
}
33+
34+
def execute(self, args: list[str]) -> str:
35+
env = os.environ.copy()
36+
p = subprocess.run(
37+
["gh", *args],
38+
env=env,
39+
cwd=self.path,
40+
text=True,
41+
stdout=subprocess.PIPE,
42+
stderr=subprocess.STDOUT,
43+
)
44+
return p.stdout

patchwork/common/tools/github_tool.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from patchwork.common.tools.tool import Tool
77

88

9-
class GitHubTool(Tool, tool_name="github_tool"):
9+
class GitHubTool(Tool, tool_name="github_tool", abc_register=False):
1010
def __init__(self, path: str, gh_token: str):
1111
super().__init__()
1212
self.path = path

patchwork/steps/GitHubAgent/GitHubAgent.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
AgentConfig,
66
AgenticStrategyV2,
77
)
8+
from patchwork.common.tools.git_tool import GitTool
89
from patchwork.common.tools.github_tool import GitHubTool
910
from patchwork.common.utils.utils import mustache_render
1011
from patchwork.step import Step
@@ -34,7 +35,10 @@ def __init__(self, inputs):
3435
AgentConfig(
3536
name="Assistant",
3637
model="gemini-2.0-flash",
37-
tool_set=dict(github_tool=GitHubTool(base_path, inputs["github_api_key"])),
38+
tool_set=dict(
39+
github_tool=GitHubTool(base_path, inputs["github_api_key"]),
40+
git_tool=GitTool(base_path),
41+
),
3842
system_prompt="""\
3943
You are a senior software developer helping the program manager to obtain some data from GitHub.
4044
You can access github through the `gh` CLI app.

0 commit comments

Comments
 (0)