Skip to content

feat: timestamped chat history with session tracking#277

Open
Matt Mo (supmo668) wants to merge 3 commits intolangchain-ai:mainfrom
supmo668:feature/timestamped-chat-history
Open

feat: timestamped chat history with session tracking#277
Matt Mo (supmo668) wants to merge 3 commits intolangchain-ai:mainfrom
supmo668:feature/timestamped-chat-history

Conversation

@supmo668
Copy link
Copy Markdown

Summary

  • Message timestamps on retrieval: created_at is injected into each message's additional_kwargs["created_at"] as an ISO 8601 string when retrieved via get_messages() / aget_messages()
  • Session tracking table: A new {table}_sessions table with:
    • created_at — timestamp of the first message (session start time)
    • last_message_time — timestamp of the most recent message (session last active)
    • message_count — running total of messages added to the session
  • New methods:
    • get_session_info() / aget_session_info() — returns dict with created_at, last_message_time, message_count (or None if no messages)
    • get_last_message_time() / aget_last_message_time() — convenience accessor for session last active time
  • Test defaults: Updated tests/utils.py to use standard local postgres (postgres:postgres@localhost:5432) with env var overrides for CI

Test plan

  • test_sync_chat_history — basic CRUD (updated for additional_kwargs)
  • test_async_chat_history — async equivalent
  • test_sync_message_timestamps — verifies created_at in additional_kwargs with recency check
  • test_async_message_timestamps — async equivalent
  • test_sync_session_info — session created_at, last_message_time, message_count; persistence after clear
  • test_async_session_info — async equivalent
  • test_sync_use_timestamp_with_retrieval — explicit timestamp round-trip via use_timestamp=True
  • test_sync_empty_session_infoNone for empty session
  • test_sync_multiple_sessions_independent — session isolation across multiple sessions

All 9 tests pass. mypy, ruff check, and ruff format all clean.

Matt Mo (supmo668) and others added 3 commits February 4, 2026 12:05
- Add use_timestamp parameter to add_messages() and aadd_messages()
- Add _insert_message_query_timestamped() for explicit timestamp inserts
- Add _get_message_timestamp() helper to extract timestamps from messages
- Support timestamps via message.created_at or additional_kwargs['created_at']
- Maintains full backward compatibility (default use_timestamp=False)
…sageHistory

- Inject `created_at` into `additional_kwargs["created_at"]` on message retrieval
- Add `{table}_sessions` table tracking `last_message_time` per session via UPSERT
- Add `get_last_message_time()` / `aget_last_message_time()` methods
- Update test defaults to use standard local postgres (postgres:postgres@localhost:5432)
- Add comprehensive tests for timestamps, session tracking, and multi-session isolation

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Extend the session schema with:
- created_at: timestamp of first message (session start time)
- message_count: running total of messages added to the session

Add get_session_info() / aget_session_info() returning a dict with
created_at, last_message_time, and message_count. The existing
get_last_message_time() / aget_last_message_time() now delegate to
session_info internally.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant