"""
运行:`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 的故事的文章")