@ -1,56 +1,39 @@
{
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"provenance": [],
"machine_shape": "hm",
"gpuType": "L4"
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
},
"accelerator": "GPU"
},
"cells": [
"cells": [
{
{
"cell_type": "markdown",
"cell_type": "markdown",
"metadata": {
"id": "Qf8eZIT71wba"
},
"source": [
"source": [
"# Entry for SwarmsHackathon 2024\n",
"# Entry for SwarmsHackathon 2024\n",
"\n"
"\n"
],
]
"metadata": {
"id": "Qf8eZIT71wba"
}
},
},
{
{
"cell_type": "markdown",
"cell_type": "markdown",
"source": [
"## Install Swarms"
],
"metadata": {
"metadata": {
"id": "-rBXNMWV4EWN"
"id": "-rBXNMWV4EWN"
}
},
"source": [
"## Install Swarms"
]
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 1,
"execution_count": 1,
"metadata": {
"metadata": {
"id": "w4FoSEyP1q_x",
"colab": {
"colab": {
"base_uri": "https://localhost:8080/",
"base_uri": "https://localhost:8080/",
"height": 1000
"height": 1000
},
},
"id": "w4FoSEyP1q_x",
"outputId": "ea6b15e7-c53c-47aa-86c6-b24d4aff041b"
"outputId": "ea6b15e7-c53c-47aa-86c6-b24d4aff041b"
},
},
"outputs": [
"outputs": [
{
{
"output_type": "stream",
"name": "stdout",
"name": "stdout",
"output_type": "stream",
"text": [
"text": [
"Collecting swarms\n",
"Collecting swarms\n",
" Downloading swarms-5.1.4-py3-none-any.whl (338 kB)\n",
" Downloading swarms-5.1.4-py3-none-any.whl (338 kB)\n",
@ -214,19 +197,19 @@
]
]
},
},
{
{
"output_type": "display_data",
"data": {
"data": {
"application/vnd.colab-display-data+json": {
"application/vnd.colab-display-data+json": {
"id": "43b664ed28b2464da4f7c30cb0f343ce",
"pip_warning": {
"pip_warning": {
"packages": [
"packages": [
"PIL",
"PIL",
"asyncio"
"asyncio"
]
]
},
}
"id": "43b664ed28b2464da4f7c30cb0f343ce"
}
}
},
},
"metadata": {}
"metadata": {},
"output_type": "display_data"
}
}
],
],
"source": [
"source": [
@ -235,60 +218,57 @@
},
},
{
{
"cell_type": "markdown",
"cell_type": "markdown",
"source": [
"Import keys"
],
"metadata": {
"metadata": {
"id": "QTMXxRxw7yR5"
"id": "QTMXxRxw7yR5"
}
},
"source": [
"Import keys"
]
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"source": [
"execution_count": 1,
"from google.colab import userdata\n",
"anthropic_api_key = userdata.get('ANTHROPIC_API_KEY')"
],
"metadata": {
"metadata": {
"id": "lzSnwHw-7z8B"
"id": "lzSnwHw-7z8B"
},
},
"execution_count": 1,
"outputs": [],
"outputs": []
"source": [
"from google.colab import userdata\n",
"anthropic_api_key = userdata.get('ANTHROPIC_API_KEY')"
]
},
},
{
{
"cell_type": "markdown",
"cell_type": "markdown",
"source": [
"## Devin like"
],
"metadata": {
"metadata": {
"id": "eD0PkNm25SVT"
"id": "eD0PkNm25SVT"
}
},
"source": [
"## Devin like"
]
},
},
{
{
"cell_type": "markdown",
"cell_type": "markdown",
"source": [
"This example requires the anthropic library which is not installed by default."
],
"metadata": {
"metadata": {
"id": "0Shm1vrS-YFZ"
"id": "0Shm1vrS-YFZ"
}
},
"source": [
"This example requires the anthropic library which is not installed by default."
]
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"source": [
"execution_count": 2,
"!pip install anthropic"
],
"metadata": {
"metadata": {
"id": "aZG6eSjr-U7J",
"colab": {
"colab": {
"base_uri": "https://localhost:8080/"
"base_uri": "https://localhost:8080/"
},
},
"id": "aZG6eSjr-U7J",
"outputId": "b5460b70-5db9-45d7-d66a-d2eb596b86b7"
"outputId": "b5460b70-5db9-45d7-d66a-d2eb596b86b7"
},
},
"execution_count": 2,
"outputs": [
"outputs": [
{
{
"output_type": "stream",
"name": "stdout",
"name": "stdout",
"output_type": "stream",
"text": [
"text": [
"Collecting anthropic\n",
"Collecting anthropic\n",
" Using cached anthropic-0.28.0-py3-none-any.whl (862 kB)\n",
" Using cached anthropic-0.28.0-py3-none-any.whl (862 kB)\n",
@ -324,23 +304,26 @@
"Successfully installed anthropic-0.28.0 h11-0.14.0 httpcore-1.0.5 httpx-0.27.0 jiter-0.4.1\n"
"Successfully installed anthropic-0.28.0 h11-0.14.0 httpcore-1.0.5 httpx-0.27.0 jiter-0.4.1\n"
]
]
}
}
],
"source": [
"!pip install anthropic"
]
]
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"execution_count": 3,
"execution_count": 3,
"metadata": {
"metadata": {
"id": "NyroG92H1m2G",
"colab": {
"colab": {
"base_uri": "https://localhost:8080/",
"base_uri": "https://localhost:8080/",
"height": 1000
"height": 1000
},
},
"id": "NyroG92H1m2G",
"outputId": "69f4ff8b-39c7-41db-c876-4694336d812e"
"outputId": "69f4ff8b-39c7-41db-c876-4694336d812e"
},
},
"outputs": [
"outputs": [
{
{
"output_type": "stream",
"name": "stderr",
"name": "stderr",
"output_type": "stream",
"text": [
"text": [
"\u001b[32m2024-06-02T20:32:00.407576+0000\u001b[0m \u001b[1mNumber of tools: 4\u001b[0m\n",
"\u001b[32m2024-06-02T20:32:00.407576+0000\u001b[0m \u001b[1mNumber of tools: 4\u001b[0m\n",
"\u001b[32m2024-06-02T20:32:00.407998+0000\u001b[0m \u001b[1mTools provided, Automatically converting to OpenAI function\u001b[0m\n",
"\u001b[32m2024-06-02T20:32:00.407998+0000\u001b[0m \u001b[1mTools provided, Automatically converting to OpenAI function\u001b[0m\n",
@ -351,8 +334,8 @@
]
]
},
},
{
{
"output_type": "stream",
"name": "stdout",
"name": "stdout",
"output_type": "stream",
"text": [
"text": [
"Initializing Autonomous Agent Devin...\n",
"Initializing Autonomous Agent Devin...\n",
"Autonomous Agent Activated.\n",
"Autonomous Agent Activated.\n",
@ -506,9 +489,9 @@
]
]
},
},
{
{
"output_type": "error",
"ename": "KeyboardInterrupt",
"ename": "KeyboardInterrupt",
"evalue": "Interrupted by user",
"evalue": "Interrupted by user",
"output_type": "error",
"traceback": [
"traceback": [
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
"\u001b[0;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)",
"\u001b[0;31mKeyboardInterrupt\u001b[0m Traceback (most recent call last)",
@ -613,7 +596,6 @@
" max_loops=\"auto\",\n",
" max_loops=\"auto\",\n",
" autosave=True,\n",
" autosave=True,\n",
" dashboard=False,\n",
" dashboard=False,\n",
" streaming_on=True,\n",
" verbose=True,\n",
" verbose=True,\n",
" stopping_token=\"<DONE>\",\n",
" stopping_token=\"<DONE>\",\n",
" interactive=True,\n",
" interactive=True,\n",
@ -629,71 +611,7 @@
},
},
{
{
"cell_type": "code",
"cell_type": "code",
"source": [
"execution_count": 7,
"from swarms import Agent, AgentRearrange, rearrange\n",
"from typing import List\n",
"\n",
"llm = Anthropic(\n",
" temperature=0.1,\n",
" anthropic_api_key = anthropic_api_key\n",
")\n",
"# Initialize the director agent\n",
"director = Agent(\n",
" agent_name=\"Director\",\n",
" system_prompt=\"Directs the tasks for the workers\",\n",
" llm=llm,\n",
" max_loops=1,\n",
" dashboard=False,\n",
" streaming_on=True,\n",
" verbose=True,\n",
" stopping_token=\"<DONE>\",\n",
" state_save_file_type=\"json\",\n",
" saved_state_path=\"director.json\",\n",
")\n",
"\n",
"# Initialize worker 1\n",
"worker1 = Agent(\n",
" agent_name=\"Worker1\",\n",
" system_prompt=\"Generates a transcript for a youtube video on what swarms are\",\n",
" llm=llm,\n",
" max_loops=1,\n",
" dashboard=False,\n",
" streaming_on=True,\n",
" verbose=True,\n",
" stopping_token=\"<DONE>\",\n",
" state_save_file_type=\"json\",\n",
" saved_state_path=\"worker1.json\",\n",
")\n",
"\n",
"# Initialize worker 2\n",
"worker2 = Agent(\n",
" agent_name=\"Worker2\",\n",
" system_prompt=\"Summarizes the transcript generated by Worker1\",\n",
" llm=llm,\n",
" max_loops=1,\n",
" dashboard=False,\n",
" streaming_on=True,\n",
" verbose=True,\n",
" stopping_token=\"<DONE>\",\n",
" state_save_file_type=\"json\",\n",
" saved_state_path=\"worker2.json\",\n",
")\n",
"\n",
"# Create a list of agents\n",
"agents = [director, worker1, worker2]\n",
"\n",
"# Define the flow pattern\n",
"flow = \"Director -> Worker1 -> Worker2\"\n",
"\n",
"# Using AgentRearrange class\n",
"agent_system = AgentRearrange(agents=agents, flow=flow)\n",
"output = agent_system.run(\"Create a format to express and communicate swarms of llms in a structured manner for youtube\")\n",
"print(output)\n",
"\n",
"# Using rearrange function\n",
"output = rearrange(agents, flow, \"Create a format to express and communicate swarms of llms in a structured manner for youtube\")\n",
"print(output)"
],
"metadata": {
"metadata": {
"colab": {
"colab": {
"base_uri": "https://localhost:8080/"
"base_uri": "https://localhost:8080/"
@ -701,19 +619,18 @@
"id": "1j3RgVk1ol6G",
"id": "1j3RgVk1ol6G",
"outputId": "a365266e-7c11-4c2d-9e31-19842483b165"
"outputId": "a365266e-7c11-4c2d-9e31-19842483b165"
},
},
"execution_count": 7,
"outputs": [
"outputs": [
{
{
"output_type": "stream",
"name": "stderr",
"name": "stderr",
"output_type": "stream",
"text": [
"text": [
"\u001b[32m2024-06-02T20:34:54.149688+0000\u001b[0m \u001b[1mAgentRearrange initialized with agents: ['Director', 'Worker1', 'Worker2']\u001b[0m\n",
"\u001b[32m2024-06-02T20:34:54.149688+0000\u001b[0m \u001b[1mAgentRearrange initialized with agents: ['Director', 'Worker1', 'Worker2']\u001b[0m\n",
"\u001b[32m2024-06-02T20:34:54.151361+0000\u001b[0m \u001b[1mRunning agents sequentially: ['Director']\u001b[0m\n"
"\u001b[32m2024-06-02T20:34:54.151361+0000\u001b[0m \u001b[1mRunning agents sequentially: ['Director']\u001b[0m\n"
]
]
},
},
{
{
"output_type": "stream",
"name": "stdout",
"name": "stdout",
"output_type": "stream",
"text": [
"text": [
"Flow is valid.\n",
"Flow is valid.\n",
"Initializing Autonomous Agent Director...\n",
"Initializing Autonomous Agent Director...\n",
@ -728,15 +645,15 @@
]
]
},
},
{
{
"output_type": "stream",
"name": "stderr",
"name": "stderr",
"output_type": "stream",
"text": [
"text": [
"\u001b[32m2024-06-02T20:35:02.526464+0000\u001b[0m \u001b[1mRunning agents sequentially: ['Worker1']\u001b[0m\n"
"\u001b[32m2024-06-02T20:35:02.526464+0000\u001b[0m \u001b[1mRunning agents sequentially: ['Worker1']\u001b[0m\n"
]
]
},
},
{
{
"output_type": "stream",
"name": "stdout",
"name": "stdout",
"output_type": "stream",
"text": [
"text": [
"\n",
"\n",
"Llm Swarm Video Format\n",
"Llm Swarm Video Format\n",
@ -771,15 +688,15 @@
]
]
},
},
{
{
"output_type": "stream",
"name": "stderr",
"name": "stderr",
"output_type": "stream",
"text": [
"text": [
"\u001b[32m2024-06-02T20:35:07.814536+0000\u001b[0m \u001b[1mRunning agents sequentially: ['Worker2']\u001b[0m\n"
"\u001b[32m2024-06-02T20:35:07.814536+0000\u001b[0m \u001b[1mRunning agents sequentially: ['Worker2']\u001b[0m\n"
]
]
},
},
{
{
"output_type": "stream",
"name": "stdout",
"name": "stdout",
"output_type": "stream",
"text": [
"text": [
"\n",
"\n",
"[Swarm Name] Llm Swarm\n",
"[Swarm Name] Llm Swarm\n",
@ -810,16 +727,16 @@
]
]
},
},
{
{
"output_type": "stream",
"name": "stderr",
"name": "stderr",
"output_type": "stream",
"text": [
"text": [
"\u001b[32m2024-06-02T20:35:11.887014+0000\u001b[0m \u001b[1mAgentRearrange initialized with agents: ['Director', 'Worker1', 'Worker2']\u001b[0m\n",
"\u001b[32m2024-06-02T20:35:11.887014+0000\u001b[0m \u001b[1mAgentRearrange initialized with agents: ['Director', 'Worker1', 'Worker2']\u001b[0m\n",
"\u001b[32m2024-06-02T20:35:11.889429+0000\u001b[0m \u001b[1mRunning agents sequentially: ['Director']\u001b[0m\n"
"\u001b[32m2024-06-02T20:35:11.889429+0000\u001b[0m \u001b[1mRunning agents sequentially: ['Director']\u001b[0m\n"
]
]
},
},
{
{
"output_type": "stream",
"name": "stdout",
"name": "stdout",
"output_type": "stream",
"text": [
"text": [
"\n",
"\n",
"[Swarm Name] Llm Swarm\n",
"[Swarm Name] Llm Swarm\n",
@ -868,15 +785,15 @@
]
]
},
},
{
{
"output_type": "stream",
"name": "stderr",
"name": "stderr",
"output_type": "stream",
"text": [
"text": [
"\u001b[32m2024-06-02T20:35:18.085897+0000\u001b[0m \u001b[1mRunning agents sequentially: ['Worker1']\u001b[0m\n"
"\u001b[32m2024-06-02T20:35:18.085897+0000\u001b[0m \u001b[1mRunning agents sequentially: ['Worker1']\u001b[0m\n"
]
]
},
},
{
{
"output_type": "stream",
"name": "stdout",
"name": "stdout",
"output_type": "stream",
"text": [
"text": [
"\n",
"\n",
"Llm Swarm Video Format\n",
"Llm Swarm Video Format\n",
@ -912,15 +829,15 @@
]
]
},
},
{
{
"output_type": "stream",
"name": "stderr",
"name": "stderr",
"output_type": "stream",
"text": [
"text": [
"\u001b[32m2024-06-02T20:35:23.508710+0000\u001b[0m \u001b[1mRunning agents sequentially: ['Worker2']\u001b[0m\n"
"\u001b[32m2024-06-02T20:35:23.508710+0000\u001b[0m \u001b[1mRunning agents sequentially: ['Worker2']\u001b[0m\n"
]
]
},
},
{
{
"output_type": "stream",
"name": "stdout",
"name": "stdout",
"output_type": "stream",
"text": [
"text": [
"\n",
"\n",
"[Swarm Name] Llm Swarm\n",
"[Swarm Name] Llm Swarm\n",
@ -993,7 +910,86 @@
"I think focusing on presenting uplifting dialogue between AI systems is a thoughtful idea. This script outlines a respectful approach. Please let me know if you would like me to modify or expand on anything! I'm happy to help further.\n"
"I think focusing on presenting uplifting dialogue between AI systems is a thoughtful idea. This script outlines a respectful approach. Please let me know if you would like me to modify or expand on anything! I'm happy to help further.\n"
]
]
}
}
],
"source": [
"from swarms import Agent, AgentRearrange, rearrange\n",
"from typing import List\n",
"\n",
"llm = Anthropic(\n",
" temperature=0.1,\n",
" anthropic_api_key = anthropic_api_key\n",
")\n",
"# Initialize the director agent\n",
"director = Agent(\n",
" agent_name=\"Director\",\n",
" system_prompt=\"Directs the tasks for the workers\",\n",
" llm=llm,\n",
" max_loops=1,\n",
" dashboard=False,\n",
" verbose=True,\n",
" stopping_token=\"<DONE>\",\n",
" state_save_file_type=\"json\",\n",
" saved_state_path=\"director.json\",\n",
")\n",
"\n",
"# Initialize worker 1\n",
"worker1 = Agent(\n",
" agent_name=\"Worker1\",\n",
" system_prompt=\"Generates a transcript for a youtube video on what swarms are\",\n",
" llm=llm,\n",
" max_loops=1,\n",
" dashboard=False,\n",
" verbose=True,\n",
" stopping_token=\"<DONE>\",\n",
" state_save_file_type=\"json\",\n",
" saved_state_path=\"worker1.json\",\n",
")\n",
"\n",
"# Initialize worker 2\n",
"worker2 = Agent(\n",
" agent_name=\"Worker2\",\n",
" system_prompt=\"Summarizes the transcript generated by Worker1\",\n",
" llm=llm,\n",
" max_loops=1,\n",
" dashboard=False,\n",
" verbose=True,\n",
" stopping_token=\"<DONE>\",\n",
" state_save_file_type=\"json\",\n",
" saved_state_path=\"worker2.json\",\n",
")\n",
"\n",
"# Create a list of agents\n",
"agents = [director, worker1, worker2]\n",
"\n",
"# Define the flow pattern\n",
"flow = \"Director -> Worker1 -> Worker2\"\n",
"\n",
"# Using AgentRearrange class\n",
"agent_system = AgentRearrange(agents=agents, flow=flow)\n",
"output = agent_system.run(\"Create a format to express and communicate swarms of llms in a structured manner for youtube\")\n",
"print(output)\n",
"\n",
"# Using rearrange function\n",
"output = rearrange(agents, flow, \"Create a format to express and communicate swarms of llms in a structured manner for youtube\")\n",
"print(output)"
]
]
}
}
]
],
"metadata": {
"accelerator": "GPU",
"colab": {
"gpuType": "L4",
"machine_shape": "hm",
"provenance": []
},
"kernelspec": {
"display_name": "Python 3",
"name": "python3"
},
"language_info": {
"name": "python"
}
},
"nbformat": 4,
"nbformat_minor": 0
}
}