Skip to content

Commit 70175b2

Browse files
authored
Merge pull request #9 from MaestroError/chat-keys-management
Fix chat clear command
2 parents bfa658a + bac5805 commit 70175b2

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -491,7 +491,7 @@ public function lastMessage(): ?MessageInterface;
491491
/**
492492
* Get all chat keys associated with this agent class
493493
*/
494-
public function getChatKeys(): array
494+
public function getChatKeys(): array;
495495
```
496496

497497
### Tools

src/Commands/AgentChatClearCommand.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,9 @@ public function handle()
3131
if (!empty($chatKeys)) {
3232
// Clear each chat history
3333
foreach ($chatKeys as $key) {
34-
$agent = $agentClass::for($key);
34+
// Create new chat history with save_chat_keys disabled
35+
$agent->createChatHistory($key);
36+
// Clear messages
3537
$agent->clear();
3638
}
3739
}

tests/Commands/AgentChatClearCommandTest.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,17 @@ protected function onInitialize()
7272
$agent->message('Hello')->respond();
7373

7474
// Verify chat history exists
75-
expect($agent->getChatKeys())->not->toBeEmpty();
75+
$chatKeys = $agent->getChatKeys();
76+
expect($chatKeys)->toHaveCount(1);
77+
expect($chatKeys)->toContain('TestAgent_gpt-4-mini_test_key');
7678

7779
// Clear the history
7880
$this->artisan('agent:chat:clear', ['agent' => 'TestAgent'])
7981
->assertSuccessful()
8082
->expectsOutput('Successfully cleared chat history for agent: TestAgent');
8183

82-
// Verify chat history is cleared
83-
expect(\App\AiAgents\TestAgent::for('test_key')->chatHistory()->getMessages())->toBeEmpty();
84+
// Verify all chat histories are cleared but keys remain
85+
$agent = \App\AiAgents\TestAgent::for('test_key');
86+
expect($agent->chatHistory()->getMessages())->toBeEmpty();
87+
expect($agent->getChatKeys())->toHaveCount(1);
8488
});

0 commit comments

Comments
 (0)