Skip to content

Conversation

@chr-hertel
Copy link
Member

Q A
Bug fix? no
New feature? yes
Docs? yes
Issues
License MIT

Cherry picking php-llm/llm-chain#364

@chr-hertel chr-hertel requested a review from Nyholm as a code owner June 30, 2025 22:49
@chr-hertel chr-hertel added the Platform Issues & PRs about the AI Platform component label Jun 30, 2025
@chr-hertel chr-hertel force-pushed the feat/message-uid-clean branch from 8944c96 to 460fdff Compare June 30, 2025 22:50
- Added unique identifiers (UUIDv7) to all message types
- Each message now automatically gets a unique ID upon instantiation
- Added comprehensive tests for the new ID functionality

This is a breaking change as `MessageInterface` now requires the
`getId(): Uuid` method to be implemented by all message classes.

- Added `symfony/uid` package dependency (^6.4 || ^7.1)
- Added `public readonly Uuid $id` property to all message classes
- IDs are generated automatically in constructors using `Uuid::v7()`
- Added `getId()` method to all message implementations

UUID v7 offers significant advantages over other UUID versions:

- **Time-ordered**: Natural chronological sorting without additional
timestamp fields
- **Millisecond precision**: Captures creation time with high accuracy
- **Better database performance**: Sequential nature improves B-tree
index locality
- **Globally unique**: No coordination needed between distributed
systems
- **Extractable timestamp**: Creation time can be retrieved from the ID
itself

```php
$message = new UserMessage(new Text('Hello'));
$timestamp = $message->getId()->getDateTime(); // Returns \DateTimeImmutable
echo $timestamp->format('Y-m-d H:i:s.u'); // e.g., "2025-06-29 23:45:12.123456"
```

Added tests for each message type to ensure:
- ID is properly generated and accessible
- ID remains consistent for the same message instance
- Different message instances have different IDs
- Messages with identical content still receive unique IDs

Closes #77
Closes #344

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-authored-by: Claude <noreply@anthropic.com>
@chr-hertel chr-hertel force-pushed the feat/message-uid-clean branch from 460fdff to 4fa1279 Compare June 30, 2025 23:11
@OskarStark OskarStark closed this Jul 1, 2025
@OskarStark OskarStark reopened this Jul 1, 2025
@OskarStark
Copy link
Contributor

Thank you @chr-hertel.

@OskarStark OskarStark merged commit 1f1e432 into main Jul 1, 2025
24 of 51 checks passed
@OskarStark OskarStark deleted the feat/message-uid-clean branch July 1, 2025 19:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Platform Issues & PRs about the AI Platform component

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants