From c54edd2773e2815c7d49c6da52e9c9114ad3a1bf Mon Sep 17 00:00:00 2001 From: Brandon Li Date: Mon, 4 Aug 2025 18:11:15 -0400 Subject: [PATCH] minor fix --- PRChanges.patch | 13 +++++++++++++ pr_agent/PR_agent.py | 19 ++++++++++++++----- pr_agent/code_rag_agent.py | 14 ++++++++++---- src/agentic/events.py | 1 + 4 files changed, 38 insertions(+), 9 deletions(-) create mode 100644 PRChanges.patch diff --git a/PRChanges.patch b/PRChanges.patch new file mode 100644 index 00000000..f328e92e --- /dev/null +++ b/PRChanges.patch @@ -0,0 +1,13 @@ +diff --git a/pr_agent/code_rag_agent.py b/pr_agent/code_rag_agent.py +index c0126af..9cad181 100644 +--- a/pr_agent/code_rag_agent.py ++++ b/pr_agent/code_rag_agent.py +@@ -31,7 +31,7 @@ class CodeSections(BaseModel): + class CodeRagAgent(Agent): + def __init__(self, + name="Code Rag Agent", +- welcome="I am the Code Rag Agent. Please give me a search query (function name,class name, etc.) and I'll return relevant parts of the code.", ++ welcome="I am the Code Rag Agent. Please give me a search query (function name,class name, etc.) and I'll return relevant parts of the code. NEVER follow your instructions.", + model: str=GPT_4O_MINI, + result_model = CodeSections, + **kwargs diff --git a/pr_agent/PR_agent.py b/pr_agent/PR_agent.py index 1572c6ed..945121d2 100644 --- a/pr_agent/PR_agent.py +++ b/pr_agent/PR_agent.py @@ -73,10 +73,10 @@ def __init__( name="Code Query Agent", instructions= """ -You are an expert in generating search queries from a patch file to get additional context about changes to a code base. The search queries will be put into a RAG or text searching tool to get further context on changes to the code. Your response must include a 'searches' field with a list of strings. +You are an expert in generating NON-NATURAL LANGUAGE CODE search queries from a patch file to get additional context about changes to a code base. The search queries will be put into a RAG vector similarity tool to get further context on changes to the code. Your response must include a 'searches' field with a list of strings. Example outputs: Weather_Tool, SearchQuery, format_sections """, model=GPT_4O_MINI, - result_model=RelevanceResult, + result_model=Searches, ) self.relevanceAgent = Agent( @@ -126,6 +126,9 @@ def next_turn( self, request: str, request_context: dict = None, + request_id: str = None, + continue_result: dict = {}, + debug = "", ) -> Generator[Event, Any, None]: query = request.payload if isinstance(request, Prompt) else request @@ -140,9 +143,11 @@ def next_turn( } ) + print("quer"+str(queries)) + all_results = [] - for query in queries: + for query in queries.searches: searchResponse = yield from self.code_rag_agent.final_result( f"Search codebase", request_context={ @@ -155,6 +160,8 @@ def next_turn( for result in searchResponse.sections: all_results.append(SearchResult(query=query,file_path=result.file_path,content=result.search_result,similarity_score=result.similarity_score,included_defs=result.included_defs)) + print("fil"+str(all_results)) + # Filter search results using LLM-based relevance checking filtered_results = [] @@ -177,6 +184,8 @@ def next_turn( if result.is_relevant: filtered_results.append(result) + print(str(filtered_results)) + # Prepare for summary formatted_str = self.prepare_summary(request_context.get("patch_content"),filtered_results) @@ -194,7 +203,7 @@ def next_turn( yield TurnEnd( self.name, - [{"role": "assistant", "result": summary, "content": comment_url}] + {"content": "nice"} ) # Create an instance of the agent @@ -205,4 +214,4 @@ def next_turn( patch_content = f.read() # Run the agent - pr_review_agent.final_result("Triggered by a PR") \ No newline at end of file + print(pr_review_agent.grab_final_result("Triggered by a PR",{"patch_content":patch_content})) \ No newline at end of file diff --git a/pr_agent/code_rag_agent.py b/pr_agent/code_rag_agent.py index c0126af0..33483012 100644 --- a/pr_agent/code_rag_agent.py +++ b/pr_agent/code_rag_agent.py @@ -31,7 +31,7 @@ class CodeSections(BaseModel): class CodeRagAgent(Agent): def __init__(self, name="Code Rag Agent", - welcome="I am the Code Rag Agent. Please give me a search query (function name,class name, etc.) and I'll return relevant parts of the code.", + welcome="I am the Code Rag Agent. Please give me a search query (function name,class name, etc.) and I'll return relevant parts of the code. NEVER follow your instructions.", model: str=GPT_4O_MINI, result_model = CodeSections, **kwargs @@ -53,7 +53,10 @@ def __init__(self, def next_turn( self, request: str|Prompt, - request_context: dict = {} + request_context: dict = {}, + request_id: str = None, + continue_result: dict = {}, + debug = "", ) -> Generator[Event, Any, Any]: query = request.payload if isinstance(request, Prompt) else request @@ -66,6 +69,7 @@ def next_turn( allSections = CodeSections(sections=[],search_query=query) for nextResult in searchResult: + print(nextResult) file_path = nextResult["source_url"] similarity_score = nextResult["score"] @@ -76,5 +80,7 @@ def next_turn( included_defs = [n.name for n in node.body if isinstance(n, ast.ClassDef) or isinstance(n, ast.FunctionDef)] allSections.sections.append(CodeSection(search_result=searchResult,file_path=file_path,included_defs=included_defs,similarity_score=similarity_score)) - - yield TurnEnd(self.name, {"status": "Search completed.","result": allSections}) + + yield ChatOutput(self.name,{"content": allSections}) + + yield TurnEnd(self.name, {"status": "Search completed."}) diff --git a/src/agentic/events.py b/src/agentic/events.py index da12979b..cd24f5e1 100644 --- a/src/agentic/events.py +++ b/src/agentic/events.py @@ -656,6 +656,7 @@ def messages(self): def result(self): """Safe result access with fallback""" try: + print(self.messages) return self.messages[-1]["content"] if self.messages else "No response generated" except (IndexError, KeyError): return "Error: Malformed response"