Skip to content

Python SDK for AI agent monitoring, LLM cost tracking, benchmarking, and more. Integrates with most LLMs and agent frameworks including CrewAI, Agno, OpenAI Agents SDK, Langchain, Autogen, AG2, and CamelAI

doc: swarmzero integration (#604)

Tomisin Jenrolaa26f0dea1c81
diff --git a/README.md b/README.md
index 61269a4c..3d7dcdac 100644
--- a/README.md
+++ b/README.md
@@ -679,6 +679,36 @@ AgentOps provides support for Llama Stack Python Client(>=0.0.53), allowing you
- [AgentOps integration example 2](https://github.com/AgentOps-AI/agentops/pull/530/files/65a5ab4fdcf310326f191d4b870d4f553591e3ea#diff-6688ff4fb7ab1ce7b1cc9b8362ca27264a3060c16737fb1d850305787a6e3699)
- [Official Llama Stack Python Client](https://github.com/meta-llama/llama-stack-client-python)
+### SwarmZero AI 🐝
+
+Track and analyze SwarmZero agents with full observability. Set an `AGENTOPS_API_KEY` in your environment and initialize AgentOps to get started.
+
+- [SwarmZero](https://swarmzero.ai) - Advanced multi-agent framework
+- [AgentOps integration example](https://docs.agentops.ai/v1/integrations/swarmzero)
+- [SwarmZero AI integration example](https://docs.swarmzero.ai/examples/ai-agents/build-and-monitor-a-web-search-agent)
+- [SwarmZero AI - AgentOps documentation](https://docs.swarmzero.ai/sdk/observability/agentops)
+- [Official SwarmZero Python SDK](https://github.com/swarmzero/swarmzero)
+
+<details>
+ <summary>Installation</summary>
+
+```bash
+pip install swarmzero
+pip install agentops
+```
+
+```python
+from dotenv import load_dotenv
+load_dotenv()
+
+import agentops
+agentops.init(<INSERT YOUR API KEY HERE>)
+
+from swarmzero import Agent, Swarm
+# ...
+```
+</details>
+
## Time travel debugging 🔮
<div style="justify-content: center">
@@ -746,6 +776,7 @@ Check out our growth in the community:
|<img class="avatar mr-2" src="https://avatars.githubusercontent.com/u/162546372?s=40&v=4" width="20" height="20" alt=""> &nbsp; [BasedHardware](https://github.com/BasedHardware) / [Omi](https://github.com/BasedHardware/Omi) | 2723 |
|<img class="avatar mr-2" src="https://avatars.githubusercontent.com/u/454862?s=40&v=4" width="20" height="20" alt=""> &nbsp; [MervinPraison](https://github.com/MervinPraison) / [PraisonAI](https://github.com/MervinPraison/PraisonAI) | 2007 |
|<img class="avatar mr-2" src="https://avatars.githubusercontent.com/u/140554352?s=40&v=4" width="20" height="20" alt=""> &nbsp; [AgentOps-AI](https://github.com/AgentOps-AI) / [Jaiqu](https://github.com/AgentOps-AI/Jaiqu) | 272 |
+|<img class="avatar mr-2" src="https://avatars.githubusercontent.com/u/173542722?s=48&v=4" width="20" height="20" alt=""> &nbsp; [swarmzero](https://github.com/swarmzero) / [swarmzero](https://github.com/swarmzero/swarmzero) | 195 |
|<img class="avatar mr-2" src="https://avatars.githubusercontent.com/u/3074263?s=40&v=4" width="20" height="20" alt=""> &nbsp; [strnad](https://github.com/strnad) / [CrewAI-Studio](https://github.com/strnad/CrewAI-Studio) | 134 |
|<img class="avatar mr-2" src="https://avatars.githubusercontent.com/u/18406448?s=40&v=4" width="20" height="20" alt=""> &nbsp; [alejandro-ao](https://github.com/alejandro-ao) / [exa-crewai](https://github.com/alejandro-ao/exa-crewai) | 55 |
|<img class="avatar mr-2" src="https://avatars.githubusercontent.com/u/64493665?s=40&v=4" width="20" height="20" alt=""> &nbsp; [tonykipkemboi](https://github.com/tonykipkemboi) / [youtube_yapper_trapper](https://github.com/tonykipkemboi/youtube_yapper_trapper) | 47 |
diff --git a/docs/images/external/swarmzero/swarmzero_logo.png b/docs/images/external/swarmzero/swarmzero_logo.png
new file mode 100644
index 00000000..2921b9d9
Binary files /dev/null and b/docs/images/external/swarmzero/swarmzero_logo.png differ
diff --git a/docs/images/external/swarmzero/swarmzero_session.png b/docs/images/external/swarmzero/swarmzero_session.png
new file mode 100644
index 00000000..ed04f95e
Binary files /dev/null and b/docs/images/external/swarmzero/swarmzero_session.png differ
diff --git a/docs/mint.json b/docs/mint.json
index e53011f1..88959ae5 100644
--- a/docs/mint.json
+++ b/docs/mint.json
@@ -102,6 +102,7 @@
"v1/integrations/ollama",
"v1/integrations/openai",
"v1/integrations/rest",
+ "v1/integrations/swarmzero",
"v1/integrations/taskweaver",
"v1/integrations/xai"
]
diff --git a/docs/v1/examples/examples.mdx b/docs/v1/examples/examples.mdx
index 7dbea88f..5a699642 100644
--- a/docs/v1/examples/examples.mdx
+++ b/docs/v1/examples/examples.mdx
@@ -85,6 +85,10 @@ mode: "wide"
Create a REST server that performs and observes agent tasks
</Card>
+ <Card title="SwarmZero" icon={<img src="https://www.github.com/agentops-ai/agentops/blob/main/docs/images/external/swarmzero/swarmzero_logo.png?raw=true" alt="SwarmZero" />} iconType="image" href="/v1/integrations/swarmzero">
+ SwarmZero multi-agent framework for AI Agents and AI Swarms with AgentOps support
+ </Card>
+
<Card title="TaskWeaver" icon={<img src="https://www.github.com/agentops-ai/agentops/blob/main/docs/images/external/microsoft/microsoft_logo.svg?raw=true" alt="TaskWeaver" />} iconType="image" href="/v1/integrations/taskweaver">
First class support for Microsoft TaskWeaver
</Card>
diff --git a/docs/v1/integrations/swarmzero.mdx b/docs/v1/integrations/swarmzero.mdx
new file mode 100644
index 00000000..5c85e18b
--- /dev/null
+++ b/docs/v1/integrations/swarmzero.mdx
@@ -0,0 +1,165 @@
+---
+title: SwarmZero
+description: "Build powerful web search agents with SwarmZero and AgentOps monitoring"
+---
+
+import CodeTooltip from '/snippets/add-code-tooltip.mdx'
+import EnvTooltip from '/snippets/add-env-tooltip.mdx'
+
+AgentOps has first party support for [SwarmZero](https://swarmzero.ai) via its Python SDK. Explore development with SwarmZero by visiting their [docs](https://docs.swarmzero.ai).
+
+## Steps to integrate SwarmZero with AgentOps
+
+<Steps>
+ <Step title="Install SwarmZero">
+ <CodeGroup>
+ ```bash pip
+ pip install swarmzero
+ ```
+ ```bash poetry
+ poetry add swarmzero
+ ```
+ </CodeGroup>
+ </Step>
+ <Step title="Install the AgentOps SDK">
+ <CodeGroup>
+ ```bash pip
+ pip install agentops
+ ```
+ ```bash poetry
+ poetry add agentops
+ ```
+ </CodeGroup>
+ </Step>
+ <Step title="Install additional dependencies">
+ <CodeGroup>
+ ```bash pip
+ pip install python-dotenv tavily-python
+ ```
+ ```bash poetry
+ poetry add python-dotenv tavily-python
+ ```
+ </CodeGroup>
+ </Step>
+ <Step title="Add AgentOps to your code">
+ <CodeTooltip/>
+ <CodeGroup>
+ ```python python
+ import os
+ import agentops
+ from dotenv import load_dotenv
+ from swarmzero import Agent
+ from tavily import TavilyClient
+
+ # Load environment variables
+ load_dotenv()
+
+ # Initialize clients
+ agentops.init(os.getenv("AGENTOPS_API_KEY"))
+ tavily_client = TavilyClient(api_key=os.getenv("TAVILY_API_KEY"))
+
+ # Your SwarmZero agent code here...
+ ```
+ </CodeGroup>
+ <EnvTooltip />
+ <CodeGroup>
+ ```python .env
+ AGENTOPS_API_KEY=<YOUR API KEY>
+ TAVILY_API_KEY=<YOUR API KEY>
+ OPENAI_API_KEY=<YOUR API KEY>
+ ```
+ </CodeGroup>
+ Read more about environment variables in [Advanced Configuration](/v1/usage/advanced-configuration)
+ </Step>
+ <Step title="Run your Agent">
+ Execute your program and visit [app.agentops.ai/drilldown](https://app.agentops.ai/drilldown) to observe your Agent! 🕵️
+ <Tip>
+ After your run, AgentOps prints a clickable url to console linking directly to your session in the Dashboard
+ </Tip>
+ <Frame type="glass" caption="Clickable link to session">
+ <img height="200" src="https://github.com/AgentOps-AI/agentops/blob/main/docs/images/external/swarmzero/swarmzero_session.png?raw=true" />
+ </Frame>
+ </Step>
+</Steps>
+
+## Full Example
+
+<CodeGroup>
+ ```python web_search_agent.py
+ import os
+ import agentops
+ from dotenv import load_dotenv
+ from swarmzero import Agent
+ from tavily import TavilyClient
+
+ load_dotenv()
+ agentops.init(os.getenv("AGENTOPS_API_KEY"))
+ tavily_client = TavilyClient(api_key=os.getenv("TAVILY_API_KEY"))
+
+ async def web_search(query: str) -> dict:
+ response = tavily_client.search(query)
+ results = []
+ for result in response["results"][:3]:
+ results.append({"title": result["title"], "url": result["url"], "content": result["content"]})
+ return results
+
+ async def extract_from_urls(urls: list[str]) -> dict:
+ response = tavily_client.extract(urls=urls)
+
+ if response["failed_results"]:
+ print(f"Failed to extract from {response['failed_results']}")
+
+ results = []
+ for result in response["results"]:
+ results.append({"url": result["url"], "raw_content": result["raw_content"]})
+
+ return results
+
+ my_agent = Agent(
+ name="workflow-assistant",
+ functions=[
+ web_search,
+ extract_from_urls,
+ ],
+ config_path="./swarmzero_config.toml", # see https://github.com/swarmzero/swarmzero/blob/main/swarmzero_config_example.toml
+ instruction="You are a helpful assistant that can search the web and extract information from a given URL.",
+ # chat_only_mode=True # remove comment only if using `my_agent.chat()`
+ )
+
+ my_agent.run() # see agent API at localhost:8000/docs
+
+ """
+ # chat directly without starting the agent's server
+ import asyncio
+
+ response = asyncio.run(my_agent.chat(prompt="what is Decentralized-AI about about?"))
+ print(response)
+ """
+
+ ```
+</CodeGroup>
+
+### Using the Agent
+
+Once your agent is running, you can interact with it using HTTP requests:
+
+<CodeGroup>
+ ```bash curl
+ curl -X 'POST' \
+ 'http://localhost:8000/api/v1/chat' \
+ -H 'accept: application/json' \
+ -H 'Content-Type: multipart/form-data' \
+ -F 'user_id=test_user' \
+ -F 'session_id=test_web_search_agent' \
+ -F 'chat_data={"messages":[{"role":"user","content":"what is Decentralized-AI about about?"}]}'
+ ```
+</CodeGroup>
+
+This example can be found in this [notebook](https://github.com/AgentOps-AI/agentops/blob/main/examples/swarmzero_examples/web_search_agent.ipynb)
+This full code for this example can be found in this [repository](https://github.com/swarmzero/examples/tree/main/agents/web_search_agent).
+
+<script type="module" src="/scripts/github_stars.js"></script>
+<script type="module" src="/scripts/scroll-img-fadein-animation.js"></script>
+<script type="module" src="/scripts/button_heartbeat_animation.js"></script>
+<script type="css" src="/styles/styles.css"></script>
+<script type="module" src="/scripts/adjust_api_dynamically.js"></script>
diff --git a/examples/swarmzero_examples/README.md b/examples/swarmzero_examples/README.md
new file mode 100644
index 00000000..0210b8ba
--- /dev/null
+++ b/examples/swarmzero_examples/README.md
@@ -0,0 +1,71 @@
+# Web Search Agent
+
+A powerful web search agent built using SwarmZero framework that enables intelligent web searching capabilities.
+
+## Description
+
+This agent utilizes the Tavily API for performing web searches and is built on top of the SwarmZero framework, providing enhanced search capabilities with AI-powered processing.
+
+## Prerequisites
+
+- Python 3.11 or higher
+- Poetry package manager
+- Tavily API key
+- AgentOps API key
+
+## Installation
+
+1. Clone the repository:
+```bash
+git clone https://github.com/swarmzero/examples.git
+cd examples/agents/web_search_agent
+```
+
+2. Install dependencies using Poetry:
+```bash
+poetry install --no-root
+```
+
+3. Set up environment variables:
+Create a `.env` file in the root directory and add your API keys:
+```
+TAVILY_API_KEY=your_tavily_api_key_here
+AGENTOPS_API_KEY=your_agentops_api_key_here
+OPENAI_API_KEY=your_openai_api_key_here
+```
+
+## Usage
+
+1. Activate the Poetry shell:
+```bash
+poetry shell
+```
+
+2. Run the agent:
+```bash
+poetry run python main.py
+```
+
+3. Send a message to the agent:
+```bash
+curl -X 'POST' \
+ 'http://localhost:8000/api/v1/chat' \
+ -H 'accept: application/json' \
+ -H 'Content-Type: multipart/form-data' \
+ -F 'user_id=test_user' \
+ -F 'session_id=test_web_search_agent' \
+ -F 'chat_data={"messages":[{"role":"user","content":"what is swarmzero.ai about?"}]}'
+```
+
+4. AgentOps will automatically capture the session:
+- View the _agentops.log_ file
+- See the [AgentOps Dashboard](https://app.agentops.ai/drilldown)
+
+## Dependencies
+
+- `swarmzero`: Framework for multi-agent development
+- `agentops`: Agent observability and monitoring
+- `tavily-python`: Web search API client
+
+## Learn more
+Visit [SwarmZero](https://swarmzero.ai) to learn more about the SwarmZero framework.
diff --git a/examples/swarmzero_examples/swarmzero_config.toml b/examples/swarmzero_examples/swarmzero_config.toml
new file mode 100644
index 00000000..e16851c4
--- /dev/null
+++ b/examples/swarmzero_examples/swarmzero_config.toml
@@ -0,0 +1,11 @@
+[model]
+model = "gpt-4o"
+
+[environment]
+type = "dev"
+
+[timeout]
+llm = 30
+
+[sample_prompts]
+prompts = []
diff --git a/examples/swarmzero_examples/web_search_agent.ipynb b/examples/swarmzero_examples/web_search_agent.ipynb
new file mode 100644
index 00000000..893534cc
--- /dev/null
+++ b/examples/swarmzero_examples/web_search_agent.ipynb
@@ -0,0 +1,176 @@
+{
+ "cells": [
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "# Web Search Agent\n",
+ "This notebook demonstrates a web search agent using SwarmZero framework and Tavily API."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "import os\n",
+ "\n",
+ "import agentops\n",
+ "from dotenv import load_dotenv\n",
+ "from swarmzero import Agent\n",
+ "from tavily import TavilyClient\n",
+ "\n",
+ "load_dotenv()\n",
+ "agentops.init(os.getenv(\"AGENTOPS_API_KEY\"))\n",
+ "tavily_client = TavilyClient(api_key=os.getenv(\"TAVILY_API_KEY\"))"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Define Search Functions"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "async def web_search(query: str) -> dict:\n",
+ " response = tavily_client.search(query)\n",
+ " results = []\n",
+ " for result in response[\"results\"][:3]:\n",
+ " results.append({\"title\": result[\"title\"], \"url\": result[\"url\"], \"content\": result[\"content\"]})\n",
+ " return results\n",
+ "\n",
+ "\n",
+ "async def extract_from_urls(urls: list[str]) -> dict:\n",
+ " response = tavily_client.extract(urls=urls)\n",
+ "\n",
+ " if response[\"failed_results\"]:\n",
+ " print(f\"Failed to extract from {response['failed_results']}\")\n",
+ "\n",
+ " results = []\n",
+ " for result in response[\"results\"]:\n",
+ " results.append({\"url\": result[\"url\"], \"raw_content\": result[\"raw_content\"]})\n",
+ "\n",
+ " return results"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "## Initialize and Run Agent"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "my_agent = Agent(\n",
+ " name=\"workflow-assistant\",\n",
+ " functions=[\n",
+ " web_search,\n",
+ " extract_from_urls,\n",
+ " ],\n",
+ " config_path=\"./swarmzero_config.toml\", # see https://github.com/swarmzero/swarmzero/blob/main/swarmzero_config_example.toml\n",
+ " instruction=\"You are a helpful assistant that can search the web and extract information from a given URL.\",\n",
+ " # chat_only_mode=True # remove comment only if using `my_agent.chat()`\n",
+ ")"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "### Option 1: Chat directly without starting the agent's server"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "import asyncio"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "response = asyncio.run(my_agent.chat(prompt=\"what is Decentralized-AI about about?\"))"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "print(response)"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "### Option 2: Run agent server"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {},
+ "outputs": [],
+ "source": [
+ "# my_agent.run() # see agent API at localhost:8000/docs"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "Send a message to the agent:\n",
+ "```bash\n",
+ "curl -X 'POST' \\\n",
+ " 'http://localhost:8000/api/v1/chat' \\\n",
+ " -H 'accept: application/json' \\\n",
+ " -H 'Content-Type: multipart/form-data' \\\n",
+ " -F 'user_id=test_user' \\\n",
+ " -F 'session_id=test_web_search_agent' \\\n",
+ " -F 'chat_data={\"messages\":[{\"role\":\"user\",\"content\":\"what is swarmzero.ai about?\"}]}'\n",
+ "```"
+ ]
+ }
+ ],
+ "metadata": {
+ "kernelspec": {
+ "display_name": "Python 3",
+ "language": "python",
+ "name": "python3"
+ },
+ "language_info": {
+ "codemirror_mode": {
+ "name": "ipython",
+ "version": 3
+ },
+ "file_extension": ".py",
+ "mimetype": "text/x-python",
+ "name": "python",
+ "nbconvert_exporter": "python",
+ "pygments_lexer": "ipython3",
+ "version": "3.11"
+ }
+ },
+ "nbformat": 4,
+ "nbformat_minor": 4
+}