Conversation Summary Memory ​
Conversation Summary memory generates a summary of the entire conversation, including responses from the user, agent, and tool calls. This is a direct implementation of Langchain's conversation summary memory.
Getting Started ​
To implement conversation summary 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
ConversationSummaryMemory
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\ConversationSummaryMemory;
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 ConversationSummaryMemory();
}
}