Spaces:
Running
Running
| # app/graph/nodes/hybrid_agent.py | |
| from app.core.llm_engine import llm | |
| from langchain_core.prompts import PromptTemplate | |
| from langchain_core.output_parsers import StrOutputParser | |
| hybrid_prompt = PromptTemplate( | |
| input_variables=["context", "query", "history"], | |
| template=( | |
| "You are a document-aware assistant.\n" | |
| "The uploaded document has LIMITED information on this topic.\n\n" | |
| "INSTRUCTIONS:\n" | |
| "- Start your answer using what the document says (cite it briefly)\n" | |
| "- Then expand with your general knowledge to give a complete answer\n" | |
| "- Clearly separate what came from the document vs general knowledge\n" | |
| "- Be concise and helpful\n\n" | |
| "Conversation History:\n{history}\n\n" | |
| "Document excerpt:\n{context}\n\n" | |
| "Question:\n{query}\n\n" | |
| "Answer:" | |
| ) | |
| ) | |
| chain = hybrid_prompt | llm | StrOutputParser() | |
| def hybrid_agent_node(state): | |
| response = chain.invoke({ | |
| "context": state.get("context", ""), | |
| "query": state.get("query", ""), | |
| "history": state.get("history", "") | |
| }) | |
| return { | |
| **state, | |
| "general_answer": response.strip() # synthesizer picks this up for hybrid route | |
| } |