claude-agent-sdk-python icon indicating copy to clipboard operation
claude-agent-sdk-python copied to clipboard

Message models are missing 'timestamp' field

Open danielsiwiec opened this issue 4 months ago • 9 comments

This timestamp field is present in the JSONL file, but the Message types are missing it. Adding it, would be helpful for use cases where the actual Message timestamp is important (ex. displaying a timeline)

danielsiwiec avatar Oct 15 '25 17:10 danielsiwiec

I'm happy to submit a PR for this, if there's an agreement this is useful to have

danielsiwiec avatar Oct 15 '25 17:10 danielsiwiec

greetings, @danielsiwiec do you mind checking this out? also should I prepare tests? although i did mock it

 {
    "type": "assistant",
    "timestamp": 1734300000123,
    "parent_tool_use_id": None,
    "message": {
        "role": "assistant",
        "model": "fake-model",
        "content": [
            {"type": "text", "text": "hello"}
        ]
    }
}
msg = parse_message(raw)
print(type(msg).__name__)
print("timestamp:", getattr(msg, "timestamp", None))
print("model:", getattr(msg, "model", None))
print("content:", getattr(msg, "content", None))

AssistantMessage timestamp: 1734300000123 model: fake-model content: [TextBlock(text='hello')]

vikramsingh117 avatar Oct 15 '25 20:10 vikramsingh117

Hi! 👋

I can add the missing timestamp field to Message models.

Analysis

Message models in agent SDK should include timestamp for tracking message timing and sequencing.

Implementation Plan

  1. Add timestamp field to Message model (datetime type)
  2. Populate on message creation
  3. Update serialization/deserialization
  4. Add tests for timestamp handling
  5. Update type hints + documentation

Questions

  1. ISO 8601 format or Unix timestamp?
  2. Should it be optional (backwards compat) or required?
  3. Timezone: UTC or preserve original?

Background

Experienced with Anthropic SDK patterns, maintained EGOS v.2 with comprehensive message tracking.

Timeline: 2 days

Happy to implement!

enioxt avatar Oct 15 '25 21:10 enioxt

thanks @vikramsingh117 , @enioxt. I already have a PR for this here @ashwin-ant or @dicksontsai - would love a review on this PR 🙏

danielsiwiec avatar Oct 15 '25 23:10 danielsiwiec

@ashwin-ant just bumping this up. hopefully this is nothing controversial and is similar to the other PR I contributed before (basically, extending the types coverage over the serialized json structure). thanks in advance!

danielsiwiec avatar Oct 20 '25 20:10 danielsiwiec

Hey, we're looking into how to support this. I think the open PRs are not actually correct, since adding timestamps requires updating the CC binary to output timestamps in its messages over stdio (something it doesn't currently do). We'll have more here soon!

ashwin-ant avatar Oct 20 '25 21:10 ashwin-ant

@ashwin-ant the current CC binary already outputs "timestamp" per each message (except the SystemMessage). example:

{...,"version":"2.0.19","gitBranch":"","message":{"model":"claude-sonnet-4-5-20250929","id":"msg_bdrk_01V5GhD8qakWV3u9RV23XXfb","type":"message","role":"assistant","content":"..."},"type":"assistant","uuid":"31727d65-53eb-47b3-b843-1b6e1821a534","timestamp":"2025-10-20T10:30:52.256Z"}

danielsiwiec avatar Oct 21 '25 21:10 danielsiwiec

That's visible in the JSONL file but it's not actually coming through the stdio pipe at the moment.

ashwin-ant avatar Oct 21 '25 21:10 ashwin-ant

gotcha, thanks @ashwin-ant . is there anything I can do to help move this along?

danielsiwiec avatar Oct 22 '25 21:10 danielsiwiec