File tree Expand file tree Collapse file tree 3 files changed +50
-2
lines changed Expand file tree Collapse file tree 3 files changed +50
-2
lines changed Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change 66from 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
Original file line number Diff line number Diff line change 55 AgentConfig ,
66 AgenticStrategyV2 ,
77)
8+ from patchwork .common .tools .git_tool import GitTool
89from patchwork .common .tools .github_tool import GitHubTool
910from patchwork .common .utils .utils import mustache_render
1011from 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.
4044You can access github through the `gh` CLI app.
You can’t perform that action at this time.
0 commit comments