Skip to content

feat(schema): add CreatedAt field to Message#894

Open
majiayu000 wants to merge 2 commits into
cloudwego:mainfrom
majiayu000:feat/issue-888-add-created-at-to-message
Open

feat(schema): add CreatedAt field to Message#894
majiayu000 wants to merge 2 commits into
cloudwego:mainfrom
majiayu000:feat/issue-888-add-created-at-to-message

Conversation

@majiayu000
Copy link
Copy Markdown

Fixes #888

Changes

  • Add CreatedAt *time.Time field to Message struct with json:"created_at,omitempty" tag
  • Use *time.Time (pointer) so omitempty works correctly across Go 1.18-1.24
  • Auto-populate CreatedAt in all four constructors: UserMessage(), AssistantMessage(), SystemMessage(), ToolMessage()
  • Handle CreatedAt in ConcatMessages: use the earliest non-nil value from input messages (semantically correct for streaming — first chunk represents message creation time)
  • Deep-copy the time.Time value in ConcatMessages to avoid pointer aliasing (consistent with how ResponseMeta/TokenUsage are handled)

Note on AgenticMessage

The issue title mentions schema.AgenticMessage but this type does not exist in the codebase. Only schema.Message is modified.

Test Coverage

  • Constructor tests: verify all four constructors set non-nil CreatedAt close to time.Now()
  • JSON marshal/unmarshal: CreatedAt present when set, omitted when nil
  • ConcatMessages: earliest timestamp selected, nil values handled, pointer independence verified with NotSame()

Add a CreatedAt *time.Time field to schema.Message to support
persisting message timestamps. The field is auto-populated by
all constructor functions (UserMessage, AssistantMessage,
SystemMessage, ToolMessage) and uses the earliest timestamp
when concatenating messages via ConcatMessages.

Signed-off-by: majiayu000 <1835304752@qq.com>
…aliasing

Copy the time.Time value instead of sharing the pointer with input
messages, consistent with how other pointer fields (ResponseMeta,
TokenUsage, LogProbs) are handled. Add test asserting pointer
independence.

Signed-off-by: majiayu000 <1835304752@qq.com>
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented Mar 17, 2026

CLA assistant check
All committers have signed the CLA.

@majiayu000 majiayu000 marked this pull request as ready for review March 17, 2026 07:28
@shentongmartin shentongmartin added C-enhancement Category: This is a PR that adds a new feature or fixes a bug. D-schema Domain: this issue relates to basic domain entities and definitions in eino's schema package labels Apr 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-enhancement Category: This is a PR that adds a new feature or fixes a bug. D-schema Domain: this issue relates to basic domain entities and definitions in eino's schema package

Development

Successfully merging this pull request may close these issues.

[Feature] No message time in schema.Message and schema.AgenticMessage

3 participants