Skip to content
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

Enhancement of PR Agent with User Interaction #78

Merged
merged 18 commits into from
Jul 18, 2023
Merged

Enhancement of PR Agent with User Interaction #78

merged 18 commits into from
Jul 18, 2023

Conversation

mrT23
Copy link
Collaborator

@mrT23 mrT23 commented Jul 17, 2023

Type of PR:
Enhancement


PR Description:
This PR introduces the ability for the PR Agent to interact with the user by asking questions and processing the user's answers. It also includes changes to the command line interface and the GitHub action runner to support these new features. Additionally, it modifies the configuration settings and the prompts used by the PR Agent.


PR Main Files Walkthrough:
-pr_agent/agent/pr_agent.py: The main agent class has been updated to handle new commands for asking questions and processing answers. It also uses the settings to decide whether to ask questions before reviewing a PR.
-pr_agent/cli.py: The command line interface has been updated to support the new 'user_answers' command.
-pr_agent/servers/github_action_runner.py: The GitHub action runner has been updated to handle the new '/answer' command and to ask questions before reviewing a PR based on the settings.
-pr_agent/tools/pr_information_from_user.py: The method for preparing the PR answer has been updated to change the format of the response.
-pr_agent/tools/pr_reviewer.py: The PRReviewer class has been updated to handle the new 'is_answer' parameter and to get the user's answers from the PR discussion. It also publishes inline code comments based on the settings.
-pr_agent/settings/configuration.toml: The configuration settings have been updated to include a new 'ask_and_reflect' setting for the PR reviewer.
-pr_agent/settings/pr_information_from_user_prompts.toml: The prompts for getting information from the user have been updated to change the format of the questions.
-pr_agent/settings/pr_reviewer_prompts.toml: The prompts for the PR reviewer have been updated to include insights from the user's answers and to change the format of the questions.

@mrT23 mrT23 requested a review from okotek July 17, 2023 12:50
@mrT23 mrT23 added the WIP label Jul 17, 2023
Copy link

@BossModus666 BossModus666 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mrT23
Copy link
Collaborator Author

mrT23 commented Jul 18, 2023

Preparing pr description...

@mrT23 mrT23 changed the title Tr/agent logic Enhancement of PR Agent with User Interaction Jul 18, 2023
@mrT23 mrT23 removed the WIP label Jul 18, 2023
@@ -53,8 +54,14 @@ async def run_action():
pr_url = event_payload.get("issue", {}).get("pull_request", {}).get("url", None)
if pr_url:
body = comment_body.strip().lower()
if any(cmd in body for cmd in ["/review", "/review_pr"]):
await PRReviewer(pr_url).review()
if any(cmd in body for cmd in ["/answer"]):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let me replace that with PRAgent call

@@ -9,18 +9,22 @@
from pr_agent.algo.token_handler import TokenHandler
from pr_agent.algo.utils import convert_to_markdown, try_fix_json
from pr_agent.config_loader import settings
from pr_agent.git_providers import get_git_provider
from pr_agent.git_providers import get_git_provider, GithubProvider
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
from pr_agent.git_providers import get_git_provider, GithubProvider
from pr_agent.git_providers import get_git_provider


self.git_provider = get_git_provider()(pr_url)
self.main_language = get_main_pr_language(
self.git_provider.get_languages(), self.git_provider.get_files()
)
self.is_answer = is_answer
if self.is_answer and type(self.git_provider) != GithubProvider:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

let me add is_supported in git provider

answer_str = question_str = ""
if self.is_answer:
discussion_messages = self.git_provider.pr.get_issue_comments()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me add that function in the base class

@okotek okotek merged commit 9e0f5f0 into main Jul 18, 2023
@okotek okotek deleted the tr/agent_logic branch July 18, 2023 07:37
@okotek
Copy link
Contributor

okotek commented Jul 18, 2023

/answer

@github-actions
Copy link
Contributor

PR Analysis

  • 🎯 Main theme: This PR introduces the ability for the PR Agent to interact with the user by asking questions and processing the user's answers. It also includes changes to the command line interface and the GitHub action runner to support these new features. Additionally, it modifies the configuration settings and the prompts used by the PR Agent.
  • 📌 Type of PR: Enhancement
  • 🧪 Relevant tests added: No
  • Insights from user's answer: No user answers were provided.
  • Focused PR: Yes, the PR has a clear and coherent title and description, and all PR code diff changes are properly derived from the title and description.
  • 🔒 Security concerns: No, this PR does not introduce any obvious security concerns. The PR mainly deals with adding new features and updating existing ones, and does not involve any operations that could potentially lead to security issues such as SQL injection, XSS, CSRF, etc.

PR Feedback

  • 💡 General PR suggestions: The PR is well-structured and the changes are clearly explained in the description. However, it would be beneficial to include tests for the new features introduced in this PR. This would help ensure that the new features work as expected and prevent potential regressions in the future.

How to use

To invoke the PR-Agent, add a comment using one of the following commands:
/review - Request a review of the latest update to the PR.
/describe - Modify the PR title and description based on the contents of the PR.
/improve - Suggest improvements to the code in the PR. These will be provided as pull request comments, ready to commit.
/ask - Pose a question about the PR.



class PRAgent:
def __init__(self):
pass

async def handle_request(self, pr_url, request) -> bool:
if any(cmd in request for cmd in ["/review", "/review_pr"]):
await PRReviewer(pr_url).review()
if any(cmd in request for cmd in ["/answer"]):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider refactoring the handle_request method to reduce its complexity and improve readability. You could extract the logic for each command into separate methods. [important]


self.git_provider = get_git_provider()(pr_url)
self.main_language = get_main_pr_language(
self.git_provider.get_languages(), self.git_provider.get_files()
)
self.is_answer = is_answer
if self.is_answer and not self.git_provider.is_supported("get_issue_comments"):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be beneficial to handle the case where the get_issue_comments method is not supported by the git provider in a more user-friendly way. Instead of raising an exception, you could display a message to the user informing them that this feature is not supported. [medium]

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably do that

@okotek
Copy link
Contributor

okotek commented Jul 18, 2023

/reflect_and_review

@github-actions
Copy link
Contributor

Questions to better understand the PR:

  1. In the pr_agent.py file, I see that the handle_request method has been updated to handle new commands for asking questions and processing answers. Can you confirm if these new commands are also reflected in the command line interface?
  2. The PRReviewer class has been updated to handle the new 'is_answer' parameter and to get the user's answers from the PR discussion. How does the system handle situations where the 'is_answer' parameter is not provided?
  3. Can you provide more context on how the 'ask_and_reflect' setting in the configuration file is used in the PR review process?

Please respond to the questions above in the following format:

/answer

  1. ...
  2. ...
    ...

@okotek
Copy link
Contributor

okotek commented Jul 18, 2023

/answer

  1. These commands are also reflected in the command line interface.
  2. It is handled in the Jinja template of the AI prompt.
  3. If this setting is set, every review defaults to "reflect and review"

@github-actions
Copy link
Contributor

PR Analysis

  • 🎯 Main theme: Enhancement of PR Agent with User Interaction
  • 📌 Type of PR: Enhancement
  • 🧪 Relevant tests added: No
  • Insights from user's answer: The new commands for asking questions and processing answers are reflected in the command line interface. The 'is_answer' parameter is handled in the Jinja template of the AI prompt. If the 'ask_and_reflect' setting is set, every review defaults to 'reflect and review'.
  • Focused PR: Yes, the PR has a clear and coherent title and description, and all PR code diff changes are properly derived from the title and description.
  • 🔒 Security concerns: No, the PR does not introduce any obvious security concerns. It mainly deals with user interaction and does not involve any sensitive data or operations that could be exploited.

PR Feedback

  • 💡 General PR suggestions: The PR is well-structured and the changes are clearly explained. However, it would be beneficial to include tests for the new functionality to ensure it works as expected and to prevent future regressions.

How to use

To invoke the PR-Agent, add a comment using one of the following commands:
/review - Request a review of the latest update to the PR.
/describe - Modify the PR title and description based on the contents of the PR.
/improve - Suggest improvements to the code in the PR. These will be provided as pull request comments, ready to commit.
/ask - Pose a question about the PR.


self.git_provider = get_git_provider()(pr_url)
self.main_language = get_main_pr_language(
self.git_provider.get_languages(), self.git_provider.get_files()
)
self.is_answer = is_answer
if self.is_answer and not self.git_provider.is_supported("get_issue_comments"):
raise Exception(f"Answer mode is not supported for {settings.config.git_provider} for now")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using a more specific exception type instead of the generic Exception. This can help with debugging and error handling. For example, you could define a custom exception for this specific error case. [important]

pass

def _get_user_answers(self):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding a docstring to the '_get_user_answers' method to explain its purpose, inputs, and outputs. This can improve code readability and maintainability. [medium]

""")
parser.add_argument('--pr_url', type=str, help='The URL of the PR to review', required=True)
parser.add_argument('command', type=str, help='The', choices=['review', 'review_pr',
'ask', 'ask_question',
'describe', 'describe_pr',
'improve', 'improve_code',
'user_questions'], default='review')
'reflect', 'review_after_reflect'],
default='review')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using an enum or constants for command names instead of hardcoding them in multiple places. This can reduce the risk of typos and make the code easier to maintain. [medium]

yochail pushed a commit to yochail/pr-agent that referenced this pull request Feb 11, 2024
Enhancement of PR Agent with User Interaction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants