Memory
Give an agent a conversation buffer that persists across turns.
Memory allows an agent to remember previous conversations.
Instead of treating every request as a new conversation, the agent can retain context and generate more natural responses.
Create a Memory#
Python
from abagentsdk import Memory
memory = Memory()Use Memory with an Agent#
agent.py
from abagentsdk import Agent, Memory
memory = Memory()
agent = Agent(
name="Assistant",
instructions="You are a helpful AI assistant.",
model="gemini-2.5-flash",
memory=memory
)Your agent will now remember previous messages during the conversation.
Example#
Python
agent.run("My name is Abu Bakar.")
response = agent.run("What is my name?")
print(response.content)Example Output
Output
Your name is Abu Bakar.Clearing Memory#
Create a new Memory instance to start a fresh conversation.
Python
memory = Memory()When to Use Memory#
Memory is useful for:
- AI Chatbots
- Customer Support
- Personal Assistants
- Research Assistants
- Voice Assistants
Best Practices#
- Create one memory instance for each conversation.
- Reuse the same memory object during the conversation.
- Create a new memory instance for a new conversation.
Next Step#
Continue to Tools.