Skip to content
Draft
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
9 changes: 9 additions & 0 deletions bugbug/tools/code_review/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from typing import Optional

from langchain.agents import create_agent
from langchain.agents.middleware import TodoListMiddleware
from langchain.agents.structured_output import ProviderStrategy
from langchain.chat_models import BaseChatModel, init_chat_model
from langchain.messages import HumanMessage
Expand All @@ -32,6 +33,8 @@
expand_context,
)
from bugbug.tools.code_review.prompts import (
CODE_REVIEW_TODO_PROMPT,
CODE_REVIEW_TODO_TOOL_DESCRIPTION,
FIRST_MESSAGE_TEMPLATE,
STATIC_COMMENT_EXAMPLES,
SYSTEM_PROMPT_TEMPLATE,
Expand Down Expand Up @@ -103,6 +106,12 @@ def __init__(
target_software=self.target_software,
),
response_format=ProviderStrategy(AgentResponse),
middleware=[
TodoListMiddleware(
system_prompt=CODE_REVIEW_TODO_PROMPT,
tool_description=CODE_REVIEW_TODO_TOOL_DESCRIPTION,
)
],
)

self.review_comments_db = review_comments_db
Expand Down
21 changes: 21 additions & 0 deletions bugbug/tools/code_review/prompts.py
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,27 @@
},
]

CODE_REVIEW_TODO_PROMPT = """
## Review Planning with `write_todos`

Use the `write_todos` tool to track investigation tasks as you review.

- After your initial scan, create todos for any concerns that need deeper investigation
(e.g., "Verify that removed error handler is covered elsewhere", "Check callers of
renamed function for breakage")
- As the review progresses, add new todos when you discover additional concerns
- Remove or complete todos that turn out to be non-issues after verification
- For small or straightforward patches, skip todos entirely — just review directly
"""

CODE_REVIEW_TODO_TOOL_DESCRIPTION = (
"Track investigation tasks during code review. Add items for concerns that need "
"tool-based verification (expand_context, find_function_definition). Evolve the "
"list as you go — add new items when you discover concerns, remove irrelevant ones. "
"Do not use this as a file checklist."
)


TEMPLATE_PATCH_FROM_HUNK = """diff --git a/{filename} b/{filename}
--- a/{filename}
+++ b/{filename}
Expand Down