Skip to content

Commit

Permalink
Fix multiagent web assistant notebook
Browse files Browse the repository at this point in the history
  • Loading branch information
aymeric-roucher committed Jan 6, 2025
1 parent 0dc2ba1 commit 7a81cb9
Showing 1 changed file with 14 additions and 19 deletions.
33 changes: 14 additions & 19 deletions notebooks/en/multiagent_web_assistant.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,6 @@
"```\n",
"Let's set up this system. \n",
"\n",
<<<<<<< Updated upstream
=======
"⚡️ Our agent will be powered by [meta-llama/Meta-Llama-3.1-70B-Instruct](https://huggingface.co/meta-llama/Meta-Llama-3.1-70B-Instruct) using `HfApiModel` class that uses HF's Inference API: the Inference API allows to quickly and easily run any OS model.\n",
"\n",
>>>>>>> Stashed changes
"Run the line below to install the required dependencies:"
]
},
Expand All @@ -46,7 +41,7 @@
"metadata": {},
"outputs": [],
"source": [
"!pip install markdownify duckduckgo-search smolagents --upgrade -q"
"!pip install markdownify duckduckgo-search \"transformers[agents]\" --upgrade -q"
]
},
{
Expand Down Expand Up @@ -109,7 +104,7 @@
"import requests\n",
"from markdownify import markdownify as md\n",
"from requests.exceptions import RequestException\n",
"from smolagents import tool\n",
"from transformers.agents import tool\n",
"\n",
"\n",
"@tool\n",
Expand Down Expand Up @@ -192,7 +187,7 @@
"Now that we have all the tools `search` and `visit_webpage`, we can use them to create the web agent.\n",
"\n",
"Which configuration to choose for this agent?\n",
"- Web browsing is a single-timeline task that does not require parallel tool calls, so JSON tool calling works well for that. We thus choose a `ToolCallingAgent`.\n",
"- Web browsing is a single-timeline task that does not require parallel tool calls, so JSON tool calling works well for that. We thus choose a `ReactJsonAgent`.\n",
"- Also, since sometimes web search requires exploring many pages before finding the correct answer, we prefer to increase the number of `max_iterations` to 10."
]
},
Expand All @@ -202,19 +197,19 @@
"metadata": {},
"outputs": [],
"source": [
"from smolagents import (\n",
" CodeAgent,\n",
" ToolCallingAgent,\n",
" HfApiModel,\n",
"from transformers.agents import (\n",
" ReactCodeAgent,\n",
" ReactJsonAgent,\n",
" HfApiEngine,\n",
" ManagedAgent,\n",
")\n",
"from smolagents.search import DuckDuckGoSearchTool\n",
"from transformers.agents.search import DuckDuckGoSearchTool\n",
"\n",
"model = HfApiModel(model)\n",
"llm_engine = HfApiEngine(model)\n",
"\n",
"web_agent = ToolCallingAgent(\n",
"web_agent = ReactJsonAgent(\n",
" tools=[DuckDuckGoSearchTool(), visit_webpage],\n",
" model=model,\n",
" llm_engine=llm_engine,\n",
" max_iterations=10,\n",
")"
]
Expand Down Expand Up @@ -245,7 +240,7 @@
"source": [
"Finally we create a manager agent, and upon initialization we pass our managed agent to it in its `managed_agents` argument.\n",
"\n",
"Since this agent is the one tasked with the planning and thinking, advanced reasoning will be beneficial, so a `CodeAgent` will be the best choice.\n",
"Since this agent is the one tasked with the planning and thinking, advanced reasoning will be beneficial, so a `ReactCodeAgent` will be the best choice.\n",
"\n",
"Also, we want to ask a question that involves the current year: so let us add `additional_authorized_imports=[\"time\", \"datetime\"]`"
]
Expand All @@ -256,9 +251,9 @@
"metadata": {},
"outputs": [],
"source": [
"manager_agent = CodeAgent(\n",
"manager_agent = ReactCodeAgent(\n",
" tools=[],\n",
" model=model,\n",
" llm_engine=llm_engine,\n",
" managed_agents=[managed_web_agent],\n",
" additional_authorized_imports=[\"time\", \"datetime\"],\n",
")"
Expand Down

0 comments on commit 7a81cb9

Please sign in to comment.