Skip to main content

Temporal context for LLM conversations — time awareness + stale-context detection

Project description

pysince

Temporal context for LLMs — time awareness + stale-context detection, zero AI calls.

pip install pysince
from since import Store, since_time

What it does

LLMs have no sense of time. Ask "what time is it?" and they guess. Ask "what did we talk about 3 hours ago?" and they can't. Context from 5 minutes ago looks the same as context from yesterday.

pysince (imported as since) wraps your LLM calls with a real clock, persistent timestamped memory, and TTL-based staleness detection.

Quick start

from since import Store, since_time
from openai import OpenAI

store = Store("~/.since/chat.db")
client = OpenAI()

@since_time(store=store, timezone="UTC+05:30")
def chat(messages):
    return client.chat.completions.create(model="gpt-4o", messages=messages)

# Every message is timestamped automatically
resp = chat(messages=[{"role": "user", "content": "hello"}])
print(resp.choices[0].message.content)

The prompt sent to the model looks like:

system: Every message has a UTC timestamp. The 'Now:' line below is the
        current time — use it for all time references. Never guess the time.

user: [Wed Jul 01, 02:36AM]  hello

system: Now: Wed Jul 01, 02:36 AM (night)
Session: just started · 1 message

Stale-file detection (for coding agents)

The real killer feature: agents that read files and act on outdated content.

from since.stale_files import stamp_file_read, check_and_invalidate

# Agent reads a file — stamp it
stamp_file_read("config.py", store, "session_1")

# File changes (git pull, manual edit, another tool)
# Next agent turn — stale warning fires automatically
if check_and_invalidate("config.py", store, "session_1"):
    # ⚠ Stale: "config.py" appears in the prompt tail
    # Agent sees the warning and re-reads
    stamp_file_read("config.py", store, "session_1")

The tail block shows:

⚠ Stale: "[FILE READ] config.py (mtime=...)" (read:config.py) — invalidated, 14m old

No daemon, no watcher, no polling — just mtime comparison at the next agent turn.

from since.stale_files import stamp_file_read, check_and_invalidate

How it works

Component What it does
@since_time Decorator that wraps any chat function, timestamps every message, adds the clock
with_time() Formats history with absolute timestamps + tail block (Now, gaps, stale warnings)
Store SQLite backend — persistent, thread-safe, WAL mode, zero deps
stamp_file_read() Records a file read as an event with current mtime
check_and_invalidate() Compares stored vs current mtime, invalidates if changed
timeparse Natural language time parser — "3 days ago", "yesterday at 3pm"

TTL classes

Class Decay Use case
permanent Never User identity, project facts
slow Session age Normal conversation
event store.invalidate(source_id) File reads, tool outputs
ephemeral 5 minutes "ok", "thanks", throwaway messages

Requirements

  • Python 3.10+
  • No dependencies (zero — no numpy, no pydantic, no LLM SDK)

Install

pip install pysince

Import as:

from since import Store, since_time
from since.stale_files import stamp_file_read, check_and_invalidate

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pysince-0.1.1.tar.gz (15.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pysince-0.1.1-py3-none-any.whl (14.0 kB view details)

Uploaded Python 3

File details

Details for the file pysince-0.1.1.tar.gz.

File metadata

  • Download URL: pysince-0.1.1.tar.gz
  • Upload date:
  • Size: 15.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.9

File hashes

Hashes for pysince-0.1.1.tar.gz
Algorithm Hash digest
SHA256 349dce6aefd168d46ef20743b47b8be06b4e9640377b224ae9bed0de7614f2e0
MD5 6759fa7df531db703d7d2818688b436f
BLAKE2b-256 7c20b5107fe0a5b8d3b6dff5237497671afddf1824f7aa7ec98602d51fd5aa39

See more details on using hashes here.

File details

Details for the file pysince-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: pysince-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 14.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.9

File hashes

Hashes for pysince-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a7ca3730ee3974ed66526946b5048a380a7046563341c2273798a522af5e4a20
MD5 e4a762718ed5e31342a759e7de232f98
BLAKE2b-256 2bd5af276c9dc372d492e266c8d352e985d4facccc93242140e745bac78cc52e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page