Quickstart
Build a code agent that can search the web and do math, in six lines:
from smolagents import CodeAgent, WebSearchTool, InferenceClientModel
model = InferenceClientModel() # a hosted LLM
agent = CodeAgent(tools=[WebSearchTool()], model=model)
agent.run(
"How many seconds would it take for a leopard at full speed "
"to run through Pont des Arts?"
)
The agent will search for the leopard's top speed and the bridge's length, then write Python to compute the answer — all on its own.
Inspect the run
Pass stream=True to watch each step, or read agent.logs afterwards to see every thought, code block, and observation. The agent also prints a colored trace to the console by default.
Add more tools
from smolagents import CodeAgent, WebSearchTool, PythonInterpreterTool
agent = CodeAgent(
tools=[WebSearchTool(), PythonInterpreterTool()],
model=model,
additional_authorized_imports=["numpy", "pandas"],
)