"""
运行: `pip install openai duckduckgo-search newspaper4k lxml_html_clean agno redis` 来安装依赖
"""
from typing import List
from agno.agent import Agent
from agno.models.openai import OpenAIChat
from agno.storage.redis import RedisStorage
from agno.team import Team
from agno.tools.duckduckgo import DuckDuckGoTools
from agno.tools.hackernews import HackerNewsTools
from pydantic import BaseModel
# 使用默认的本地连接初始化 Redis 存储
storage = RedisStorage(
# 用于为 session 命名空间的 Redis 键前缀
prefix="agno_test",
# Redis 主机地址
host="localhost",
# Redis 端口号
port=6379,
)
class Article(BaseModel):
title: str
summary: str
reference_links: List[str]
hn_researcher = Agent(
name="HackerNews 研究员",
model=OpenAIChat("gpt-4o"),
role="获取 hackernews 的热门新闻。",
tools=[HackerNewsTools()],
)
web_searcher = Agent(
name="网络搜索员",
model=OpenAIChat("gpt-4o"),
role="搜索网络信息。",
tools=[DuckDuckGoTools()],
add_datetime_to_instructions=True,
)
hn_team = Team(
name="HackerNews 团队",
mode="coordinate",
model=OpenAIChat("gpt-4o"),
members=[hn_researcher, web_searcher],
storage=storage,
instructions=[
"首先,在 hackernews 上搜索用户正在查询的内容。",
"然后,让网络搜索员搜索每个故事以获取更多信息。",
"最后,提供一个有见地且引人入胜的总结。",
],
response_model=Article,
show_tool_calls=True,
markdown=True,
debug_mode=True,
show_members_responses=True,
)
hn_team.print_response("写一篇关于 hackernews 上排名前2的故事的文章")