Skip to content

Latest commit

 

History

1 Commit

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 

Repository files navigation

Time Awareness for Open WebUI

A Filter Function that gives every LLM real-time and historical awareness of when things happened.

On every chat turn the model receives:

  1. The current wall-clock time — auto-detected from the user's timezone (Open WebUI already collects this at login).
  2. A chronological timeline of the past conversation — with each message's real timestamp pulled from Open WebUI's chat_message database table.

What the model sees

# Temporal Awareness

The current time is: 2026-07-15 16:23:00 CEST.

Conversation timeline (each turn's real timestamp, oldest first):
- [2026-07-15 14:30:02 CEST] user: Hi, can you remind me what we discussed last week…
- [2026-07-15 14:30:45 CEST] assistant: Last week we outlined three pillars for Q3…
- [2026-07-15 16:21:11 CEST] user: Great. Now what about the budget?
- [2026-07-15 16:22:38 CEST] assistant: For the budget…

Use the timestamps above to reason about when each message was sent. When the user
asks about something that happened earlier, later, or "now", refer to this temporal context.

Why it survives everything

Scenario What happens
Page reload Timestamps are fetched fresh from the DB on the next request.
Browser cache cleared Same — DB is the source of truth.
Open WebUI server restart Filter reloads from request.app.state.FUNCTIONS; DB still has everything.
New chat Only "current time" is injected until a prior message exists.
Direct API call (no chat_id) Only "current time" is injected. Timeline is skipped.

How it works

Open WebUI's middleware.py strips timestamp from body["messages"] before inlet() runs. This filter works around that by calling Chats.get_messages_map_by_chat_id() directly — the same internal method Open WebUI uses to reconstruct conversation history, and it does include timestamp.

Installation

Admin Panel (recommended)

  1. Open Open WebUI as an admin.
  2. Admin Panel → Functions → Create
  3. ID: time_awareness
  4. Name: Time Awareness
  5. Paste the contents of time_awareness.py into the editor.
  6. Save
  7. Toggle Active ON.
  8. (Recommended) Click the globe icon to make it Global — applies to all models automatically.

Import from URL

https://raw.githubusercontent.com/open-webui-timeawareness/main/time_awareness.py

Admin Panel → Functions → Import from URL → paste → Save.

Configuration

Admin settings (Valves)

Valve Default Description
priority 0 Filter ordering. Lower runs first.
inject_current_time True Inject current wall-clock time.
inject_message_timeline True Inject per-message timeline.
time_format %Y-%m-%d %H:%M:%S %Z strftime format string.
default_timezone UTC Fallback IANA timezone.
max_timeline_messages 50 Hard cap on past messages listed.
timeline_preview_chars 60 Characters of each message to include as preview.

User settings (UserValves)

  • Because self.toggle = True, it appears as a clickable chip in the chat input bar.
  • Clicking opens the per-user valve modal where each user can enable/disable it per chat.

Compatibility

  • Open WebUI ≥ 0.5.0 (uses Chats.get_messages_map_by_chat_id).
  • All models — works with native and legacy function calling.
  • No external dependencies — only stdlib (zoneinfo, datetime) plus pydantic (already bundled).

License

MIT

About

Open WebUI Filter Function that injects current time and per-message timestamps into the system prompt so LLMs stay temporally aware.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages