You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
"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:"
95
114
]
96
115
},
97
116
{
98
117
"cell_type": "code",
118
+
"execution_count": null,
99
119
"id": "01689447",
100
120
"metadata": {},
101
121
"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",
"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)",
0 commit comments