enable_agentic_memory=True。
代码
cookbook/agent_concepts/memory/07_agentic_memory.py
from agno.agent.agent import Agent
from agno.memory.v2.db.sqlite import SqliteMemoryDb
from agno.memory.v2.memory import Memory
from agno.models.openai import OpenAIChat
from rich.pretty import pprint
memory_db = SqliteMemoryDb(table_name="memory", db_file="tmp/memory.db")
# 无需设置模型,它会被智能体设置为智能体的模型
memory = Memory(db=memory_db)
# 重置此示例的记忆
memory.clear()
john_doe_id = "john_doe@example.com"
agent = Agent(
model=OpenAIChat(id="gpt-4o-mini"),
memory=memory,
enable_agentic_memory=True,
)
agent.print_response(
"My name is John Doe and I like to hike in the mountains on weekends.",
stream=True,
user_id=john_doe_id,
)
agent.print_response("What are my hobbies?", stream=True, user_id=john_doe_id)
memories = memory.get_user_memories(user_id=john_doe_id)
print("Memories about John Doe:")
pprint(memories)
agent.print_response(
"Remove all existing memories of me.",
stream=True,
user_id=john_doe_id,
)
memories = memory.get_user_memories(user_id=john_doe_id)
print("Memories about John Doe:")
pprint(memories)
agent.print_response(
"My name is John Doe and I like to paint.", stream=True, user_id=john_doe_id
)
memories = memory.get_user_memories(user_id=john_doe_id)
print("Memories about John Doe:")
pprint(memories)
agent.print_response(
"I don't pain anymore, i draw instead.", stream=True, user_id=john_doe_id
)
memories = memory.get_user_memories(user_id=john_doe_id)
print("Memories about John Doe:")
pprint(memories)