The ChatHistory interface has been streamlined in v1.0. Manual context window management and memory-based key management have been removed in favor of an automated truncation system and a new Context facade.
1. Message Retrieval
getMessages() now returns a MessageArray instead of a plain array. MessageArray implements Countable and IteratorAggregate, so existing foreach loops will still work, but you can now use helper methods like ->all(), ->first(), and ->last().
2. Context Truncation
Instead of manually calling setContextWindow() or truncateOldMessages(), configure truncation directly on the Agent class:
$enableTruncation = true$truncationThreshold = 50000
3. Chat Key and Identity Management
Manual memory management methods (like saveKeyToMemory()) are removed. Use the LarAgent\Facades\Context facade or Agent methods to manage chat identities and storage.
Using the Context Facade:
Context::of(MyAgent::class)->getChatKeys(): Get all chat history keys for a specific agent class.Context::named('MyAgent')->getChatKeys(): Lightweight access by agent name.Context::of(MyAgent::class)->forUser('user-123')->clear(): Clear chats for a specific user.Context::of(MyAgent::class)->removeAllChats(): Deletes all chats entirely.
// ✅ AFTER (v1.0) - Handling MessageArray
$messages = $chatHistory->getMessages(); // returns MessageArray
foreach ($messages as $msg) { ... }
$first = $messages->first();
// ✅ AFTER (v1.0) - Context Management via Facade
use LarAgent\Facades\Context;
Context::of(MyAgent::class)->forUser('user-123')->clear(); // Clear specific user chats
Context::of(MyAgent::class)->removeAllChats(); // Delete everything