Sensory Memory
Like human sensory memory, the sensory memory is registers perceptual inputs, and it will receive the observations from the environment, some of sensory memory will be transferred to short-term memory.
NOTE
You should not use the SensoryMemory
directly in most cases, it is designed to receive
the observations from the environment, only a part of sensory memory will be transferred to short-term memory.
Simple Example of Sensory Memory
First, you need to create an instance of SensoryMemory
and then you can use it to store the observations.
from dbgpt.agent import AgentMemory, SensoryMemory
# Create an agent memory, which contains a sensory memory
memory = SensoryMemory(buffer_size=2)
agent_memory: AgentMemory = AgentMemory(memory=memory)
Then, let's create some user messages for testing.
import os
from dbgpt.agent import AgentContext
from dbgpt.model.proxy import OpenAILLMClient
llm_client = OpenAILLMClient(
model_alias="gpt-4o",
api_base=os.getenv("OPENAI_API_BASE"),
api_key=os.getenv("OPENAI_API_KEY"),
)
context: AgentContext = AgentContext(
conv_id="test123",
language="en",
temperature=0.9,
max_new_tokens=2048,
)
messages = [
"When I was 4 years old, I went to primary school for the first time, please tell me a joke",
"When I was 10 years old, I went to middle school for the first time, please tell me a joke",
"When I was 16 years old, I went to high school for the first time, please tell me a joke",
"When I was 18 years old, I went to college for the first time, please tell me a joke",
]
Verifying Remember
import asyncio
from dbgpt.agent import (
ConversableAgent,
ProfileConfig,
LLMConfig,
BlankAction,
UserProxyAgent,
)
async def verify_remember():
joy = (
await ConversableAgent(profile=ProfileConfig(name="Joy", role="Comedians"))
.bind(context)
.bind(LLMConfig(llm_client=llm_client))
.bind(agent_memory)
.bind(BlankAction)
.build()
)
user_proxy = await UserProxyAgent().bind(agent_memory).bind(context).build()
# The turns not more than 2, make sure the agent remembers the previous conversation
for message in messages[:2]:
await user_proxy.initiate_chat(
recipient=joy,
reviewer=user_proxy,
message=message,
)
await user_proxy.initiate_chat(
recipient=joy,
reviewer=user_proxy,
message="How old was I when I went to primary school?"
)
if __name__ == "__main__":
asyncio.run(verify_remember())