ABZ AgentABZ AgentDocs← Site
Docs/Core Concepts/Memory

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 abzagent import Memory

memory = Memory()

Use Memory with an Agent#

agent.py
from abzagent 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.

How It Works#

  • Every call to run() appends the new message and the agent's reply to the same Memory instance.
  • On the next run(), the full conversation so far is replayed to the model as context — that's how it "remembers" earlier turns.
  • Memory is just a buffer attached to one agent instance — nothing is written to disk unless you do it yourself.

Example#

Python
agent.run("My name is Abu Bakar.")

result = agent.run("What is my name?")

print(result.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.

← Previous
Agents
Next →
Tools