fix: updated the multi-agent researcher to use teams in Agno
This commit is contained in:
parent
ef2a867b71
commit
7c1341642a
3 changed files with 91 additions and 41 deletions
|
|
@ -31,13 +31,17 @@ streamlit run research_agent.py
|
|||
### How it works?
|
||||
|
||||
- Upon running the app, you will be prompted to enter your OpenAI API key. This key is used to authenticate and access the OpenAI language models.
|
||||
- Once you provide a valid API key, three instances of the Assistant class are created:
|
||||
- **story_researcher**: Specializes in researching HackerNews stories.
|
||||
- **user_researcher**: Focuses on researching HackerNews users and reading articles from URLs.
|
||||
- **hn_assistant**: A team assistant that coordinates the research efforts of the story and user researchers.
|
||||
- Once you provide a valid API key, three specialized AI agents are created:
|
||||
- **HackerNews Researcher**: Specializes in getting top stories from HackerNews using the HackerNews API.
|
||||
- **Web Searcher**: Searches the web for additional information on topics using DuckDuckGo search.
|
||||
- **Article Reader**: Reads and extracts content from article URLs using newspaper4k tools.
|
||||
|
||||
- These agents work together as a coordinated team under the **HackerNews Team** which orchestrates the research process.
|
||||
- Enter your research query in the provided text input field. This could be a topic, keyword, or specific question related to HackerNews stories or users.
|
||||
- The hn_assistant will orchestrate the research process by delegating tasks to the story_researcher and user_researcher based on your query.
|
||||
- The AI assistants will gather relevant information from HackerNews using the provided tools and generate a comprehensive response using the GPT-4 language model.
|
||||
- The generated content, which could be a blog post, report, or social media post, will be displayed in the app for you to review and use.
|
||||
- The HackerNews Team follows a structured workflow:
|
||||
1. First searches HackerNews for relevant stories based on your query
|
||||
2. Uses the Article Reader to extract detailed content from the story URLs
|
||||
3. Leverages the Web Searcher to gather additional context and information
|
||||
4. Finally provides a thoughtful and engaging summary with title, summary, and reference links
|
||||
- The generated content is structured as an Article with a title, summary, and reference links for easy review and use.
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,14 @@
|
|||
# Import the required libraries
|
||||
import streamlit as st
|
||||
from agno.agent import Agent
|
||||
from agno.tools.hackernews import HackerNewsTools
|
||||
from agno.models.openai import OpenAIChat
|
||||
from agno.team import Team
|
||||
from agno.tools.duckduckgo import DuckDuckGoTools
|
||||
from agno.tools.hackernews import HackerNewsTools
|
||||
from agno.tools.newspaper4k import Newspaper4kTools
|
||||
from pydantic import BaseModel
|
||||
from typing import List
|
||||
import os
|
||||
|
||||
# Set up the Streamlit app
|
||||
st.title("Multi-Agent AI Researcher 🔍🤖")
|
||||
|
|
@ -10,30 +16,47 @@ st.caption("This app allows you to research top stories and users on HackerNews
|
|||
|
||||
# Get OpenAI API key from user
|
||||
openai_api_key = st.text_input("OpenAI API Key", type="password")
|
||||
os.environ["OPENAI_API_KEY"] = openai_api_key
|
||||
|
||||
if openai_api_key:
|
||||
# Create instances of the Assistant
|
||||
story_researcher = Agent(
|
||||
name="HackerNews Story Researcher",
|
||||
role="Researches hackernews stories and users.",
|
||||
hn_researcher = Agent(
|
||||
name="HackerNews Researcher",
|
||||
model=OpenAIChat(id="gpt-4o-mini"),
|
||||
role="Gets top stories from hackernews.",
|
||||
tools=[HackerNewsTools()],
|
||||
)
|
||||
|
||||
user_researcher = Agent(
|
||||
name="HackerNews User Researcher",
|
||||
web_searcher = Agent(
|
||||
name="Web Searcher",
|
||||
model=OpenAIChat(id="gpt-4o-mini"),
|
||||
role="Searches the web for information on a topic",
|
||||
tools=[DuckDuckGoTools()],
|
||||
add_datetime_to_instructions=True,
|
||||
)
|
||||
|
||||
article_reader = Agent(
|
||||
name="Article Reader",
|
||||
model=OpenAIChat(id="gpt-4o-mini"),
|
||||
role="Reads articles from URLs.",
|
||||
tools=[HackerNewsTools()],
|
||||
tools=[Newspaper4kTools()],
|
||||
)
|
||||
|
||||
hn_assistant = Agent(
|
||||
name="Hackernews Team",
|
||||
team=[story_researcher, user_researcher],
|
||||
model=OpenAIChat(
|
||||
id="gpt-4o",
|
||||
max_tokens=1024,
|
||||
temperature=0.5,
|
||||
api_key=openai_api_key
|
||||
)
|
||||
hackernews_team = Team(
|
||||
name="HackerNews Team",
|
||||
mode="coordinate",
|
||||
model=OpenAIChat(id="gpt-4o-mini"),
|
||||
members=[hn_researcher, web_searcher, article_reader],
|
||||
instructions=[
|
||||
"First, search hackernews for what the user is asking about.",
|
||||
"Then, ask the article reader to read the links for the stories to get more information.",
|
||||
"Important: you must provide the article reader with the links to read.",
|
||||
"Then, ask the web searcher to search for each story to get more information.",
|
||||
"Finally, provide a thoughtful and engaging summary.",
|
||||
],
|
||||
show_tool_calls=True,
|
||||
markdown=True,
|
||||
debug_mode=True,
|
||||
show_members_responses=True,
|
||||
)
|
||||
|
||||
# Input field for the report query
|
||||
|
|
@ -41,5 +64,5 @@ if openai_api_key:
|
|||
|
||||
if query:
|
||||
# Get the response from the assistant
|
||||
response = hn_assistant.run(query, stream=False)
|
||||
response = hackernews_team.run(query, stream=False)
|
||||
st.write(response.content)
|
||||
|
|
@ -1,32 +1,55 @@
|
|||
# Import the required libraries
|
||||
import streamlit as st
|
||||
from agno.agent import Agent
|
||||
from agno.tools.hackernews import HackerNews
|
||||
from agno.team import Team
|
||||
from agno.tools.duckduckgo import DuckDuckGoTools
|
||||
from agno.tools.hackernews import HackerNewsTools
|
||||
from agno.tools.newspaper4k import Newspaper4kTools
|
||||
from agno.models.ollama import Ollama
|
||||
|
||||
# Set up the Streamlit app
|
||||
st.title("Multi-Agent AI Researcher using Llama-3 🔍🤖")
|
||||
st.caption("This app allows you to research top stories and users on HackerNews and write blogs, reports and social posts.")
|
||||
|
||||
# Create instances of the Assistant
|
||||
story_researcher = Agent(
|
||||
name="HackerNews Story Researcher",
|
||||
role="Researches hackernews stories and users.",
|
||||
tools=[HackerNews()],
|
||||
model=Ollama(id="llama3.2", max_tokens=1024)
|
||||
# Create the specialized agents
|
||||
hn_researcher = Agent(
|
||||
name="HackerNews Researcher",
|
||||
model=Ollama(id="llama3.2", max_tokens=1024),
|
||||
role="Gets top stories from hackernews.",
|
||||
tools=[HackerNewsTools()],
|
||||
)
|
||||
|
||||
user_researcher = Agent(
|
||||
name="HackerNews User Researcher",
|
||||
web_searcher = Agent(
|
||||
name="Web Searcher",
|
||||
model=Ollama(id="llama3.2", max_tokens=1024),
|
||||
role="Searches the web for information on a topic",
|
||||
tools=[DuckDuckGoTools()],
|
||||
add_datetime_to_instructions=True,
|
||||
)
|
||||
|
||||
article_reader = Agent(
|
||||
name="Article Reader",
|
||||
model=Ollama(id="llama3.2", max_tokens=1024),
|
||||
role="Reads articles from URLs.",
|
||||
tools=[HackerNews()],
|
||||
model=Ollama(id="llama3.2", max_tokens=1024)
|
||||
tools=[Newspaper4kTools()],
|
||||
)
|
||||
|
||||
hn_assistant = Agent(
|
||||
name="Hackernews Team",
|
||||
team=[story_researcher, user_researcher],
|
||||
model=Ollama(id="llama3.2", max_tokens=1024)
|
||||
hackernews_team = Team(
|
||||
name="HackerNews Team",
|
||||
mode="coordinate",
|
||||
model=Ollama(id="llama3.2", max_tokens=1024),
|
||||
members=[hn_researcher, web_searcher, article_reader],
|
||||
instructions=[
|
||||
"First, search hackernews for what the user is asking about.",
|
||||
"Then, ask the article reader to read the links for the stories to get more information.",
|
||||
"Important: you must provide the article reader with the links to read.",
|
||||
"Then, ask the web searcher to search for each story to get more information.",
|
||||
"Finally, provide a thoughtful and engaging summary.",
|
||||
],
|
||||
show_tool_calls=True,
|
||||
markdown=True,
|
||||
debug_mode=True,
|
||||
show_members_responses=True,
|
||||
)
|
||||
|
||||
# Input field for the report query
|
||||
|
|
@ -34,5 +57,5 @@ query = st.text_input("Enter your report query")
|
|||
|
||||
if query:
|
||||
# Get the response from the assistant
|
||||
response = hn_assistant.run(query, stream=False)
|
||||
response = hackernews_team.run(query, stream=False)
|
||||
st.write(response.content)
|
||||
Loading…
Reference in a new issue