Skip to main content

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

Project description

since: temporal context for LLMs

CI Tests

since gives anything in an LLM's context a sense of how old it is — conversation turns, file reads, tool outputs. One library, zero dependencies.

pip install pysince
from since import Store, since_time

For chat apps

Wrap your chat function with @since_time. Every message gets a timestamp. The model sees a timeline instead of a flat list.

from since import Store, since_time
from openai import OpenAI

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

@since_time(store=store, timezone="Asia/Kolkata")
def chat(messages):
    return client.chat.completions.create(model="gpt-4o", messages=messages)

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

Before: ask a vanilla model about past conversations. It has no memory.

> What did we talk about last time?
I don't have information about previous conversations.

After: the model sees when each message happened and how long the gaps were.

> What did we talk about last time?
Welcome back! It's been 2 days since we last spoke.
We were debugging your auth flow — specifically the JWT expiry issue.

The prompt tail the model sees:

Now: Wed Jul 01, 02:36 AM (night)
Session: 9h 2m · 4m active · 3 sittings · 8 messages
Gap: 6h between messages
Stale: "config.py" (read:config.py) invalidated, 14m old

The model knows when things happened, how long ago, and what context is stale.

For coding agents (MCP server)

Same primitive, aimed at files. Stamp a file when you read it. Check staleness before editing.

pysince-mcp

stamp_file_read — call after reading any file you intend to edit:

Stamped read: read:/path/to/config.json

check_staleness — call before editing a previously-read file:

Stale=True (content changed, mtime changed) read 4m ago

If the file changed, the agent re-reads it before acting on cached content. No daemon, no polling — just mtime and content hash comparison at the next turn.

Setup: your MCP client needs a trigger line telling the agent when to call the tools. For Claude Code or Cursor, add to your system instructions:

For every file you read, call stamp_file_read immediately. Before any edit, call check_staleness on files involved in the change.

TTL system

Class Decay Use case
permanent Never Facts, identity
slow Session age Normal conversation
event On invalidate() File reads, tool outputs
ephemeral 5 minutes "ok", "thanks"

Works with any provider

OpenAI, Anthropic, Gemini — @since_time detects the response shape automatically. Pass extract_reply= for anything else.

@since_time(store=store, extract_reply=lambda r: r.content[0].text)
def chat(messages):
    return anthropic.messages.create(model="claude-3-5-sonnet-20241022", messages=messages)

Requirements

  • Python 3.10+
  • Zero dependencies

Install

pip install pysince

The PyPI name is pysince (the since name was taken on PyPI). Import and repo are since.

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.2.6.tar.gz (21.2 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.2.6-py3-none-any.whl (19.2 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pysince-0.2.6.tar.gz
Algorithm Hash digest
SHA256 7547332bc4d7a5745e1513d702722a1b4bbf05b841ae1963cd14d8fb4db7ed80
MD5 7799d5fc84c09dee9214dde753490c6b
BLAKE2b-256 6e6ed8a28045468fb04d3d1c7483da9605253fe060bdce8204f1dfa5ef0c17cf

See more details on using hashes here.

File details

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

File metadata

  • Download URL: pysince-0.2.6-py3-none-any.whl
  • Upload date:
  • Size: 19.2 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.2.6-py3-none-any.whl
Algorithm Hash digest
SHA256 9b2f5620bf659eb36bcb0d3f4177d49c0b07cd737079152c0414c3aa34f844dc
MD5 5eddb349818b1f3df07826fe83536bf2
BLAKE2b-256 29a0188af49e3fb9e7359b8ead2f86f8ea62df48c01f6c1715f080c2dd8f1d22

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