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

用法

你需要为 DynamoDbStorage 类提供 aws_access_key_idaws_secret_access_key 参数。

dynamodb_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.dynamodb import DynamoDbStorage
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="Gets top stories from hackernews.",
    tools=[HackerNewsTools()],
)

web_searcher = Agent(
    name="Web Searcher",
    model=OpenAIChat("gpt-4o"),
    role="Searches the web for information on a topic",
    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=DynamoDbStorage(table_name="team_sessions", region_name="us-east-1"),
    instructions=[
        "First, search hackernews for what the user is asking about.",
        "Then, ask the web searcher to search for each story to get more information.",
        "Finally, provide a thoughtful and engaging summary.",
    ],
    response_model=Article,
    show_tool_calls=True,
    markdown=True,
    debug_mode=True,
    show_members_responses=True,
)

hn_team.print_response("Write an article about the top 2 stories on hackernews")

参数

参数类型默认描述
table_namestr-要使用的表名。
region_nameOptional[str]NoneDynamoDB 表的区域名称。
aws_access_key_idOptional[str]NoneAWS 访问密钥 ID,如果提供的话。
aws_secret_access_keyOptional[str]NoneAWS 秘密访问密钥,如果提供的话。
endpoint_urlOptional[str]None端点 URL,如果提供的话。
create_table_if_not_existsboolTrue如果为 true,则在表不存在时创建该表。

开发者资源