Skip to content

Commit

Permalink
lose agent definition
Browse files Browse the repository at this point in the history
  • Loading branch information
burtenshaw committed Jan 15, 2025
1 parent 74375b5 commit 34f73f0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 23 deletions.
36 changes: 15 additions & 21 deletions 8_agents/notebooks/agents.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -48,10 +48,7 @@
"from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel\n",
"\n",
"# Initialize the agent\n",
"agent = CodeAgent(\n",
" tools=[DuckDuckGoSearchTool()],\n",
" model=HfApiModel()\n",
")\n",
"agent = CodeAgent(tools=[DuckDuckGoSearchTool()], model=HfApiModel())\n",
"\n",
"# Test the agent\n",
"response = agent.run(\"What's the difference between a list and a tuple in Python?\")\n",
Expand Down Expand Up @@ -87,38 +84,37 @@
"from smolagents import CodeAgent, tool\n",
"from typing import Union\n",
"\n",
"\n",
"@tool\n",
"def calculate(operation: str, numbers: object) -> float:\n",
" \"\"\"Performs basic mathematical operations on a list of numbers.\n",
" \n",
"\n",
" Args:\n",
" operation: One of 'sum', 'average', 'multiply', 'min', 'max'\n",
" numbers: List of numbers to operate on\n",
" \n",
"\n",
" Returns:\n",
" float: Result of the operation\n",
" \"\"\"\n",
" if operation == 'sum':\n",
" if operation == \"sum\":\n",
" return sum(numbers)\n",
" elif operation == 'average':\n",
" elif operation == \"average\":\n",
" return sum(numbers) / len(numbers)\n",
" elif operation == 'multiply':\n",
" elif operation == \"multiply\":\n",
" result = 1\n",
" for n in numbers:\n",
" result *= n\n",
" return result\n",
" elif operation == 'min':\n",
" elif operation == \"min\":\n",
" return min(numbers)\n",
" elif operation == 'max':\n",
" elif operation == \"max\":\n",
" return max(numbers)\n",
" else:\n",
" raise ValueError(f\"Unknown operation: {operation}\")\n",
"\n",
"\n",
"# Create agent with custom tool\n",
"math_agent = CodeAgent(\n",
" tools=[calculate],\n",
" model=HfApiModel()\n",
")\n",
"math_agent = CodeAgent(tools=[calculate], model=HfApiModel())\n",
"\n",
"# Test the agent\n",
"response = math_agent.run(\"What is the average of 10, 15, 20, 25, and 30?\")\n",
Expand Down Expand Up @@ -150,22 +146,20 @@
"metadata": {},
"outputs": [],
"source": [
"from smolagents import Agent\n",
"from smolagents import CodeAgent\n",
"from smolagents.tools import DuckDuckGoSearch\n",
"\n",
"# Initialize the agent with memory\n",
"research_agent = Agent(\n",
" ... # TODO: Define the agent\n",
")\n",
"research_agent = CodeAgent(...) # TODO: Define the agent\n",
"\n",
"# Test with a multi-turn conversation\n",
"questions = [\n",
" \"What are the main types of machine learning?\",\n",
" \"Can you explain supervised learning in more detail?\",\n",
" \"What are some popular algorithms for this type?\"\n",
" \"What are some popular algorithms for this type?\",\n",
"]\n",
"\n",
"# TODO: Test the agent "
"# TODO: Test the agent"
]
},
{
Expand Down
4 changes: 2 additions & 2 deletions 8_agents/retrieval_agents.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ Traditional RAG has key limitations - it only performs a single retrieval step a
Let's start by building a simple agent that can search the web using DuckDuckGo. This agent will be able to answer questions by retrieving relevant information and synthesizing responses.

```python
from smolagents import Agent
from smolagents import CodeAgent
from smolagents.tools import DuckDuckGoSearch

# Initialize the search tool
search_tool = DuckDuckGoSearch()

# Create an agent with memory
agent = Agent(
agent = CodeAgent(
name="research_assistant",
description="I help find and synthesize information from the web",
tools=[search_tool]
Expand Down

0 comments on commit 34f73f0

Please sign in to comment.