From 9906ec3687dbfc2666731ab45c5308059f428a68 Mon Sep 17 00:00:00 2001 From: "benedict.lee" Date: Mon, 21 Apr 2025 17:14:36 +0900 Subject: [PATCH] Improve conversation history formatting with numbered comments --- .../settings/pr_line_questions_prompts.toml | 2 +- pr_agent/tools/pr_line_questions.py | 19 ++++++++++++------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/pr_agent/settings/pr_line_questions_prompts.toml b/pr_agent/settings/pr_line_questions_prompts.toml index 24608313..93cdab86 100644 --- a/pr_agent/settings/pr_line_questions_prompts.toml +++ b/pr_agent/settings/pr_line_questions_prompts.toml @@ -50,7 +50,7 @@ Previous discussion on this code: {{ conversation_history|trim }} ====== -Consider this conversation history (format: "Username: Message"). When responding: +Consider this conversation history (format: "N. Username: Message", where numbers indicate the comment order). When responding: - Maintain consistency with previous technical explanations - Address unresolved issues from earlier discussions - Build upon existing knowledge without contradictions diff --git a/pr_agent/tools/pr_line_questions.py b/pr_agent/tools/pr_line_questions.py index c5cc234c..f373a4a1 100644 --- a/pr_agent/tools/pr_line_questions.py +++ b/pr_agent/tools/pr_line_questions.py @@ -119,8 +119,8 @@ class PR_LineQuestions: # retrieve thread comments thread_comments = self.git_provider.get_review_thread_comments(comment_id) - # generate conversation history - conversation_history = [] + # filter and prepare comments + filtered_comments = [] for comment in thread_comments: body = getattr(comment, 'body', '') @@ -130,12 +130,17 @@ class PR_LineQuestions: user = comment.user author = user.login if hasattr(user, 'login') else 'Unknown' - conversation_history.append(f"{author}: {body}") + filtered_comments.append((author, body)) - # transform conversation history to string - if conversation_history: - get_logger().info(f"Loaded {len(conversation_history)} comments from the code review thread") - return "\n\n".join(conversation_history) + # transform conversation history to string using the same pattern as get_commit_messages + if filtered_comments: + comment_count = len(filtered_comments) + get_logger().info(f"Loaded {comment_count} comments from the code review thread") + + # Format as numbered list, similar to get_commit_messages + conversation_history_str = "\n".join([f"{i + 1}. {author}: {body}" + for i, (author, body) in enumerate(filtered_comments)]) + return conversation_history_str return ""