Innovation 4: Temporal Awareness Layer

Hassan Uriostegui (EB1A Computer Scientist) & Lic. Fernanda Beltran

← Back to Main Paper | View Production Results

Overview

🎯 Core Innovation

System tracks real elapsed time between messages and adjusts character behavior accordingly. After 4+ hours, characters greet naturally. Otherwise, conversation continues seamlessly.

Why Temporal Awareness Matters

Without time tracking:

With Temporal Awareness

Production Implementation

Core Logic (from servicesTimeAware.py)

def get_time_aware_context(chat):
    """Calculate temporal awareness for conversation"""
    
    # Get elapsed time since last message
    elapsed_seconds = time.time() - chat["last_message_time"]
    total_seconds = time.time() - chat["created_at"]
    
    # Get current datetime in user's timezone
    timezone = chat.get("timezone", "America/Los_Angeles")
    current_datetime = datetime.now(pytz.timezone(timezone))
    formatted_time = current_datetime.strftime("%A, %B %d, %Y at %I:%M %p")
    
    # Determine greeting behavior
    if elapsed_seconds > 4 * 3600:  # 4+ hours
        context = {
            "should_greet": True,
            "elapsed_formatted": format_duration(elapsed_seconds),
            "greeting_note": f"Note: It's been {format_duration(elapsed_seconds)} since last message"
        }
    else:
        context = {
            "should_greet": False,
            "elapsed_formatted": format_duration(elapsed_seconds),
            "continuation_note": "Note: Continue conversation naturally without greeting"
        }
    
    context["current_datetime"] = formatted_time
    context["conversation_age"] = format_duration(total_seconds)
    
    return context


def format_duration(seconds):
    """Format seconds into human-readable duration"""
    if seconds < 60:
        return f"{int(seconds)} seconds"
    elif seconds < 3600:
        return f"{int(seconds / 60)} minutes"
    elif seconds < 86400:
        return f"{int(seconds / 3600)} hours"
    else:
        return f"{int(seconds / 86400)} days"

Integration into Prompts

# TEMPORAL AWARENESS section in every prompt:
# Note: Current date/time: {current_datetime}
# Note: Chat started {conversation_age} ago
# Note: Last spoke {elapsed_formatted} ago
# Note: {greeting_note or continuation_note}

Opening Message Logic

if should_greet:
    prompt += """
# Note: This is first contact or reconnection after long gap
# Note: Start with appropriate greeting (time-aware)
# Note: Reference how long it's been if appropriate
"""
else:
    prompt += """
# Note: Active conversation - continue naturally
# Note: No greeting needed - pick up where left off
"""

Real Examples

Scenario 1: Immediate Response (30 seconds gap)

User: "What's your favorite movie?"
[30 seconds later]
User: "Also, have you seen any good ones lately?"

Character: "oh and yeah! I just watched Everything Everywhere All At Once last week 
and it was INSANE 🤯 like my mind was blown the whole time"

# No greeting - natural continuation

Scenario 2: After 4+ Hours (Morning → Evening)

User: "Good morning! Coffee?"
[8 hours later - 6pm]
User: "How was your day?"

Character: "hey!! omg it's been a long day 😅 morning coffee feels like forever ago lol. 
day was crazy busy with back-to-back meetings but finally done! how was yours?"

# Natural reconnection with time reference

Scenario 3: Next Day

User: "Want to grab lunch?"
[Next day - 18 hours later]
User: "Still on for today?"

Character: "hey! yeah sorry didn't see this yesterday 😬 today works great! 
what time were you thinking?"

# Acknowledges time gap naturally

Step-by-Step Replication

Step 1: Track Message Timestamps

class Chat(db.Model):
    id = db.Column(db.Integer, primary_key=True)
    created_at = db.Column(db.Float, default=time.time)
    last_message_time = db.Column(db.Float, default=time.time)
    timezone = db.Column(db.String(50), default="America/Los_Angeles")

# Update on each message
chat.last_message_time = time.time()
db.session.commit()

Step 2: Calculate Time Deltas

import time
from datetime import datetime
import pytz

elapsed_seconds = time.time() - chat.last_message_time
should_greet = elapsed_seconds > (4 * 3600)  # 4 hours threshold

# Get local time
tz = pytz.timezone(chat.timezone)
current_time = datetime.now(tz).strftime("%A, %B %d, %Y at %I:%M %p")

Step 3: Inject into Prompts

prompt_context = f"""
# TEMPORAL AWARENESS:
# Note: Current date/time: {current_time}
# Note: Chat started {format_duration(total_seconds)} ago
# Note: Last spoke {format_duration(elapsed_seconds)} ago
"""

if should_greet:
    prompt_context += "# Note: Reconnecting after gap - natural greeting appropriate\n"
else:
    prompt_context += "# Note: Active conversation - continue naturally without greeting\n"

Performance Impact

MetricValue
Calculation Time<1ms
Storage2 floats per chat
User Experience ImpactSignificantly improved

Production Result

Tested across 20,000 conversations. Reduces repetitive greetings by 85%. Creates natural conversation flow. View study: wakenai.com/mst-prerelease