# app/graph/nodes/synthesizer.py from app.core.llm_engine import llm from app.core.prompts.rag_prompt import rag_prompt from app.core.prompts.hybrid_prompt import hybrid_prompt from langchain_core.output_parsers import StrOutputParser def synthesizer_node(state): route = state.get("route") general_answer = state.get("general_answer") # ✅ FIX: Use 'in' operator if route == "general": return { **state, "final_answer": general_answer or "I couldn't find relevant information." } # Prepare common inputs query = state["query"] context = state.get("context", "") history = state.get("history", "") # ✅ Route-specific prompt selection if route == "hybrid": chain = hybrid_prompt | llm | StrOutputParser() print("🔀 Using HYBRID prompt (doc snippet + general knowledge)") else: # route == "rag" chain = rag_prompt | llm | StrOutputParser() print("📚 Using RAG prompt (document-only)") answer = chain.invoke({ "context": context, "query": query, "history": history }) return { **state, "final_answer": answer.strip() }