How to access the date and time of a message from a state in create_react_agent?

Hey there, guys!

I am facing a problem that i need to find a solution for. I need to summarize the conversation every 15 minutes. But i cannot access the timestamp of the first message to check that.
I am using postgres for the checkpoint.

Have anyone found a solution for this?

Hi @FLFortunato

afaik there isn’t a per-message timestamp automatically stored by create_react_agent in the messages state. Instead, LangGraph persists conversation progress as checkpoints that include a creation timestamp. You can use the checkpoint timestamps to compute elapsed time windows (e.g., 15 minutes) and trigger summarization, or add your own message-level timestamps via metadata.

How to retrieve timestamps

  • Current snapshot: graph.get_state(config) returns a StateSnapshot whose created_at is the timestamp of the latest checkpoint.

  • History: graph.get_state_history(config)/graph.aget_state_history(config) yield snapshots with created_at. The earliest snapshot’s created_at can serve as the conversation start time for the configured thread_id/checkpoint_ns.

Practical patterns

  1. Time-based summarization without per-message timestamps

    • On each turn, compare now() to the earliest relevant checkpoint’s created_at (or the last summarization checkpoint) and summarize if >= 15 minutes.
    • Use get_state_history(config, limit=1) to quickly fetch the oldest or newest snapshot depending on implementation; otherwise paginate until you reach the first.
  2. Adding message-level timestamps (optional)

    • Include a timestamp in message metadata when you create HumanMessage/AIMessage (e.g., additional_kwargs={"ts": datetime.utcnow().isoformat()}) so you can compute precise windows across message boundaries.
    • If you want these persisted robustly with reducers, keep them in messages content/metadata so they survive through add_messages reducer merges.
1 Like

Thank you so much, buddy!
Your help saved me haha

1 Like