Skip to content

Commit eb0eb7e

Browse files
committed
fix: Correct markdown formatting and remove deprecated multi-agent example notebook
1 parent ac323f4 commit eb0eb7e

3 files changed

Lines changed: 79 additions & 279 deletions

File tree

examples/smolagents/multi_smolagents_system.ipynb

Lines changed: 78 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
" | Visit webpage tool |\n",
3535
" +--------------------------------+\n",
3636
"```\n",
37-
"Let\u2019s set up this system.\n",
37+
"Let’s set up this system.\n",
3838
"\n",
3939
"Run the line below to install the required dependencies:"
4040
]
@@ -57,32 +57,51 @@
5757
"id": "00509499",
5858
"metadata": {},
5959
"source": [
60-
"\ud83d\udd87\ufe0f Now we initialize the AgentOps client and load the environment variables to use the API keys."
60+
"🖇️ Now we initialize the AgentOps client and load the environment variables to use the API keys."
6161
]
6262
},
6363
{
6464
"cell_type": "code",
65+
"execution_count": null,
6566
"id": "330770fd",
6667
"metadata": {},
6768
"outputs": [],
68-
"source": "import agentops\nfrom dotenv import load_dotenv\nimport os\nimport re\nimport requests\nfrom markdownify import markdownify\nfrom requests.exceptions import RequestException\nfrom smolagents import tool\nfrom smolagents import LiteLLMModel\nfrom smolagents import (\n CodeAgent,\n ToolCallingAgent,\n ManagedAgent,\n DuckDuckGoSearchTool,\n)\n\nload_dotenv()\nos.environ[\"AGENTOPS_API_KEY\"] = os.getenv(\"AGENTOPS_API_KEY\", \"your_api_key_here\")\nos.environ[\"OPENAI_API_KEY\"] = os.getenv(\"OPENAI_API_KEY\", \"your_openai_api_key_here\")",
69-
"execution_count": null
69+
"source": [
70+
"import agentops\n",
71+
"from dotenv import load_dotenv\n",
72+
"import os\n",
73+
"import re\n",
74+
"import requests\n",
75+
"from markdownify import markdownify\n",
76+
"from requests.exceptions import RequestException\n",
77+
"\n",
78+
"load_dotenv()\n",
79+
"os.environ[\"AGENTOPS_API_KEY\"] = os.getenv(\"AGENTOPS_API_KEY\", \"your_api_key_here\")\n",
80+
"os.environ[\"OPENAI_API_KEY\"] = os.getenv(\"OPENAI_API_KEY\", \"your_openai_api_key_here\")"
81+
]
7082
},
7183
{
7284
"cell_type": "markdown",
7385
"id": "9516d2a7",
7486
"metadata": {},
7587
"source": [
76-
"\u26a1\ufe0f Our agent will be powered by `openai/gpt-4o-mini` using the `LiteLLMModel` class."
88+
"⚡️ Our agent will be powered by `openai/gpt-4o-mini` using the `LiteLLMModel` class."
7789
]
7890
},
7991
{
8092
"cell_type": "code",
93+
"execution_count": null,
8194
"id": "5f78927c",
8295
"metadata": {},
8396
"outputs": [],
84-
"source": "agentops.init(auto_start_session=False)\ntracer = agentops.start_trace(\n trace_name=\"Orchestrate a Multi-Agent System\", tags=[\"smolagents\", \"example\", \"multi-agent\", \"agentops-example\"]\n)\nmodel = LiteLLMModel(\"openai/gpt-4o-mini\")",
85-
"execution_count": null
97+
"source": [
98+
"agentops.init(auto_start_session=False)\n",
99+
"tracer = agentops.start_trace(\n",
100+
" trace_name=\"Orchestrate a Multi-Agent System\", tags=[\"smolagents\", \"example\", \"multi-agent\", \"agentops-example\"]\n",
101+
")\n",
102+
"from smolagents import LiteLLMModel, tool ,CodeAgent, ToolCallingAgent, DuckDuckGoSearchTool\n",
103+
"model = LiteLLMModel(\"openai/gpt-4o-mini\")"
104+
]
86105
},
87106
{
88107
"cell_type": "markdown",
@@ -91,23 +110,51 @@
91110
"source": [
92111
"## Create a Web Search Tool\n",
93112
"\n",
94-
"For web browsing, we can already use our pre-existing `DuckDuckGoSearchTool`. However, we will also create a `VisitWebpageTool` from scratch using `markdownify`. Here\u2019s how:"
113+
"For web browsing, we can already use our pre-existing `DuckDuckGoSearchTool`. However, we will also create a `VisitWebpageTool` from scratch using `markdownify`. Here’s how:"
95114
]
96115
},
97116
{
98117
"cell_type": "code",
118+
"execution_count": null,
99119
"id": "01689447",
100120
"metadata": {},
101121
"outputs": [],
102-
"source": "@tool\ndef visit_webpage(url: str) -> str:\n \"\"\"Visits a webpage at the given URL and returns its content as a markdown string.\n\n Args:\n url: The URL of the webpage to visit.\n\n Returns:\n The content of the webpage converted to Markdown, or an error message if the request fails.\n \"\"\"\n try:\n # Send a GET request to the URL\n response = requests.get(url)\n response.raise_for_status() # Raise an exception for bad status codes\n\n # Convert the HTML content to Markdown\n markdown_content = markdownify(response.text).strip()\n\n # Remove multiple line breaks\n markdown_content = re.sub(r\"\\n{3,}\", \"\\n\\n\", markdown_content)\n\n return markdown_content\n\n except RequestException as e:\n return f\"Error fetching the webpage: {str(e)}\"\n except Exception as e:\n return f\"An unexpected error occurred: {str(e)}\"",
103-
"execution_count": null
122+
"source": [
123+
"@tool\n",
124+
"def visit_webpage(url: str) -> str:\n",
125+
" \"\"\"Visits a webpage at the given URL and returns its content as a markdown string.\n",
126+
"\n",
127+
" Args:\n",
128+
" url: The URL of the webpage to visit.\n",
129+
"\n",
130+
" Returns:\n",
131+
" The content of the webpage converted to Markdown, or an error message if the request fails.\n",
132+
" \"\"\"\n",
133+
" try:\n",
134+
" # Send a GET request to the URL\n",
135+
" response = requests.get(url)\n",
136+
" response.raise_for_status() # Raise an exception for bad status codes\n",
137+
"\n",
138+
" # Convert the HTML content to Markdown\n",
139+
" markdown_content = markdownify(response.text).strip()\n",
140+
"\n",
141+
" # Remove multiple line breaks\n",
142+
" markdown_content = re.sub(r\"\\n{3,}\", \"\\n\\n\", markdown_content)\n",
143+
"\n",
144+
" return markdown_content\n",
145+
"\n",
146+
" except RequestException as e:\n",
147+
" return f\"Error fetching the webpage: {str(e)}\"\n",
148+
" except Exception as e:\n",
149+
" return f\"An unexpected error occurred: {str(e)}\""
150+
]
104151
},
105152
{
106153
"cell_type": "markdown",
107154
"id": "3c45517b",
108155
"metadata": {},
109156
"source": [
110-
"Let\u2019s test our tool:"
157+
"Let’s test our tool:"
111158
]
112159
},
113160
{
@@ -132,18 +179,32 @@
132179
},
133180
{
134181
"cell_type": "code",
182+
"execution_count": null,
135183
"id": "f274b34f",
136184
"metadata": {},
137185
"outputs": [],
138-
"source": "web_agent = ToolCallingAgent(\n tools=[DuckDuckGoSearchTool(), visit_webpage],\n model=model,\n max_iterations=10,\n)\n\nmanaged_web_agent = ManagedAgent(\n agent=web_agent,\n name=\"search\",\n description=\"Runs web searches for you. Give it your query as an argument.\",\n)\n\nmanager_agent = CodeAgent(\n tools=[],\n model=model,\n managed_agents=[managed_web_agent],\n additional_authorized_imports=[\"time\", \"numpy\", \"pandas\"],\n)",
139-
"execution_count": null
186+
"source": [
187+
"web_agent = ToolCallingAgent(\n",
188+
" tools=[DuckDuckGoSearchTool(), visit_webpage],\n",
189+
" model=model,\n",
190+
" name=\"search\",\n",
191+
" description=\"Runs web searches for you. Give it your query as an argument.\",\n",
192+
")\n",
193+
"\n",
194+
"manager_agent = CodeAgent(\n",
195+
" tools=[],\n",
196+
" model=model,\n",
197+
" managed_agents=[web_agent],\n",
198+
" additional_authorized_imports=[\"time\", \"numpy\", \"pandas\"],\n",
199+
")"
200+
]
140201
},
141202
{
142203
"cell_type": "markdown",
143204
"id": "d5977883",
144205
"metadata": {},
145206
"source": [
146-
"Let\u2019s run our system with the following query:"
207+
"Let’s run our system with the following query:"
147208
]
148209
},
149210
{
@@ -189,7 +250,7 @@
189250
],
190251
"metadata": {
191252
"kernelspec": {
192-
"display_name": "test",
253+
"display_name": ".venv",
193254
"language": "python",
194255
"name": "python3"
195256
},
@@ -203,9 +264,9 @@
203264
"name": "python",
204265
"nbconvert_exporter": "python",
205266
"pygments_lexer": "ipython3",
206-
"version": "3.12.8"
267+
"version": "3.11.12"
207268
}
208269
},
209270
"nbformat": 4,
210271
"nbformat_minor": 5
211-
}
272+
}

examples/smolagents/multi_smolagents_system.py

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
from smolagents import (
4141
CodeAgent,
4242
ToolCallingAgent,
43-
ManagedAgent,
4443
DuckDuckGoSearchTool,
4544
)
4645

@@ -96,19 +95,12 @@ def visit_webpage(url: str) -> str:
9695
web_agent = ToolCallingAgent(
9796
tools=[DuckDuckGoSearchTool(), visit_webpage],
9897
model=model,
99-
max_iterations=10,
100-
)
101-
102-
managed_web_agent = ManagedAgent(
103-
agent=web_agent,
104-
name="search",
105-
description="Runs web searches for you. Give it your query as an argument.",
10698
)
10799

108100
manager_agent = CodeAgent(
109101
tools=[],
110102
model=model,
111-
managed_agents=[managed_web_agent],
103+
managed_agents=[web_agent],
112104
additional_authorized_imports=["time", "numpy", "pandas"],
113105
)
114106
# Let’s run our system with the following query:

0 commit comments

Comments
 (0)