Format/Lint

This commit is contained in:
2026-03-05 06:06:01 +00:00
parent 5941c41296
commit db879cee9f
6 changed files with 102 additions and 57 deletions

View File

@@ -34,17 +34,19 @@ async def provide_dynamic_instruction(
"""
# Only check notifications on the first message
if not ctx or not ctx._invocation_context:
if not ctx:
logger.debug("No context available for dynamic instruction")
return ""
session = ctx._invocation_context.session
session = ctx.session
if not session:
logger.debug("No session available for dynamic instruction")
return ""
# FOR TESTING: Always check for notifications (comment out to enable first-message-only)
# Only check on first message (when events list is empty or has only 1-2 events)
# FOR TESTING: Always check for notifications
# (comment out to enable first-message-only)
# Only check on first message (when events list is empty
# or has only 1-2 events)
# Events include both user and agent messages, so < 2 means first interaction
# event_count = len(session.events) if session.events else 0
#
@@ -74,7 +76,11 @@ async def provide_dynamic_instruction(
return ""
# Build dynamic instruction with notification details
notification_ids = [n.get("id_notificacion") for n in pending_notifications]
notification_ids = [
nid
for n in pending_notifications
if (nid := n.get("id_notificacion")) is not None
]
count = len(pending_notifications)
# Format notification details for the agent
@@ -97,9 +103,11 @@ INSTRUCCIONES:
- Menciona estas notificaciones de forma natural en tu respuesta inicial
- No necesitas leerlas todas literalmente, solo hazle saber que las tiene
- Sé breve y directo según tu personalidad (directo y cálido)
- Si el usuario pregunta algo específico, prioriza responder eso primero y luego menciona las notificaciones
- Si el usuario pregunta algo específico, prioriza responder eso primero\
y luego menciona las notificaciones
Ejemplo: "¡Hola! 👋 Antes de empezar, veo que tienes {count} notificación(es) pendiente(s) en tu cuenta. ¿Te gustaría revisarlas o prefieres que te ayude con algo más?"
Ejemplo: "¡Hola! 👋 Tienes {count} notificación(es)\
pendiente(s). ¿Te gustaría revisarlas?"
"""
# Mark notifications as notified in Firestore
@@ -111,10 +119,11 @@ Ejemplo: "¡Hola! 👋 Antes de empezar, veo que tienes {count} notificación(es
phone_number,
)
return instruction
except Exception:
logger.exception(
"Error building dynamic instruction for user %s", phone_number
"Error building dynamic instruction for user %s",
phone_number,
)
return ""
else:
return instruction