Spaces:
Runtime error
Runtime error
| from typing import Dict, List | |
| import os | |
| from app.llm.client import llm_client | |
| class GeneralAgent: | |
| """Agent for general construction questions and conversations.""" | |
| def __init__(self): | |
| """Initialize general agent with prompt template.""" | |
| prompt_path = os.path.join( | |
| os.path.dirname(__file__), | |
| "..", | |
| "prompts", | |
| "general.txt" | |
| ) | |
| with open(prompt_path, "r") as f: | |
| self.system_prompt = f.read() | |
| def answer(self, query: str, chat_history: List[Dict] = None) -> Dict[str, any]: | |
| """ | |
| Generate answer for general construction queries. | |
| Args: | |
| query: User query string | |
| chat_history: Optional chat history for context | |
| Returns: | |
| Dictionary with 'answer' and 'agent' keys | |
| """ | |
| try: | |
| messages = [{"role": "system", "content": self.system_prompt}] | |
| # Add chat history if provided | |
| if chat_history: | |
| messages.extend(chat_history[-6:]) # Last 3 exchanges | |
| messages.append({"role": "user", "content": query}) | |
| answer = llm_client.get_completion( | |
| messages=messages, | |
| temperature=0.7, | |
| max_tokens=1024 | |
| ) | |
| return { | |
| "answer": answer, | |
| "agent": "general" | |
| } | |
| except Exception as e: | |
| print(f"General agent error: {e}") | |
| return { | |
| "answer": "I apologize, but I encountered an error. Please try again.", | |
| "agent": "general" | |
| } | |
| # Global general agent instance | |
| general_agent = GeneralAgent() | |