-
Notifications
You must be signed in to change notification settings - Fork 822
Improvement: Enhance ask_line tool by adding PR review comment threads as context #1687
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
Improvement: Enhance ask_line tool by adding PR review comment threads as context #1687
Conversation
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Latest suggestions up to 9c06b6b
Previous suggestions✅ Suggestions up to commit b53d277
|
Co-authored-by: Prateek <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for this significant contribution.
I've made a couple of review comments on the code changes.
While reviewing, I noticed that the current version contains an error that prevents it from running. Please take a look at it.
Co-authored-by: ofir-frd <[email protected]>
Co-authored-by: ofir-frd <[email protected]>
@ofir-frd Since I haven't been working with Python for long (PR agent was my first introduction to Python), my refactored code might still be lacking. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@benedict-lee
Thank you for your contribution.
The code logic was improved significantly and it now works.
I do have a couple more comments to reduce API calls, code complexity and readability.
Please have a look.
@@ -49,10 +49,9 @@ Previous discussion on this code: | |||
====== | |||
{{ conversation_history|trim }} | |||
====== | |||
Consider both the previous review comments from authors and reviewers, as well as any previous questions and answers about this code. The "Previous Question" and "Previous AI Answer" show earlier interactions about the same code. Use this context to provide a more informed and consistent answer. | |||
Use this prior discussion context to provide a consistent and informed answer. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please make this more informative by describing the conversation structure and how the model should handle it.
pr_agent/tools/pr_line_questions.py
Outdated
@@ -16,7 +16,7 @@ | |||
from pr_agent.git_providers.git_provider import get_main_pr_language | |||
from pr_agent.log import get_logger | |||
from pr_agent.servers.help import HelpMessage | |||
|
|||
from pr_agent.git_providers.github_provider import GithubProvider |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please place this import in order with the others, next to the from pr_agent.git_providers...
imports.
pr_agent/tools/pr_line_questions.py
Outdated
@@ -103,70 +101,41 @@ async def run(self): | |||
|
|||
def _load_conversation_history(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This function currently introduces unnecessary side effects, making the code harder to read and follow. Let's build the conversation string inside the function and return it, so the run
function can handle its output.
def _load_conversation_history(self): | |
def _load_conversation_history(self) -> str: |
pr_agent/tools/pr_line_questions.py
Outdated
except Exception as e: | ||
get_logger().error(f"Error loading conversation history: {e}") | ||
self.vars["conversation_history"] = "" | ||
get_logger().error(f"Error processing conversation history, error: {e}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's return an empty string in case the code crashes.
sibling_ids = find_all_descendants_of_ancestor(ancestor_id) | ||
thread_ids.update(sibling_ids) | ||
# Get all comments | ||
all_comments = list(self.pr.get_comments()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here, you're collecting all PR comments. You can expect to find the given comment_id
within this list, making the comment = self.pr.get_comment(comment_id)
code line redundant and reducing the number of API calls by half, from 2 to 1.
pr_agent/tools/pr_line_questions.py
Outdated
if not all([comment_id, file_path, line_number]): | ||
return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets log this
thread_comments = [ | ||
c for c in all_comments | ||
if c.path == file_path and (c.raw_data.get("line") == line_number or c.raw_data.get("original_line") == line_number) | ||
] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is too general; let's work with comment IDs instead of non-unique attributes.
Hint: look for in_reply_to_id
pr_agent/tools/pr_line_questions.py
Outdated
self.vars["conversation_history"] = "" | ||
# transform and save conversation history | ||
if conversation_history: | ||
self.vars["conversation_history"] = "\n\n".join(conversation_history) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please improve the sense of order in this string, for example, count the comments.
@ofir-frd Thank you for your kind review! I've implemented all the refactoring changes you suggested. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good!
Last short round of comments.
Co-authored-by: ofir-frd <[email protected]>
Co-authored-by: ofir-frd <[email protected]>
Co-authored-by: ofir-frd <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @benedict-lee !
Code approved!
User description
Background.
When using the ask_line tool, conversations from existing author and reviewers are not included in the context.
Changes
PR Review thread example

Prompt example

PR Type
Enhancement, Tests
Description
Added functionality to retrieve and process review thread comments.
Enhanced AI prompts with conversation history for better context.
Updated configuration to enable conversation history usage.
Improved PR line question handling with review thread integration.
Changes walkthrough 📝
git_provider.py
Add methods for review comment and thread retrieval
pr_agent/git_providers/git_provider.py
interface.
github_provider.py
Implement GitHub-specific review thread comment handling
pr_agent/git_providers/github_provider.py
PyGitHub.
pr_line_questions.py
Integrate conversation history into PR line questions
pr_agent/tools/pr_line_questions.py
pr_line_questions_prompts.toml
Update AI prompts to include conversation history
pr_agent/settings/pr_line_questions_prompts.toml
configuration.toml
Add configuration for conversation history usage
pr_agent/settings/configuration.toml
use_conversation_history
setting underpr_questions
.