https://huggingface.co/docs/smolagents/index
uv pip install smolagents[transformers]
model_id = "meta-llama/Llama-3.2-3B-Instruct"
import os
from smolagents import CodeAgent, HfApiModel
model = HfApiModel(model_id=model_id)
# from smolagents import CodeAgent, TransformersModel
# model = TransformersModel(model_id=model_id)
agent = CodeAgent(tools=[], model=model, add_base_tools=True)
# agent = CodeAgent(tools=[], model=model, add_base_tools=True, use_e2b_executor=True)
agent.run("Could you give me the 5th number in the Fibonacci sequence?")
agent = CodeAgent(tools=[], model=model, additional_authorized_imports=['requests', 'bs4'])
# agent = CodeAgent(tools=[], model=model, additional_authorized_imports=['requests', 'bs4'], use_e2b_executor=True)
agent.run("Could you get me the title of the page at url 'https://huggingface.co/blog'?")
agent.logs
agent.write_memory_to_messages()
from smolagents import DuckDuckGoSearchTool
search_tool = DuckDuckGoSearchTool()
print(search_tool("Who's the current president of Russia?"))
from smolagents import CodeAgent, HfApiModel, DuckDuckGoSearchTool
model = HfApiModel()
web_agent = CodeAgent(
tools=[DuckDuckGoSearchTool(max_results=5)],
model=model,
name="web_search",
description="Runs web searches for you. Give it your query as an argument.",
use_e2b_executor=True,
)
manager_agent = CodeAgent(
tools=[],
model=model,
managed_agents=[web_agent],
additional_authorized_imports=["time", "numpy", "pandas"],
use_e2b_executor=True,
)
manager_agent = CodeAgent(
tools=[], model=model, managed_agents=[managed_web_agent]
)
manager_agent.run("Who is the governor of the State of Maryland?")