Skip to content

feat(mcp): add reference_time parameter to add_memory tool#1377

Open
daniel-rudaev wants to merge 1 commit intogetzep:mainfrom
D1DX:feat/add-memory-reference-time
Open

feat(mcp): add reference_time parameter to add_memory tool#1377
daniel-rudaev wants to merge 1 commit intogetzep:mainfrom
D1DX:feat/add-memory-reference-time

Conversation

@daniel-rudaev
Copy link
Copy Markdown

Summary

The add_memory MCP tool currently hardcodes reference_time to datetime.now(UTC) in the queue service, even though the underlying Graphiti.add_episode() fully supports it. This means all ingested episodes get the current timestamp regardless of when the content actually occurred, breaking temporal reasoning for historical data.

Use case: When ingesting conversation exports (e.g., ChatGPT, Gmail) spanning years, each episode should carry its original date so Graphiti can correctly:

  • Set valid_at on extracted facts to reflect when events actually happened
  • Use the previous-episode context window with correct temporal ordering
  • Invalidate edges based on actual chronology, not ingestion order

Changes

  • Add optional reference_time (ISO 8601 string) parameter to add_memory tool
  • Parse and pass through to QueueService.add_episode()
  • QueueService passes to Graphiti.add_episode() instead of hardcoding datetime.now()
  • Falls back to datetime.now(UTC) when not provided (preserving existing behavior)

Files changed

  • mcp_server/src/graphiti_mcp_server.py — add param to tool signature + docstring, parse ISO 8601, forward to queue service
  • mcp_server/src/services/queue_service.py — accept + forward reference_time, log it

Test plan

  • Verify add_memory without reference_time still works (defaults to now)
  • Verify add_memory with reference_time="2023-06-15T12:00:00Z" sets valid_at on extracted facts to ~2023-06-15
  • Verify invalid reference_time string logs a warning and falls back to now
  • Verify relative temporal expressions in content (e.g. "last week") are resolved against the provided reference_time

🤖 Generated with Claude Code

@danielchalef
Copy link
Copy Markdown
Member

danielchalef commented Apr 4, 2026

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

The add_memory MCP tool currently hardcodes reference_time to
datetime.now(UTC) in the queue service, even though the underlying
Graphiti.add_episode() fully supports it. This means all ingested
episodes get the current timestamp regardless of when the content
actually occurred, breaking temporal reasoning for historical data.

Changes:
- Add optional reference_time (ISO 8601 string) param to add_memory tool
- Parse and pass through to QueueService.add_episode()
- QueueService passes to Graphiti.add_episode() instead of hardcoding now()
- Falls back to datetime.now(UTC) when not provided (preserving existing behavior)
@daniel-rudaev daniel-rudaev force-pushed the feat/add-memory-reference-time branch from e0ce0d8 to 36166a9 Compare April 5, 2026 04:30
@daniel-rudaev
Copy link
Copy Markdown
Author

I have read the CLA Document and I hereby sign the CLA

danielchalef added a commit that referenced this pull request Apr 5, 2026
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.

2 participants