Iragent
This project is about using agents as simple as possible with small and large language models
Loading...
Searching...
No Matches
iragent.memory.SummarizerMemory Class Reference
Inheritance diagram for iragent.memory.SummarizerMemory:
iragent.memory.BaseMemory

Public Member Functions

None __init__ (self, AgentFactory agent_factory, int memory_limit=10)
 
None add_history (self, dict|list[dict] msg)
 
- Public Member Functions inherited from iragent.memory.BaseMemory
None __init__ (self)
 
list[dict] get_history (self)
 
None clear_history (self)
 
None add_message (self, Message msg)
 
list[dict] get_messages (self)
 
None clear_messages (self)
 

Public Attributes

 memory_limit = memory_limit
 
 summarizer
 
- Public Attributes inherited from iragent.memory.BaseMemory
list history = []
 
list messages = []
 

Protected Member Functions

 _summarize_history (self)
 

Detailed Description

A memory manager that summarizes conversation history when it exceeds a specified limit.

This class extends `BaseMemory` and adds summarization capabilities using a summarizer agent.
When the number of stored messages exceeds `memory_limit`, the full conversation history is
summarized into a compact representation and stored as a single system message.

Attributes:
    memory_limit (int): The maximum number of messages to retain before triggering summarization.
    summarizer (Agent): A stateless agent used to generate a summary of the current conversation history.

Args:
    agent_factory (AgentFactory): Factory used to create the summarizer agent.
    memory_limit (int, optional): Maximum number of messages before summarizing. Defaults to 10.

Methods:
    add_history(msg):
        Adds new message(s) to memory and summarizes history if the limit is exceeded.

    _summarize_history():
        Internal method that compresses the full message history into a single summary message.

Constructor & Destructor Documentation

◆ __init__()

None iragent.memory.SummarizerMemory.__init__ ( self,
AgentFactory agent_factory,
int memory_limit = 10 )

Member Function Documentation

◆ _summarize_history()

iragent.memory.SummarizerMemory._summarize_history ( self)
protected

◆ add_history()

None iragent.memory.SummarizerMemory.add_history ( self,
dict | list[dict] msg )

Reimplemented from iragent.memory.BaseMemory.

Member Data Documentation

◆ memory_limit

iragent.memory.SummarizerMemory.memory_limit = memory_limit

◆ summarizer

iragent.memory.SummarizerMemory.summarizer
Initial value:
= agent_factory.create_agent(
name="summarizer",
system_prompt=SMART_MEMORY,
max_token= 256,
memory=None
)

The documentation for this class was generated from the following file: