feat: timestamped chat history with session tracking#277
Open
Matt Mo (supmo668) wants to merge 3 commits intolangchain-ai:mainfrom
Open
feat: timestamped chat history with session tracking#277Matt Mo (supmo668) wants to merge 3 commits intolangchain-ai:mainfrom
Matt Mo (supmo668) wants to merge 3 commits intolangchain-ai:mainfrom
Conversation
- 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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
created_atis injected into each message'sadditional_kwargs["created_at"]as an ISO 8601 string when retrieved viaget_messages()/aget_messages(){table}_sessionstable 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 sessionget_session_info()/aget_session_info()— returns dict withcreated_at,last_message_time,message_count(orNoneif no messages)get_last_message_time()/aget_last_message_time()— convenience accessor for session last active timetests/utils.pyto use standard local postgres (postgres:postgres@localhost:5432) with env var overrides for CITest plan
test_sync_chat_history— basic CRUD (updated foradditional_kwargs)test_async_chat_history— async equivalenttest_sync_message_timestamps— verifiescreated_atinadditional_kwargswith recency checktest_async_message_timestamps— async equivalenttest_sync_session_info— session created_at, last_message_time, message_count; persistence after cleartest_async_session_info— async equivalenttest_sync_use_timestamp_with_retrieval— explicit timestamp round-trip viause_timestamp=Truetest_sync_empty_session_info—Nonefor empty sessiontest_sync_multiple_sessions_independent— session isolation across multiple sessionsAll 9 tests pass. mypy, ruff check, and ruff format all clean.