Documentation IndexFetch the complete documentation index at: /llms.txtUse this file to discover all available pages before exploring further.
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
from agno.agent.agent import Agent from agno.memory.v2.db.sqlite import SqliteMemoryDb from agno.memory.v2.memory import Memory, MemoryManager, SessionSummarizer from agno.models.anthropic.claude import Claude from agno.models.google.gemini import Gemini from agno.models.openrouter.openrouter import OpenRouter from rich.pretty import pprint memory_db = SqliteMemoryDb(table_name="memory", db_file="tmp/memory.db") # 您也可以覆盖记忆管理器的整个 `system_message` memory_manager = MemoryManager( model=OpenRouter(id="meta-llama/llama-3.3-70b-instruct"), additional_instructions=""" 重要提示:不要存储任何关于用户姓名的记忆。请直接说“用户”(The User),而不是引用用户的名字。 """, ) # 您也可以覆盖会话摘要器的整个 `system_message` session_summarizer = SessionSummarizer( model=Claude(id="claude-3-5-sonnet-20241022"), additional_instructions=""" 让摘要非常口语化和对话化。 """, ) memory = Memory( db=memory_db, memory_manager=memory_manager, summarizer=session_summarizer, ) # 重置此示例的记忆 memory.clear() john_doe_id = "john_doe@example.com" agent = Agent( model=Gemini(id="gemini-2.0-flash-exp"), memory=memory, enable_user_memories=True, enable_session_summaries=True, user_id=john_doe_id, ) agent.print_response( "我的名字叫John Doe,我喜欢游泳和踢足球。", stream=True ) agent.print_response("我不喜欢游泳", stream=True) memories = memory.get_user_memories(user_id=john_doe_id) print("John Doe 的记忆:") pprint(memories) summary = agent.get_session_summary() print("会话摘要:") pprint(summary)
创建虚拟环境
Terminal
python3 -m venv .venv source .venv/bin/activate
安装库
pip install -U agno rich
运行示例
python cookbook/agent_concepts/memory/10_custom_memory.py