fix: updated the multi-agent researcher to use teams in Agno

This commit is contained in:
ShubhamSaboo 2025-07-13 20:15:36 -05:00
parent ef2a867b71
commit 7c1341642a
3 changed files with 91 additions and 41 deletions

View file

@ -31,13 +31,17 @@ streamlit run research_agent.py
### How it works? ### 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. - 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: - Once you provide a valid API key, three specialized AI agents are created:
- **story_researcher**: Specializes in researching HackerNews stories. - **HackerNews Researcher**: Specializes in getting top stories from HackerNews using the HackerNews API.
- **user_researcher**: Focuses on researching HackerNews users and reading articles from URLs. - **Web Searcher**: Searches the web for additional information on topics using DuckDuckGo search.
- **hn_assistant**: A team assistant that coordinates the research efforts of the story and user researchers. - **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. - 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 HackerNews Team follows a structured workflow:
- The AI assistants will gather relevant information from HackerNews using the provided tools and generate a comprehensive response using the GPT-4 language model. 1. First searches HackerNews for relevant stories based on your query
- 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. 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.

View file

@ -1,8 +1,14 @@
# Import the required libraries # Import the required libraries
import streamlit as st import streamlit as st
from agno.agent import Agent from agno.agent import Agent
from agno.tools.hackernews import HackerNewsTools
from agno.models.openai import OpenAIChat 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 # Set up the Streamlit app
st.title("Multi-Agent AI Researcher 🔍🤖") 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 # Get OpenAI API key from user
openai_api_key = st.text_input("OpenAI API Key", type="password") openai_api_key = st.text_input("OpenAI API Key", type="password")
os.environ["OPENAI_API_KEY"] = openai_api_key
if openai_api_key: if openai_api_key:
# Create instances of the Assistant hn_researcher = Agent(
story_researcher = Agent( name="HackerNews Researcher",
name="HackerNews Story Researcher", model=OpenAIChat(id="gpt-4o-mini"),
role="Researches hackernews stories and users.", role="Gets top stories from hackernews.",
tools=[HackerNewsTools()], tools=[HackerNewsTools()],
) )
user_researcher = Agent( web_searcher = Agent(
name="HackerNews User Researcher", 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.", role="Reads articles from URLs.",
tools=[HackerNewsTools()], tools=[Newspaper4kTools()],
) )
hn_assistant = Agent( hackernews_team = Team(
name="Hackernews Team", name="HackerNews Team",
team=[story_researcher, user_researcher], mode="coordinate",
model=OpenAIChat( model=OpenAIChat(id="gpt-4o-mini"),
id="gpt-4o", members=[hn_researcher, web_searcher, article_reader],
max_tokens=1024, instructions=[
temperature=0.5, "First, search hackernews for what the user is asking about.",
api_key=openai_api_key "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 # Input field for the report query
@ -41,5 +64,5 @@ if openai_api_key:
if query: if query:
# Get the response from the assistant # Get the response from the assistant
response = hn_assistant.run(query, stream=False) response = hackernews_team.run(query, stream=False)
st.write(response.content) st.write(response.content)

View file

@ -1,32 +1,55 @@
# Import the required libraries # Import the required libraries
import streamlit as st import streamlit as st
from agno.agent import Agent 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 from agno.models.ollama import Ollama
# Set up the Streamlit app # Set up the Streamlit app
st.title("Multi-Agent AI Researcher using Llama-3 🔍🤖") 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.") 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 # Create the specialized agents
story_researcher = Agent( hn_researcher = Agent(
name="HackerNews Story Researcher", name="HackerNews Researcher",
role="Researches hackernews stories and users.", model=Ollama(id="llama3.2", max_tokens=1024),
tools=[HackerNews()], role="Gets top stories from hackernews.",
model=Ollama(id="llama3.2", max_tokens=1024) tools=[HackerNewsTools()],
) )
user_researcher = Agent( web_searcher = Agent(
name="HackerNews User Researcher", 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.", role="Reads articles from URLs.",
tools=[HackerNews()], tools=[Newspaper4kTools()],
model=Ollama(id="llama3.2", max_tokens=1024)
) )
hn_assistant = Agent( hackernews_team = Team(
name="Hackernews Team", name="HackerNews Team",
team=[story_researcher, user_researcher], mode="coordinate",
model=Ollama(id="llama3.2", max_tokens=1024) 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 # Input field for the report query
@ -34,5 +57,5 @@ query = st.text_input("Enter your report query")
if query: if query:
# Get the response from the assistant # Get the response from the assistant
response = hn_assistant.run(query, stream=False) response = hackernews_team.run(query, stream=False)
st.write(response.content) st.write(response.content)