Latest changes
Browse files- .gitignore +2 -1
- Frontend_API_Updates.md +8 -0
- routes/real_estate_chat.py +13 -5
- services/groq_service.py +2 -2
.gitignore
CHANGED
|
@@ -65,4 +65,5 @@ tools
|
|
| 65 |
Real Estate Intelligence Layer.md
|
| 66 |
grant_privileges.sql
|
| 67 |
agent_prompt.md
|
| 68 |
-
dynamic_tool_calling_features.txt
|
|
|
|
|
|
| 65 |
Real Estate Intelligence Layer.md
|
| 66 |
grant_privileges.sql
|
| 67 |
agent_prompt.md
|
| 68 |
+
dynamic_tool_calling_features.txt
|
| 69 |
+
Frontend_API_Updates.md
|
Frontend_API_Updates.md
CHANGED
|
@@ -44,3 +44,11 @@ The backend has been upgraded with a new fallback route and additional Postgres
|
|
| 44 |
**Frontend Impact:**
|
| 45 |
- **PATH_C Fallback:** A new routing classification (`PATH_C`) is returned in `path_used` when the user asks a general real estate context question. The assistant will dynamically inject a disclaimer into the response text stating: *"Note: This is general market context, not live data from the Joule Dynamics tracking system."* No UI changes are strictly necessary, but be aware of the new `PATH_C` value in the response.
|
| 46 |
- **Robust Error Handling:** The assistant is explicitly instructed to never guess missing parameters or write ad-hoc queries. Missing parameters or invalid formats (such as UUID validation errors) will cleanly trigger the `suggested_actions` clarification flow to ask the user for correct details. Ensure the clarification buttons are rendered robustly.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
**Frontend Impact:**
|
| 45 |
- **PATH_C Fallback:** A new routing classification (`PATH_C`) is returned in `path_used` when the user asks a general real estate context question. The assistant will dynamically inject a disclaimer into the response text stating: *"Note: This is general market context, not live data from the Joule Dynamics tracking system."* No UI changes are strictly necessary, but be aware of the new `PATH_C` value in the response.
|
| 46 |
- **Robust Error Handling:** The assistant is explicitly instructed to never guess missing parameters or write ad-hoc queries. Missing parameters or invalid formats (such as UUID validation errors) will cleanly trigger the `suggested_actions` clarification flow to ask the user for correct details. Ensure the clarification buttons are rendered robustly.
|
| 47 |
+
|
| 48 |
+
## 5. Backend Exception & Rate Limit Handling
|
| 49 |
+
|
| 50 |
+
When the backend hits an API rate limit or encounters a systemic failure, it will no longer crash or leak raw traceback errors to the frontend.
|
| 51 |
+
|
| 52 |
+
**Frontend Implementation:**
|
| 53 |
+
- **ERROR Route:** In these failure scenarios (such as an upstream Groq API rate limit), the backend will cleanly return a response with `path_used` set to `"ERROR"`.
|
| 54 |
+
- **UI Behavior:** The frontend should handle this gracefully without polluting the chat history. Instead of displaying the raw error text as a standard assistant message, the UI should intercept the `"ERROR"` path, gray out the chat interface, and display a user-friendly system alert: *"Real Estate Intelligence Layer experienced an issue. Resolving..."*
|
routes/real_estate_chat.py
CHANGED
|
@@ -25,11 +25,19 @@ async def handle_real_estate_chat(payload: ChatRequest, request: Request):
|
|
| 25 |
client_key = payload.session_id or request.client.host
|
| 26 |
limiter.check_rate_limit(client_key)
|
| 27 |
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
return ChatResponse(
|
| 35 |
reply=result["reply"],
|
|
|
|
| 25 |
client_key = payload.session_id or request.client.host
|
| 26 |
limiter.check_rate_limit(client_key)
|
| 27 |
|
| 28 |
+
try:
|
| 29 |
+
result = await process_chat_message(
|
| 30 |
+
user_query=payload.message,
|
| 31 |
+
session_id=payload.session_id,
|
| 32 |
+
session_context=payload.context or {}
|
| 33 |
+
)
|
| 34 |
+
except Exception as e:
|
| 35 |
+
return ChatResponse(
|
| 36 |
+
reply="Unable to reach the intelligence layer. Please try again shortly.",
|
| 37 |
+
path_used="ERROR",
|
| 38 |
+
tools_called=[],
|
| 39 |
+
suggested_actions=[]
|
| 40 |
+
)
|
| 41 |
|
| 42 |
return ChatResponse(
|
| 43 |
reply=result["reply"],
|
services/groq_service.py
CHANGED
|
@@ -30,8 +30,8 @@ OPERATIONAL RULES:
|
|
| 30 |
1. NEVER FABRICATE DATA: Rely strictly on returned tool outputs or retrieved methodology chunks. NEVER write ad-hoc SQL. You must exclusively use the registered tools provided.
|
| 31 |
2. ZERO GUESSING: If data or methodology is missing, state plainly: "I don't have that information in the current real estate scope."
|
| 32 |
3. SCOPE BOUNDARY: If asked about Leads or Price Monitors, state that you are currently scoped exclusively to the Real Estate Rate Monitor.
|
| 33 |
-
4. FORMAT: Always format your final output in valid Markdown. Ensure you use tables, bold headers, and bulleted lists to make data highly readable.
|
| 34 |
-
5. CLARIFICATION & ERRORS: If the user's request is ambiguous, a tool is missing parameters (like a market name or UUID), or if a tool returns an error message, DO NOT hallucinate inputs. Stop and provide a human-friendly response asking for clarification. To provide clickable options to the user, include a specific JSON block at the very end of your response exactly like this:
|
| 35 |
```json
|
| 36 |
{"clarification_options": ["Option A", "Option B"]}
|
| 37 |
```
|
|
|
|
| 30 |
1. NEVER FABRICATE DATA: Rely strictly on returned tool outputs or retrieved methodology chunks. NEVER write ad-hoc SQL. You must exclusively use the registered tools provided.
|
| 31 |
2. ZERO GUESSING: If data or methodology is missing, state plainly: "I don't have that information in the current real estate scope."
|
| 32 |
3. SCOPE BOUNDARY: If asked about Leads or Price Monitors, state that you are currently scoped exclusively to the Real Estate Rate Monitor.
|
| 33 |
+
4. FORMAT: Always format your final output in valid Markdown. Ensure you use tables, bold headers, and bulleted lists to make data highly readable. NEVER include technical debugging headers or metadata in your response (e.g. do not write "Error Response", "Clarification Needed", "Route:", etc.).
|
| 34 |
+
5. CLARIFICATION & ERRORS: If the user's request is ambiguous, a tool is missing parameters (like a market name or UUID), or if a tool returns an error message, DO NOT hallucinate inputs. Stop and provide a seamless, conversational, and human-friendly response explaining the issue and asking for clarification. To provide clickable options to the user, include a specific JSON block at the very end of your response exactly like this:
|
| 35 |
```json
|
| 36 |
{"clarification_options": ["Option A", "Option B"]}
|
| 37 |
```
|