diff --git a/patchwork/common/tools/git_tool.py b/patchwork/common/tools/git_tool.py new file mode 100644 index 000000000..d5acbfa05 --- /dev/null +++ b/patchwork/common/tools/git_tool.py @@ -0,0 +1,49 @@ +from __future__ import annotations + +import os +import subprocess + +from patchwork.common.tools.tool import Tool + + +class GitTool(Tool, tool_name="git_tool", abc_register=False): + def __init__(self, path: str): + super().__init__() + self.path = path + + @property + def json_schema(self) -> dict: + return { + "name": "git_tool", + "description": """\ +Access to the Git CLI, the command is also `git` all args provided are used as is. +""", + "input_schema": { + "type": "object", + "properties": { + "args": { + "type": "array", + "items": {"type": "string"}, + "description": """ +The args to run `git` command with. +E.g. +[\"commit\", \"-m\", \"A commit message\"] to commit changes with a commit message. +[\"add\", \".\"] to stage all changed files. +""", + } + }, + "required": ["args"], + }, + } + + def execute(self, args: list[str]) -> str: + env = os.environ.copy() + p = subprocess.run( + ["git", *args], + env=env, + cwd=self.path, + text=True, + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT, + ) + return p.stdout diff --git a/patchwork/common/tools/github_tool.py b/patchwork/common/tools/github_tool.py index aa5d5effe..16e418c08 100644 --- a/patchwork/common/tools/github_tool.py +++ b/patchwork/common/tools/github_tool.py @@ -6,7 +6,7 @@ from patchwork.common.tools.tool import Tool -class GitHubTool(Tool, tool_name="github_tool"): +class GitHubTool(Tool, tool_name="github_tool", abc_register=False): def __init__(self, path: str, gh_token: str): super().__init__() self.path = path diff --git a/patchwork/steps/FileAgent/README.md b/patchwork/steps/FileAgent/README.md new file mode 100644 index 000000000..e26820b01 --- /dev/null +++ b/patchwork/steps/FileAgent/README.md @@ -0,0 +1,58 @@ +# FileAgent Module Documentation + +This document provides an overview of the `FileAgent` module, which is a part of the `patchwork` project. It consists of three Python files: `typed.py`, `FileAgent.py`, and `__init__.py`. This module is focused on processing file-related tasks using various tools and strategies, particularly with tabular data such as CSV files. + +## Overview + +The `FileAgent` is designed to handle file processing tasks, leveraging large language models and various tools to assist with file management, data extraction, and conversion tasks. It operates on tasks described with templates, using data inputs, and utilizes a strategy pattern for task execution. + +## Files + +### 1. typed.py + +This file defines the data types for inputs and outputs used by classes in the `FileAgent` module. It utilizes Python's typing extensions to ensure type safety. + +#### Inputs + +- **FileAgentInputs**: + - `task`: A string defining the task to perform. + - `base_path`: Optional string indicating the base directory for file operations. + - `prompt_value`: A dictionary containing data for template rendering. + - `max_llm_calls`: An integer specifying the maximum number of LLM calls. + - `anthropic_api_key`: A string for API authentication. + +#### Outputs + +- **FileAgentOutputs**: + - `request_tokens`: An integer representing the number of tokens in the request. + - `response_tokens`: An integer for the number of tokens in the response. + +### 2. FileAgent.py + +This file contains the implementation of the `FileAgent` class, which extends the `Step` class. It utilizes an agentic strategy pattern to manage file-related tasks and uses various tools for file manipulation and data extraction. + +#### Inputs + +- **FileAgentInputs**: As described above. + +#### Outputs + +- **FileAgentOutputs**: As described above. + +#### Usage + +The `FileAgent` class is initialized with a set of inputs. It processes tasks using a predefined strategy and various tools such as: +- `FindTextTool`: Searches for text within files. +- `FileViewTool`: Views file contents. +- `In2CSVTool`: Converts files to CSV format. +- `CSVSQLTool`: Performs SQL operations on CSV files. + +The `run` method initiates the task execution within a temporary directory, returning results and usage statistics. + +### 3. __init__.py + +This file serves as the package initializer and is currently empty, indicating no specific initialization code is needed for the module. + +## Intended Usage + +Developers can utilize the `FileAgent` module to automate file processing tasks, particularly when dealing with structured data files. By configuring the inputs, files can be processed, converted, and summarized following custom tasks defined by users. It is particularly useful for tasks involving large volumes of tabular data and when integrated with advanced language models for context-aware operations. diff --git a/patchwork/steps/GitHubAgent/GitHubAgent.py b/patchwork/steps/GitHubAgent/GitHubAgent.py index bc8d319c1..0ac014538 100644 --- a/patchwork/steps/GitHubAgent/GitHubAgent.py +++ b/patchwork/steps/GitHubAgent/GitHubAgent.py @@ -5,6 +5,7 @@ AgentConfig, AgenticStrategyV2, ) +from patchwork.common.tools.git_tool import GitTool from patchwork.common.tools.github_tool import GitHubTool from patchwork.common.utils.utils import mustache_render from patchwork.step import Step @@ -34,7 +35,10 @@ def __init__(self, inputs): AgentConfig( name="Assistant", model="gemini-2.0-flash", - tool_set=dict(github_tool=GitHubTool(base_path, inputs["github_api_key"])), + tool_set=dict( + github_tool=GitHubTool(base_path, inputs["github_api_key"]), + git_tool=GitTool(base_path), + ), system_prompt="""\ You are a senior software developer helping the program manager to obtain some data from GitHub. You can access github through the `gh` CLI app. diff --git a/pyproject.toml b/pyproject.toml index ab89dee54..d136584c5 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "patchwork-cli" -version = "0.0.123" +version = "0.0.124" description = "" authors = ["patched.codes"] license = "AGPL"