feat(agent): 增加智能体存储和记忆功能

- 引入SqliteAgentStorage和SqliteMemoryDb来实现智能体的持久化存储
- 优化智能体的记忆管理,以支持用户记忆和会话摘要功能
This commit is contained in:
2025-03-31 03:06:38 +08:00
parent 8e871647f6
commit 6d25886286

View File

@@ -15,7 +15,7 @@ from typing import Optional
from dataclasses import dataclass
from dotenv import load_dotenv
from agno.agent import Agent
from agno.agent import Agent, AgentMemory
from agno.models.deepseek import DeepSeek
from agno.knowledge.pdf import PDFKnowledgeBase
from agno.vectordb.lancedb import LanceDb, SearchType
@@ -25,8 +25,9 @@ from agno.tools.mcp import MCPTools
from mcp.client.stdio import stdio_client
from mcp import ClientSession, StdioServerParameters
from agno.knowledge.website import WebsiteKnowledgeBase
from agno.storage.agent.sqlite import SqliteAgentStorage
from agno.memory.db.sqlite import SqliteMemoryDb
async def main():
load_dotenv()
@@ -94,13 +95,31 @@ async def main():
):
agent = Agent(
model=DeepSeek(id="deepseek-chat"),
storage=SqliteAgentStorage(
table_name="agent_sessions", db_file="tmp/agent_storage.db"
),
memory=AgentMemory(
db=SqliteMemoryDb(
table_name="agent_memory", db_file="tmp/agent_storage.db"
),
create_user_memories=True,
create_session_summary=True,
),
# Set add_history_to_messages=true to add the previous chat history to the messages sent to the Model.
#add_history_to_messages=True,
# Number of historical responses to add to the messages.
#num_history_responses=3,
markdown=True,
knowledge=knowledge_base,
search_knowledge=True,
show_tool_calls=True,
tools=[postgres_tools, searxng_tools],
session_id="1",
# Enable the agent to read the chat history
read_chat_history=True,
)
await agent.aprint_response("帮我分析一下aq.public数据库,并给出优化建议", stream=True)
await agent.aprint_response("我现在想要记录用户对智能体和课程的使用权限及使用情况,需要如何设计表结构", stream=True)
# await agent.aprint_response("帮我分析一下aq.public数据库,并给出优化建议", stream=True)
# await agent.aprint_response("阅读下 https://www.lucidchart.com/blog/database-design-best-practices 这篇文章", stream=True)