Skip to content

Commit

Permalink
Phidata -> Agno (#61)
Browse files Browse the repository at this point in the history
  • Loading branch information
manthanguptaa authored Feb 4, 2025
1 parent eff5226 commit 23bb26d
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 105 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,48 +5,44 @@
"id": "6613d551-2164-4824-a4de-1c4d021b61a9",
"metadata": {},
"source": [
"# MLB Stats Report: Mixture of Agents with Phidata and Groq"
"# MLB Stats Report: Mixture of Agents with Agno and Groq"
]
},
{
"cell_type": "markdown",
"id": "444802de-1d9f-4a5d-873d-2aeca7cea4ca",
"metadata": {},
"source": [
"In this notebook, we will showcase the concept of [Mixture of Agents (MoA)](https://arxiv.org/pdf/2406.04692) using [Phidata Assistants](https://github.com/phidatahq/phidata) and [Groq API](https://console.groq.com/playground). \n",
"In this notebook, we will showcase the concept of [Mixture of Agents (MoA)](https://arxiv.org/pdf/2406.04692) using [Agno Agents](https://github.com/agno-agi/agno) and [Groq API](https://console.groq.com/playground). \n",
"\n",
"The Mixture of Agents approach involves leveraging multiple AI agents, each equipped with different language models, to collaboratively complete a task. By combining the strengths and perspectives of various models, we can achieve a more robust and nuanced result. \n",
"\n",
"In our project, multiple MLB Writer agents, each utilizing a different language model (`llama3-70b-8192`, `llama3-8b-8192`, `gemma2-9b-it`, and `mixtral-8x7b-32768`), will independently generate game recap articles based on game data collected from other Phidata Assistants. These diverse outputs will then be aggregated by an MLB Editor agent, which will synthesize the best elements from each article to create a final, polished game recap. This process not only demonstrates the power of collaborative AI but also highlights the effectiveness of integrating multiple models to enhance the quality of the generated content."
"In our project, multiple MLB Writer agents, each utilizing a different language model (`llama3-70b-8192`, `llama3-8b-8192`, `gemma2-9b-it`, and `mixtral-8x7b-32768`), will independently generate game recap articles based on game data collected from other Agno Agents. These diverse outputs will then be aggregated by an MLB Editor agent, which will synthesize the best elements from each article to create a final, polished game recap. This process not only demonstrates the power of collaborative AI but also highlights the effectiveness of integrating multiple models to enhance the quality of the generated content."
]
},
{
"cell_type": "markdown",
"id": "633760fa",
"metadata": {},
"source": [
"## About Phidata\n",
"## About Agno\n",
"\n",
"Phidata is a framework for building AI Assistants with memory, knowledge and tools. Specifically, Phidata Assistants add memory, knowledge and tools to LLMs.\n",
"Agno is a lightweight framework for building multi-modal Agents.\n",
"\n",
"Join us on our [Discord server](https://discord.com/invite/4MtYHHrgA8) where we are actively building with the community. \n"
]
},
{
"cell_type": "markdown",
"id": "6566e491",
"metadata": {},
"source": [
"## Why Phidata?\n",
"\n",
"**Problem:** We need to turn general-purpose LLMs into specialized assistants for our use-case.\n",
"### Key features\n",
"Here’s why you should build Agents with Agno:\n",
"\n",
"**Solution:** Extend LLMs with memory, knowledge and tools:\n",
"- **Memory:** Stores **chat history** in a database and enables LLMs to have long-term conversations.\n",
"- **Knowledge:** Stores information in a vector database and provides LLMs with **business context**.\n",
"- **Tools:** Enable LLMs to **take actions** like pulling data from an API, sending emails or querying a database.\n",
"- Lightning Fast: Agent creation is 5000x faster than LangGraph (see performance).\n",
"- Model Agnostic: Use any model, any provider, no lock-in.\n",
"- Multi Modal: Native support for text, image, audio and video.\n",
"- Multi Agent: Delegate tasks across a team of specialized agents.\n",
"- Memory Management: Store user sessions and agent state in a database.\n",
"- Knowledge Stores: Use vector databases for Agentic RAG or dynamic few-shot.\n",
"- Structured Outputs: Make Agents respond with structured data.\n",
"- Monitoring: Track agent sessions and performance in real-time on agno.com.\n",
"\n",
"Memory & knowledge make LLMs **smarter** while tools make them **autonomous**."
"Join us on our [Discord server](https://agno.link/discord) where we are actively building with the community. \n"
]
},
{
Expand All @@ -56,7 +52,7 @@
"source": [
"## How it works\n",
"\n",
"- **Step 1:** Create an `Assistant`\n",
"- **Step 1:** Create an `Agent`\n",
"- **Step 2:** Add Tools (functions), Knowledge (vectordb) and Storage (database)\n",
"- **Step 3:** Serve using Streamlit, FastApi or Django to build your AI application"
]
Expand All @@ -71,8 +67,8 @@
},
{
"cell_type": "code",
"execution_count": 16,
"id": "98f4f68d-d596-4f10-a72f-f7027e3f37f4",
"execution_count": 7,
"id": "23f35a12",
"metadata": {},
"outputs": [],
"source": [
Expand All @@ -83,13 +79,14 @@
"import datetime\n",
"from datetime import timedelta, datetime\n",
"import pandas as pd\n",
"from phi.assistant import Assistant\n",
"from phi.llm.groq import Groq"
"\n",
"from agno.agent import Agent\n",
"from agno.models.groq import Groq"
]
},
{
"cell_type": "code",
"execution_count": 17,
"execution_count": 8,
"id": "40534034-a556-424b-8f5b-81392939369e",
"metadata": {},
"outputs": [],
Expand All @@ -102,20 +99,20 @@
"id": "cee9fc13-e27d-4e93-95df-57c87f5a8df4",
"metadata": {},
"source": [
"We will configure multiple LLMs using [Phidata Assistants](https://github.com/phidatahq/phidata), each requiring a Groq API Key for access which you can create [here](https://console.groq.com/keys). These models include different versions of Meta's LLaMA 3 and other specialized models like Google's Gemma 2 and Mixtral. Each model will be used by different agents to generate diverse outputs for the MLB game recap."
"We will configure multiple LLMs using [Agno Agents](https://github.com/agno-agi/agno), each requiring a Groq API Key for access which you can create [here](https://console.groq.com/keys). These models include different versions of Meta's LLaMA 3 and other specialized models like Google's Gemma 2 and Mixtral. Each model will be used by different agents to generate diverse outputs for the MLB game recap."
]
},
{
"cell_type": "code",
"execution_count": 18,
"execution_count": 9,
"id": "1cd20615-fe84-4b35-bb39-2e4d7f388b35",
"metadata": {},
"outputs": [],
"source": [
"llm_llama70b = Groq(model=\"llama3-70b-8192\", api_key=api_key)\n",
"llm_llama8b = Groq(model=\"llama3-groq-8b-8192-tool-use-preview\", api_key=api_key)\n",
"llm_gemma2 = Groq(model=\"gemma2-9b-it\", api_key=api_key)\n",
"llm_mixtral = Groq(model=\"mixtral-8x7b-32768\", api_key=api_key)"
"model_llama70b = Groq(id=\"llama3-70b-8192\", api_key=api_key)\n",
"model_llama8b = Groq(id=\"llama3-groq-8b-8192-tool-use-preview\", api_key=api_key)\n",
"model_gemma2 = Groq(id=\"gemma2-9b-it\", api_key=api_key)\n",
"model_mixtral = Groq(id=\"mixtral-8x7b-32768\", api_key=api_key)"
]
},
{
Expand All @@ -137,12 +134,12 @@
"- **get_batting_stats**: Retrieves detailed player batting statistics for a specified MLB game.\n",
"- **get_pitching_stats**: Retrieves detailed player pitching statistics for a specified MLB game.\n",
"\n",
"For more information on tool use/function calling with Phidata Mixture of Agents, check out [Phidata Documentation](https://docs.phidata.com/introduction)."
"For more information on tool use/function calling with Agno Mixture of Agents, check out [Agno Documentation](https://docs.agno.com/introduction)."
]
},
{
"cell_type": "code",
"execution_count": 19,
"execution_count": 10,
"id": "a1099020-ce9e-41ba-a477-760281d07f4f",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -226,7 +223,7 @@
"id": "2e0e09f2-e772-4c45-b29e-5bf2b9c91efc",
"metadata": {},
"source": [
"In Phidata, Assistants are autonomous entities designed to execute a task using their Knowledge, Memory, and Tools. \n",
"In Agno, Agents are autonomous entities designed to execute a task using their Knowledge, Memory, and Tools. \n",
"\n",
"- **MLB Researcher**: Uses the `get_game_info` tool to gather high-level game information.\n",
"- **MLB Batting and Pitching Statistician**: Retrieves player batting and pitching boxscore stats using the `get_batting_stats` and `get_pitching_stats` tools.\n",
Expand Down Expand Up @@ -260,15 +257,15 @@
},
{
"cell_type": "code",
"execution_count": 20,
"execution_count": 16,
"id": "54a40307-bfc5-4636-aa98-14f49513c611",
"metadata": {},
"outputs": [],
"source": [
"default_date = datetime.now().date() - timedelta(1) # Set default date to yesterday in case no date is specified\n",
"\n",
"mlb_researcher = Assistant(\n",
" llm=llm_mixtral,\n",
"mlb_researcher = Agent(\n",
" model=model_mixtral,\n",
" description=\"An detailed accurate MLB researcher extracts game information from the user question\",\n",
" instructions=[\n",
" f\"Parse the Team and date (use {default_date} if user does not specify) from the user question.\",\n",
Expand All @@ -287,8 +284,8 @@
" tools=[get_game_info], \n",
")\n",
"\n",
"mlb_batting_statistician = Assistant(\n",
" llm=llm_mixtral,\n",
"mlb_batting_statistician = Agent(\n",
" model=model_mixtral,\n",
" description=\"An industrious MLB Statistician analyzing player boxscore stats for the relevant game\",\n",
" instructions=[\n",
" \"Given information about a MLB game, retrieve ONLY boxscore player batting stats for the game identified by the MLB Researcher\",\n",
Expand All @@ -297,8 +294,8 @@
" tools=[get_batting_stats],\n",
")\n",
"\n",
"mlb_pitching_statistician = Assistant(\n",
" llm=llm_mixtral,\n",
"mlb_pitching_statistician = Agent(\n",
" model=model_mixtral,\n",
" description=\"An industrious MLB Statistician analyzing player boxscore stats for the relevant game\",\n",
" instructions=[\n",
" \"Given information about a MLB game, retrieve ONLY boxscore player pitching stats for a specific game\",\n",
Expand All @@ -307,8 +304,8 @@
" tools=[get_pitching_stats],\n",
")\n",
"\n",
"mlb_writer_llama = Assistant(\n",
" llm=llm_llama70b,\n",
"mlb_writer_llama = Agent(\n",
" model=model_llama70b,\n",
" description=\"An experienced, honest, and industrious writer who does not make things up\",\n",
" instructions=[\n",
" \"\"\"\n",
Expand All @@ -322,28 +319,28 @@
" ],\n",
")\n",
"\n",
"mlb_writer_gemma = Assistant(\n",
" llm=llm_gemma2,\n",
"mlb_writer_gemma = Agent(\n",
" model=model_gemma2,\n",
" description=\"An experienced and honest writer who does not make things up\",\n",
" instructions=[\"Write a detailed game recap article using the provided game information and stats\"],\n",
")\n",
"\n",
"mlb_writer_mixtral = Assistant(\n",
" llm=llm_mixtral,\n",
"mlb_writer_mixtral = Agent(\n",
" model=model_mixtral,\n",
" description=\"An experienced and honest writer who does not make things up\",\n",
" instructions=[\"Write a detailed game recap article using the provided game information and stats\"],\n",
")\n",
"\n",
"mlb_editor = Assistant(\n",
" llm=llm_llama70b,\n",
"mlb_editor = Agent(\n",
" model=model_llama70b,\n",
" description=\"An experienced editor that excels at taking the best parts of multiple texts to create the best final product\",\n",
" instructions=[\"Edit recap articles to create the best final product.\"],\n",
")"
]
},
{
"cell_type": "code",
"execution_count": 21,
"execution_count": 12,
"id": "d56d9ff7-e337-40c4-b2c1-e2f69940ce41",
"metadata": {
"scrolled": true
Expand All @@ -355,52 +352,13 @@
},
{
"cell_type": "code",
"execution_count": 22,
"id": "ca32dc45",
"execution_count": null,
"id": "fe2f239d",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Here is the edited recap article:\n",
"\n",
"**Yankees Dominate Orioles in 9-5 Win, Trent Grisham and Ben Rice Shine**\n",
"\n",
"The New York Yankees cruised to a convincing 9-5 victory over the Baltimore Orioles on July 14, 2024, behind stellar performances from Trent Grisham and Ben Rice. The Yankees' offense came alive early, scoring five runs in the first inning, and never looked back.\n",
"\n",
"Ben Rice got the party started with a game-opening home run, his first of the season, driving in three runs. Trent Grisham followed up with multiple hits and RBIs, including an RBI hit in the first inning. Gleyber Torres and Anthony Volpe also contributed to the early scoring surge.\n",
"\n",
"Trent Grisham was the standout performer of the game, going 3-for-5 with two runs scored and two RBIs. His three-hit performance was a season-high, and his contributions helped the Yankees maintain a comfortable lead throughout the game.\n",
"\n",
"Gleyber Torres also had a solid outing, collecting two hits and scoring a run. His 2-hit, 1-run game was a welcome sight for Yankees fans, who have been waiting for the talented second baseman to find his groove.\n",
"\n",
"The Yankees' pitching staff had a mixed bag of performances. Carlos Rodón started the game and lasted four innings, allowing two hits and two runs while striking out seven. Luke Weaver and Jake Cousins followed with scoreless innings, but the bullpen faltered in the later innings. Clay Holmes struggled in the sixth, allowing two hits and three runs, although none were earned.\n",
"\n",
"Despite the pitching struggles, the Yankees' offense and defense did enough to secure the win. The Orioles threatened to mount a comeback in the later innings, but the Yankees held firm, closing out the game with a convincing 9-5 victory.\n",
"\n",
"**Game Stats:**\n",
"\n",
"* Yankees: 9 runs, 7 hits, 2 home runs, 5 RBIs, 5 walks, 0 stolen bases\n",
"* Orioles: 5 runs, 11 hits, 0 home runs, 5 RBIs, 9 walks, 0 stolen bases\n",
"\n",
"**Notable Performances:**\n",
"\n",
"* Trent Grisham: 3 hits, 2 runs, 2 RBIs\n",
"* Ben Rice: 1 home run, 3 RBIs\n",
"* Gleyber Torres: 2 hits, 1 run\n",
"\n",
"**Pitching Line:**\n",
"\n",
"* Carlos Rodón: 4 IP, 2 H, 2 R, 7 K\n",
"* Luke Weaver: 1 IP, 1 H, 0 R, 0 ER, 1 K\n",
"* Jake Cousins: 0.2 IP, 0 H, 0 R, 0 ER, 1 K\n",
"* Clay Holmes: 1 IP, 2 H, 3 R, 0 ER, 1 K, 2 BB\n"
]
}
],
"outputs": [],
"source": [
"game_information = mlb_researcher.run(user_prompt, stream=False)\n",
"print(game_information)\n",
"\n",
"batting_stats = mlb_batting_statistician.run(game_information, stream=False)\n",
"pitching_stats = mlb_pitching_statistician.run(game_information, stream=False)\n",
Expand All @@ -410,7 +368,6 @@
"gemma_writer = mlb_writer_gemma.run(stats, stream=False)\n",
"mixtral_writer = mlb_writer_mixtral.run(stats, stream=False)\n",
"\n",
"\n",
"# Edit final outputs\n",
"editor_inputs = [llama_writer, gemma_writer, mixtral_writer]\n",
"editor = mlb_editor.run(\"\\n\".join(editor_inputs), stream=False)\n",
Expand All @@ -425,22 +382,19 @@
"source": [
"# Conclusion:\n",
"\n",
"Using Phidata Assistants + Groq allows developers to build a cost effective and high quality solution for generating MLB game recaps. The Mixture-of-Agents approach leverages multiple AI agents, each equipped with small and different language models, to complete a task.\n",
"Using Agno Agents + Groq allows developers to build a cost effective and high quality solution for generating MLB game recaps. The Mixture-of-Agents approach leverages multiple AI agents, each equipped with small and different language models, to complete a task.\n",
"\n",
"We use multiple MLB Writer agents utilizing different language models to independently generate game recap articles based on game data collected from other Phidata Assistants. An MLB Editor agent then synthesizes the best elements from each article to create a final, polished game recap.\n",
"We use multiple MLB Writer agents utilizing different language models to independently generate game recap articles based on game data collected from other Agno Agents. An MLB Editor agent then synthesizes the best elements from each article to create a final, polished game recap.\n",
"\n",
"# Connect with us:\n",
"Join the [Phidata Discord](https://discord.com/invite/4MtYHHrgA8) and [Groq Discord](https://discord.com/invite/groq) servers to discuss your ideas and get support from the community.\n",
"Join the [Agno Discord](https://agno.link/discord) and [Groq Discord](https://discord.com/invite/groq) servers to discuss your ideas and get support from the community. If you have questions, feel free to reach out to us at [Discourse](https://agno.link/community)\n",
"\n",
"# Resources:\n",
"Mixture-of-Agents:\n",
"https://arxiv.org/pdf/2406.04692\n",
"\n",
"Phidata:\n",
"https://docs.phidata.com/introduction\n",
"\n",
"Mixture-of-Agents Phidata:\n",
"https://github.com/phidatahq/phidata/cookbook/mixture_of_agents"
"Agno:\n",
"https://docs.agno.com/introduction"
]
}
],
Expand All @@ -460,7 +414,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.9"
"version": "3.9.6"
}
},
"nbformat": 4,
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
phidata
agno
groq
pandas
MLB-StatsAPI

0 comments on commit 23bb26d

Please sign in to comment.