Skip to content

PatchWork GenerateREADME #1639

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 49 additions & 0 deletions patchwork/common/tools/git_tool.py
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion patchwork/common/tools/github_tool.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
56 changes: 56 additions & 0 deletions patchwork/steps/DatabaseAgent/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Documentation: DatabaseAgent Module

## Overview

The `DatabaseAgent` module is designed to facilitate interaction with a database by generating and executing appropriate SQL queries. It uses machine learning to understand and interpret user tasks and generates an execution plan to gather and process necessary data from a database using the specified database dialect (e.g., SQL).

The main functionality is encapsulated within a class called `DatabaseAgent`, which leverages the `AgenticStrategyV2` to dynamically generate responses to user tasks. This agent uses the `AioLlmClient` and `DatabaseQueryTool` to perform its operations, geared towards summarizing conversations and fetching data based on user prompts.

## Inputs

### DatabaseAgent Inputs Class

In the file `typed.py`, the `DatabaseAgentInputs` class defines the input structure that the `DatabaseAgent` expects:

- **task (str):** A string describing the task that needs completion.
- **db_dialect (str):** Specifies the type of SQL dialect the database uses (e.g., MySQL, PostgreSQL).
- **db_driver (str):** The database driver used for connections.
- **db_username (str):** Username for database authentication.
- **db_password (str):** Password for database authentication.
- **db_host (str):** Host address of the database.
- **db_port (int):** Port number for database connection.
- **db_name (str):** Name of the database.
- **db_params (dict):** Additional connection parameters.
- **db_driver_args (dict):** Additional driver-specific arguments.
- **prompt_value (Dict[str, Any]):** Dictionary holding values for prompt customization.
- **max_llm_calls (int):** Configures the maximum number of large language model calls.
- **openai_api_key (str):** API key for OpenAI services.
- **anthropic_api_key (str):** API key for Anthropic services.
- **google_api_key (str):** API key for Google services.
- **example_json (str):** A JSON example to guide response structure.

## Outputs

### DatabaseAgent Outputs Class

Within `typed.py`, the `DatabaseAgentOutputs` class is introduced to outline the expected output format:

- **request_tokens (int):** Number of tokens used in the request.
- **response_tokens (int):** Number of tokens received in the response.

## DatabaseAgent Implementation

### Core Functionality

In `DatabaseAgent.py`, the `DatabaseAgent` class derives from the `Step` class and uses both `DatabaseAgentInputs` and `DatabaseAgentOutputs`. The class:

- Initializes an agentic strategy to process user-provided tasks and database information.
- Sets up database query configurations through the `DatabaseQueryTool`.
- Employs the `mustache_render` utility to tailor command-line interactions and strategy prompts.
- Executes the task, restricting output operation to a maximum of ten results (`limit=10`).

### `run` Method

The `run` function executes the agent's strategy to fetch requested data and append execution usage metrics from the `AgenticStrategyV2`.

By employing this module, users can expect an automated task execution environment, where high-level natural language prompts can seamlessly translate into concrete database operations. This setup is particularly useful for data analysis and management tasks that require flexible and interactive database querying capabilities.
6 changes: 5 additions & 1 deletion patchwork/steps/GitHubAgent/GitHubAgent.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "patchwork-cli"
version = "0.0.123"
version = "0.0.124"
description = ""
authors = ["patched.codes"]
license = "AGPL"
Expand Down