Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
6 changes: 6 additions & 0 deletions backend/app/agents/devrel/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
from .nodes.react_supervisor import react_supervisor_node, supervisor_decision_router
from .tool_wrappers import web_search_tool_node, faq_handler_tool_node, onboarding_tool_node, github_toolkit_tool_node
from .nodes.generate_response import generate_response_node
from .tool_wrappers import thinking_node_tool_node


logger = logging.getLogger(__name__)

Expand All @@ -38,7 +40,11 @@ def _build_graph(self):
workflow = StateGraph(AgentState)

# Phase 1: Gather Context

workflow.add_node("gather_context", gather_context_node)
workflow.add_node("thinking_node", partial(thinking_node_tool_node, llm=self.llm))
workflow.add_edge("gather_context", "thinking_node")
workflow.add_edge("thinking_node", "react_supervisor")

# Phase 2: ReAct Supervisor - Decide what to do next
workflow.add_node("react_supervisor", partial(react_supervisor_node, llm=self.llm))
Expand Down
34 changes: 34 additions & 0 deletions backend/app/agents/devrel/tool_wrappers.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,3 +55,37 @@ async def github_toolkit_tool_node(state: AgentState, github_toolkit) -> Dict[st
}

return add_tool_result(state, "github_toolkit", tool_result)


async def thinking_node_tool_node(state: AgentState, llm) -> Dict[str, Any]:
"""Rephrase user query into a clean and clear question"""
logger.info(f"Executing Thinking Node for session {state.session_id}")

latest_message = ""
if state.messages:
latest_message = state.messages[-1].get("content", "")
elif state.context.get("original_message"):
latest_message = state.context["original_message"]

# Prompt to rephrase
prompt = (
"Rephrase this user query into a clear and formal question "
"suitable for an FAQ or web search:\n\n"
f"'{latest_message}'"
)
Comment on lines +72 to +76
Copy link
Contributor

@smokeyScraper smokeyScraper Jul 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the ReAct supervisor node is the router right? won't aligning the query this way make it more aligned for FAQ or web search? as this thinking node is present prior to the router

have you tried any interactions, if yes please do share.


from langchain_core.messages import HumanMessage
try:
llm_response = await llm.ainvoke([HumanMessage(content=prompt)])
clean_question = llm_response.content.strip()
except Exception as e:
logger.error(f"Thinking node LLM error: {e}")
clean_question = latest_message # fallback

# Store in state context
state.context["rephrased_query"] = clean_question

return add_tool_result(state, "thinking_node", {
"type": "thinking_node",
"rephrased_query": clean_question
})