Collection Memory ​
Collection memory is temporary and lasts only for the duration of the application's lifecycle, storing messages in an array. Once the application finishes, the memory is lost.
Getting Started ​
To use collection memory, follow these steps:
- Add the
HasMemory
trait and implement theresolveMemory
method in your agent. - Include the
ManagesMemory
trait in your agent. - In your Blade prompt view, use the
@include('synapse::Parts.MemoryAsMessages')
snippet to display the memory as messages. - Set the memory type to
CollectionMemory
in theresolveMemory
method.
IMPORTANT
To keep things simple with memory, the handle
method input should always have an input
key. This is what is stored as the user's content. For example:$agent->handle(['input' => 'How Are you?']);
Example:
php
<?php
use UseTheFork\Synapse\Agent;
use UseTheFork\Synapse\Integrations\OpenAIIntegration;
use UseTheFork\Synapse\Memory\CollectionMemory;
use UseTheFork\Synapse\Contracts\Agent\HasMemory;
use UseTheFork\Synapse\Traits\Agent\ManagesMemory;
class SimpleAgent extends Agent implements HasMemory
{
use ManagesMemory;
protected string $promptView = 'synapse::Prompts.SimplePrompt';
public function resolveIntegration(): Integration
{
return new OpenAIIntegration();
}
public function resolveMemory(): Memory
{
return new CollectionMemory();
}
}