From 66f023893ccb2bafe7dc5fbc8d9c692a64602ac6 Mon Sep 17 00:00:00 2001 From: Venkatesh Bharadwaj Srinivasan Date: Sun, 11 Jan 2026 13:26:13 -0800 Subject: [PATCH 1/3] Fix log analysis agent: deprecation warnings, model output parsing, and AttributeError --- community/log_analysis_multi_agent_rag/.env.example | 1 + community/log_analysis_multi_agent_rag/.gitignore | 6 ++++++ .../log_analysis_multi_agent_rag/binary_score_models.py | 2 +- community/log_analysis_multi_agent_rag/graphedges.py | 4 ++-- community/log_analysis_multi_agent_rag/graphnodes.py | 2 +- community/log_analysis_multi_agent_rag/utils.py | 8 ++++---- 6 files changed, 15 insertions(+), 8 deletions(-) create mode 100644 community/log_analysis_multi_agent_rag/.env.example create mode 100644 community/log_analysis_multi_agent_rag/.gitignore diff --git a/community/log_analysis_multi_agent_rag/.env.example b/community/log_analysis_multi_agent_rag/.env.example new file mode 100644 index 000000000..1025b9bc1 --- /dev/null +++ b/community/log_analysis_multi_agent_rag/.env.example @@ -0,0 +1 @@ +API_KEY=nvapi-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx diff --git a/community/log_analysis_multi_agent_rag/.gitignore b/community/log_analysis_multi_agent_rag/.gitignore new file mode 100644 index 000000000..9e01d3dc7 --- /dev/null +++ b/community/log_analysis_multi_agent_rag/.gitignore @@ -0,0 +1,6 @@ +.env +.venv/ +__pycache__/ +*.txt +!requirements.txt +.DS_Store diff --git a/community/log_analysis_multi_agent_rag/binary_score_models.py b/community/log_analysis_multi_agent_rag/binary_score_models.py index d894541a5..f6227e29a 100644 --- a/community/log_analysis_multi_agent_rag/binary_score_models.py +++ b/community/log_analysis_multi_agent_rag/binary_score_models.py @@ -1,4 +1,4 @@ -from langchain_core.pydantic_v1 import BaseModel,Field +from pydantic import BaseModel, Field # Data models class GradeDocuments(BaseModel): """Binary score for relevance check on retrieved documents.""" diff --git a/community/log_analysis_multi_agent_rag/graphedges.py b/community/log_analysis_multi_agent_rag/graphedges.py index c56a2d276..859a6c864 100644 --- a/community/log_analysis_multi_agent_rag/graphedges.py +++ b/community/log_analysis_multi_agent_rag/graphedges.py @@ -40,8 +40,8 @@ def grade_generation_vs_documents_and_question(state): print("GRADE GENERATED vs QUESTION") try: - score_text = automation.answer_grader.invoke({"question": question, "generation": generation}) - if "yes" in score_text.lower(): + score = automation.answer_grader.invoke({"question": question, "generation": generation}) + if score and score.get("binary_score") == "yes": print("DECISION: GENERATION ADDRESSES QUESTION") return "useful" else: diff --git a/community/log_analysis_multi_agent_rag/graphnodes.py b/community/log_analysis_multi_agent_rag/graphnodes.py index 9b257d44f..96d2dec75 100644 --- a/community/log_analysis_multi_agent_rag/graphnodes.py +++ b/community/log_analysis_multi_agent_rag/graphnodes.py @@ -50,7 +50,7 @@ def grade_documents(state): score = automation.retrieval_grader.invoke( {"question": question, "document": doc.page_content} ) - grade = score.binary_score + grade = score.get("binary_score") if score else "no" if grade == "yes": print("---GRADE: DOCUMENT RELEVANT---") filtered_docs.append(doc) diff --git a/community/log_analysis_multi_agent_rag/utils.py b/community/log_analysis_multi_agent_rag/utils.py index 6a787e55e..ae057b39b 100644 --- a/community/log_analysis_multi_agent_rag/utils.py +++ b/community/log_analysis_multi_agent_rag/utils.py @@ -1,6 +1,6 @@ from langchain_nvidia_ai_endpoints import ChatNVIDIA from langchain_core.prompts import ChatPromptTemplate -from langchain_core.output_parsers import StrOutputParser +from langchain_core.output_parsers import StrOutputParser, JsonOutputParser from binary_score_models import GradeAnswer,GradeDocuments,GradeHallucinations import os from dotenv import load_dotenv @@ -41,7 +41,7 @@ def setup_prompts(self): ("human", self.prompts["grade_human"]), ] ) - self.retrieval_grader = grade_prompt | self.llm.with_structured_output(GradeDocuments) + self.retrieval_grader = grade_prompt | self.llm | StrOutputParser() | (lambda text: text.split("")[-1] if "" in text else text) | JsonOutputParser() hallucination_prompt = ChatPromptTemplate.from_messages( [ @@ -49,7 +49,7 @@ def setup_prompts(self): ("human", self.prompts["hallucination_human"]), ] ) - self.hallucination_grader = hallucination_prompt | self.llm.with_structured_output(GradeHallucinations) + self.hallucination_grader = hallucination_prompt | self.llm | StrOutputParser() | (lambda text: text.split("")[-1] if "" in text else text) | JsonOutputParser() answer_prompt = ChatPromptTemplate.from_messages( [ @@ -57,7 +57,7 @@ def setup_prompts(self): ("human", self.prompts["answer_human"]), ] ) - self.answer_grader = answer_prompt | self.llm.with_structured_output(GradeAnswer) + self.answer_grader = answer_prompt | self.llm | StrOutputParser() | (lambda text: text.split("")[-1] if "" in text else text) | JsonOutputParser() def format_docs(self, docs): return "\n\n".join(doc.page_content for doc in docs) From 59ed5455964767f9c2a96e24951255616f34fda5 Mon Sep 17 00:00:00 2001 From: Venkatesh Bharadwaj Srinivasan Date: Sun, 11 Jan 2026 13:38:05 -0800 Subject: [PATCH 2/3] Use robust regex cleaner for model output and restore json import --- community/log_analysis_multi_agent_rag/utils.py | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/community/log_analysis_multi_agent_rag/utils.py b/community/log_analysis_multi_agent_rag/utils.py index ae057b39b..a23398bcf 100644 --- a/community/log_analysis_multi_agent_rag/utils.py +++ b/community/log_analysis_multi_agent_rag/utils.py @@ -5,8 +5,16 @@ import os from dotenv import load_dotenv load_dotenv() +import re import json +def clean_text(text): + # Remove blocks (including content) + text = re.sub(r'.*?', '', text, flags=re.DOTALL) + # Remove any standalone tags just in case + text = text.replace('', '').replace('', '') + return text + class Nodeoutputs: def __init__(self, api_key, model, prompts_file): os.environ["NVIDIA_API_KEY"] = api_key @@ -41,7 +49,7 @@ def setup_prompts(self): ("human", self.prompts["grade_human"]), ] ) - self.retrieval_grader = grade_prompt | self.llm | StrOutputParser() | (lambda text: text.split("")[-1] if "" in text else text) | JsonOutputParser() + self.retrieval_grader = grade_prompt | self.llm | StrOutputParser() | clean_text | JsonOutputParser() hallucination_prompt = ChatPromptTemplate.from_messages( [ @@ -49,7 +57,7 @@ def setup_prompts(self): ("human", self.prompts["hallucination_human"]), ] ) - self.hallucination_grader = hallucination_prompt | self.llm | StrOutputParser() | (lambda text: text.split("")[-1] if "" in text else text) | JsonOutputParser() + self.hallucination_grader = hallucination_prompt | self.llm | StrOutputParser() | clean_text | JsonOutputParser() answer_prompt = ChatPromptTemplate.from_messages( [ @@ -57,7 +65,7 @@ def setup_prompts(self): ("human", self.prompts["answer_human"]), ] ) - self.answer_grader = answer_prompt | self.llm | StrOutputParser() | (lambda text: text.split("")[-1] if "" in text else text) | JsonOutputParser() + self.answer_grader = answer_prompt | self.llm | StrOutputParser() | clean_text | JsonOutputParser() def format_docs(self, docs): return "\n\n".join(doc.page_content for doc in docs) From a588c72cf15ad2c3e4b3df60835547e270e70015 Mon Sep 17 00:00:00 2001 From: Venkatesh Bharadwaj Srinivasan Date: Sun, 11 Jan 2026 13:52:44 -0800 Subject: [PATCH 3/3] Remove .env.example and .gitignore from PR --- community/log_analysis_multi_agent_rag/.env.example | 1 - community/log_analysis_multi_agent_rag/.gitignore | 6 ------ 2 files changed, 7 deletions(-) delete mode 100644 community/log_analysis_multi_agent_rag/.env.example delete mode 100644 community/log_analysis_multi_agent_rag/.gitignore diff --git a/community/log_analysis_multi_agent_rag/.env.example b/community/log_analysis_multi_agent_rag/.env.example deleted file mode 100644 index 1025b9bc1..000000000 --- a/community/log_analysis_multi_agent_rag/.env.example +++ /dev/null @@ -1 +0,0 @@ -API_KEY=nvapi-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx diff --git a/community/log_analysis_multi_agent_rag/.gitignore b/community/log_analysis_multi_agent_rag/.gitignore deleted file mode 100644 index 9e01d3dc7..000000000 --- a/community/log_analysis_multi_agent_rag/.gitignore +++ /dev/null @@ -1,6 +0,0 @@ -.env -.venv/ -__pycache__/ -*.txt -!requirements.txt -.DS_Store