Agno 支持使用 SqliteStorage 类将 Sqlite 用作团队的存储后端。

用法

你需要提供 db_urldb_filedb_engine 中的一个。以下示例使用了 db_file

sqlite_storage_for_team.py
"""
运行:`pip install openai duckduckgo-search newspaper4k lxml_html_clean agno` 来安装依赖项
"""

from typing import List

from agno.agent import Agent
from agno.models.openai import OpenAIChat
from agno.storage.sqlite import SqliteStorage
from agno.team import Team
from agno.tools.duckduckgo import DuckDuckGoTools
from agno.tools.hackernews import HackerNewsTools
from pydantic import BaseModel


class Article(BaseModel):
    title: str
    summary: str
    reference_links: List[str]


hn_researcher = Agent(
    name="HackerNews Researcher",
    model=OpenAIChat("gpt-4o"),
    role="从 hacker news 获取热门故事。",
    tools=[HackerNewsTools()],
)

web_searcher = Agent(
    name="Web Searcher",
    model=OpenAIChat("gpt-4o"),
    role="搜索与主题相关的信息",
    tools=[DuckDuckGoTools()],
    add_datetime_to_instructions=True,
)


hn_team = Team(
    name="HackerNews Team",
    mode="coordinate",
    model=OpenAIChat("gpt-4o"),
    members=[hn_researcher, web_searcher],
    storage=SqliteStorage(
        table_name="team_sessions", db_file="tmp/data.db", auto_upgrade_schema=True
    ),
    instructions=[
        "首先,在 hacker news 上搜索用户想要了解的内容。",
        "然后,让网络搜索器搜索每条信息以获取更多信息。",
        "最后,提供一个深思熟虑且引人入胜的总结。",
    ],
    response_model=Article,
    show_tool_calls=True,
    markdown=True,
    debug_mode=True,
    show_members_responses=True,
)

hn_team.print_response("写一篇关于 hacker news 上排名前 2 的故事的文章")

参数

参数类型默认值描述
table_namestr-要使用的表名。
schemaOptional[str]"ai"Schema 名称,默认为 "ai"。
db_urlOptional[str]None数据库 URL,如果提供的话。
db_engineOptional[Engine]None要使用的数据库引擎。
schema_versionint1Schema 的版本号,默认为 1。
auto_upgrade_schemaboolFalse如果为 true,则在必要时自动升级 schema。

开发者资源