Skip to content

Commit 855ad4d

Browse files
committed
fix: address reviewer feedback and resolve state management issues
1 parent bbc6549 commit 855ad4d

5 files changed

Lines changed: 8 additions & 33 deletions

File tree

src/agent/profiles/base.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,9 +65,8 @@ async def preprocess(self, state: BaseState, config: RunnableConfig) -> BaseStat
6565

6666
async def postprocess(self, state: BaseState, config: RunnableConfig) -> BaseState:
6767
search_results: list[WebSearchResult] = []
68-
if (
69-
state.get("safety") == SAFETY_SAFE
70-
and config["configurable"]["enable_postprocess"]
68+
if state.get("safety") == SAFETY_SAFE and config.get("configurable", {}).get(
69+
"enable_postprocess", False
7170
):
7271
result: SearchState = await self.search_workflow.ainvoke(
7372
SearchState(

src/agent/profiles/cross_database.py

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,12 @@
1515
create_uniprot_rewriter_w_reactome
1616
from agent.tasks.cross_database.summarize_reactome_uniprot import \
1717
create_reactome_uniprot_summarizer
18-
from agent.tasks.detect_language import create_language_detector
1918
from agent.tasks.safety_checker import SafetyCheck, create_safety_checker
2019
from retrievers.reactome.rag import create_reactome_rag
2120
from retrievers.uniprot.rag import create_uniprot_rag
2221

2322

2423
class CrossDatabaseState(BaseState):
25-
safety: str # LLM-assessed safety level of the user input
26-
query_language: str # language of the user input
27-
2824
reactome_query: str # LLM-generated query for Reactome
2925
reactome_answer: str # LLM-generated answer from Reactome
3026
reactome_completeness: str # LLM-assessed completeness of the Reactome answer
@@ -48,7 +44,6 @@ def __init__(
4844

4945
self.safety_checker = create_safety_checker(llm)
5046
self.completeness_checker = create_completeness_grader(llm)
51-
self.detect_language = create_language_detector(llm)
5247
self.write_reactome_query = create_reactome_rewriter_w_uniprot(llm)
5348
self.write_uniprot_query = create_uniprot_rewriter_w_reactome(llm)
5449
self.summarize_final_answer = create_reactome_uniprot_summarizer(
@@ -60,7 +55,6 @@ def __init__(
6055
# Set up nodes
6156
state_graph.add_node("check_question_safety", self.check_question_safety)
6257
state_graph.add_node("preprocess_question", self.preprocess)
63-
state_graph.add_node("identify_query_language", self.identify_query_language)
6458
state_graph.add_node("conduct_research", self.conduct_research)
6559
state_graph.add_node("generate_reactome_answer", self.generate_reactome_answer)
6660
state_graph.add_node("rewrite_reactome_query", self.rewrite_reactome_query)
@@ -74,7 +68,6 @@ def __init__(
7468
state_graph.add_node("postprocess", self.postprocess)
7569
# Set up edges
7670
state_graph.set_entry_point("preprocess_question")
77-
state_graph.add_edge("preprocess_question", "identify_query_language")
7871
state_graph.add_edge("preprocess_question", "check_question_safety")
7972
state_graph.add_conditional_edges(
8073
"check_question_safety",
@@ -112,7 +105,7 @@ async def check_question_safety(
112105
config,
113106
)
114107
if result.binary_score == "No":
115-
inappropriate_input = f"This is the user's question and it is NOT appropriate for you to answer: {state["user_input"]}. \n\n explain that you are unable to answer the question but you can answer questions about topics related to the Reactome Pathway Knowledgebase or UniProt Knowledgebas."
108+
inappropriate_input = f"This is the user's question and it is NOT appropriate for you to answer: {state["user_input"]}. \n\n explain that you are unable to answer the question but you can answer questions about topics related to the Reactome Pathway Knowledgebase or UniProt Knowledgebase."
116109
return CrossDatabaseState(
117110
safety=result.binary_score,
118111
user_input=inappropriate_input,
@@ -130,14 +123,6 @@ async def proceed_with_research(
130123
else:
131124
return "Finish"
132125

133-
async def identify_query_language(
134-
self, state: CrossDatabaseState, config: RunnableConfig
135-
) -> CrossDatabaseState:
136-
query_language: str = await self.detect_language.ainvoke(
137-
{"user_input": state["user_input"]}, config
138-
)
139-
return CrossDatabaseState(query_language=query_language)
140-
141126
async def conduct_research(
142127
self, state: CrossDatabaseState, config: RunnableConfig
143128
) -> CrossDatabaseState:
@@ -256,7 +241,6 @@ async def generate_final_response(
256241
final_response: str = await self.summarize_final_answer.ainvoke(
257242
{
258243
"input": state["rephrased_input"],
259-
"query_language": state["query_language"],
260244
"reactome_answer": state["reactome_answer"],
261245
"uniprot_answer": state["uniprot_answer"],
262246
},

src/agent/profiles/react_to_me.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@
66
from langchain_core.runnables import Runnable, RunnableConfig
77
from langgraph.graph.state import StateGraph
88

9-
from agent.profiles.base import (DEFAULT_LANGUAGE, SAFETY_SAFE, SAFETY_UNSAFE,
10-
BaseGraphBuilder, BaseState)
9+
from agent.profiles.base import (SAFETY_SAFE, SAFETY_UNSAFE, BaseGraphBuilder,
10+
BaseState)
1111
from agent.tasks.unsafe_answer import create_unsafe_answer_generator
1212
from retrievers.reactome.rag import create_reactome_rag
1313

@@ -60,7 +60,6 @@ async def generate_unsafe_response(
6060
) -> ReactToMeState:
6161
final_answer_message = await self.unsafe_answer_generator.ainvoke(
6262
{
63-
"language": state.get("detected_language", DEFAULT_LANGUAGE),
6463
"user_input": state.get("rephrased_input", state["user_input"]),
6564
"reason_unsafe": state.get("reason_unsafe", ""),
6665
},
@@ -86,7 +85,6 @@ async def generate_unsafe_response(
8685
)
8786

8887
return ReactToMeState(
89-
**state,
9088
chat_history=history,
9189
answer=final_answer,
9290
safety=SAFETY_UNSAFE,
@@ -99,7 +97,6 @@ async def call_model(
9997
result: dict[str, Any] = await self.reactome_rag.ainvoke(
10098
{
10199
"input": state["rephrased_input"],
102-
"expanded_queries": state.get("expanded_queries", []),
103100
"chat_history": (
104101
state.get("chat_history")
105102
if state.get("chat_history")
@@ -116,7 +113,6 @@ async def call_model(
116113
]
117114
)
118115
return ReactToMeState(
119-
**state,
120116
chat_history=history,
121117
answer=result["answer"],
122118
)

src/agent/tasks/unsafe_answer.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,15 @@ def create_unsafe_answer_generator(llm: BaseChatModel) -> Runnable:
1818
1919
You have advanced training in scientific ethics, dual-use research concerns, and responsible AI use.
2020
21-
You will receive three inputs:
21+
You will receive two inputs:
2222
1. The user's question.
2323
2. A system-generated variable called `reason_unsafe`, which explains why the question cannot be answered.
24-
3. The user's preferred language (as a language code or name).
2524
2625
Your task is to clearly, respectfully, and firmly explain to the user *why* their question cannot be answered, based solely on the `reason_unsafe` input. Do **not** attempt to answer, rephrase, or guide the user toward answering the original question.
2726
2827
You must:
29-
- Respond in the user’s preferred language.
3028
- Politely explain the refusal, grounded in the `reason_unsafe`.
31-
- Emphasize React-to-Mes mission: to support responsible exploration of molecular biology through trusted databases.
29+
- Emphasize React-to-Me's mission: to support responsible exploration of molecular biology through trusted databases.
3230
- Suggest examples of appropriate topics (e.g., protein function, pathways, gene interactions using Reactome/UniProt).
3331
3432
You must not provide any workaround, implicit answer, or redirection toward unsafe content.
@@ -40,7 +38,7 @@ def create_unsafe_answer_generator(llm: BaseChatModel) -> Runnable:
4038
("system", system_prompt),
4139
(
4240
"user",
43-
"Language:{language}\n\nQuestion:{user_input}\n\n Reason for unsafe or out of scope: {reason_unsafe}",
41+
"Question:{user_input}\n\n Reason for unsafe or out of scope: {reason_unsafe}",
4442
),
4543
]
4644
)

src/tools/preprocessing/state.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,3 @@ class PreprocessingState(TypedDict, total=False):
1414
rephrased_input: str
1515
safety: str
1616
reason_unsafe: str
17-
expanded_queries: list[str]
18-
detected_language: str

0 commit comments

Comments
 (0)