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:
@@ -186,8 +186,10 @@ def register_memory_tools(tools: dict, case_id: str | None, user_id: str | None)
|
|||||||
|
|
||||||
tools["update_user_profile"] = {
|
tools["update_user_profile"] = {
|
||||||
"description": (
|
"description": (
|
||||||
"Manage the lawyer's personal profile — preferences, communication style, common case types. "
|
"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."
|
"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": {
|
"parameters": {
|
||||||
"type": "object",
|
"type": "object",
|
||||||
|
|||||||
@@ -191,6 +191,7 @@ def register_crm_tools(
|
|||||||
return fail(f"שגיאה בשמירת זיכרון: {e}")
|
return fail(f"שגיאה בשמירת זיכרון: {e}")
|
||||||
|
|
||||||
async def save_rule(name: str, rule: str, scope: str = "global") -> str:
|
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:
|
try:
|
||||||
result = await crm.post("AssistantRule", {
|
result = await crm.post("AssistantRule", {
|
||||||
"name": name,
|
"name": name,
|
||||||
@@ -200,6 +201,11 @@ def register_crm_tools(
|
|||||||
})
|
})
|
||||||
return ok(f'כלל חדש נשמר: "{name}" (ID: {result["id"]})')
|
return ok(f'כלל חדש נשמר: "{name}" (ID: {result["id"]})')
|
||||||
except Exception as e:
|
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}")
|
return fail(f"שגיאה בשמירת כלל: {e}")
|
||||||
|
|
||||||
# Register all tools
|
# Register all tools
|
||||||
|
|||||||
Reference in New Issue
Block a user