fix: save_rule falls back to user profile when AssistantRule 404

The AssistantRule entity may not exist on some CRM instances. When save_rule
gets a 404, it now falls back to saving the rule in the local user profile
(update_user_profile). Also improved update_user_profile description so
Shira is more likely to use it for user preferences.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-04-13 20:10:10 +00:00
parent 4aad81e11e
commit a990f527a2
2 changed files with 10 additions and 2 deletions
+4 -2
View File
@@ -186,8 +186,10 @@ def register_memory_tools(tools: dict, case_id: str | None, user_id: str | None)
tools["update_user_profile"] = {
"description": (
"Manage the lawyer's personal profile — preferences, communication style, common case types. "
"This persists across conversations. Use proactively when you learn about the user's preferences."
"Manage the lawyer's personal profile — preferences, rules, communication style, common case types. "
"This persists across conversations. Use proactively when you learn about the user's preferences. "
"Also use this when the user says 'from now on always...', 'I prefer...', 'remember that I...'"
"save their preference here so you remember it in future conversations."
),
"parameters": {
"type": "object",
+6
View File
@@ -191,6 +191,7 @@ def register_crm_tools(
return fail(f"שגיאה בשמירת זיכרון: {e}")
async def save_rule(name: str, rule: str, scope: str = "global") -> str:
# Try CRM first, fall back to local user profile if entity doesn't exist
try:
result = await crm.post("AssistantRule", {
"name": name,
@@ -200,6 +201,11 @@ def register_crm_tools(
})
return ok(f'כלל חדש נשמר: "{name}" (ID: {result["id"]})')
except Exception as e:
if "404" in str(e) and user_id:
# AssistantRule entity not available — save to user profile instead
from api.services.memory import update_user_profile
entry = f"כלל [{scope}] {name}: {rule}"
return await update_user_profile(user_id, "add", entry)
return fail(f"שגיאה בשמירת כלל: {e}")
# Register all tools