✨ feat(agent): 增加智能体存储和记忆功能
- 引入SqliteAgentStorage和SqliteMemoryDb来实现智能体的持久化存储 - 优化智能体的记忆管理,以支持用户记忆和会话摘要功能
This commit is contained in:
25
数据库优化工程师.py
25
数据库优化工程师.py
@@ -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,7 +25,8 @@ 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():
|
||||
@@ -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)
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user