We're sunsetting PodQuest on 2025-07-28. Thank you for your support!
Export Podcast Subscriptions
cover of episode 876: Hugging Face’s smolagents: Agentic AI in Python Made Easy

876: Hugging Face’s smolagents: Agentic AI in Python Made Easy

2025/4/4
logo of podcast Super Data Science: ML & AI Podcast with Jon Krohn

Super Data Science: ML & AI Podcast with Jon Krohn

AI Deep Dive AI Chapters Transcript
People
J
John Krohn
Topics
我今天介绍了 Hugging Face 新推出的 Small Agents 库,它是一个用于创建 AI 智能体的 Python 库。Small Agents 的设计目标是简洁易用,其核心逻辑只有几千行代码,这使得开发者可以轻松理解和修改智能体的行为。它支持代码代理方法,允许 AI 智能体通过生成 Python 代码来执行任务,并提供沙箱环境以确保安全。Small Agents 还具有优秀的一流工具集成,允许开发者轻松地将 Python 函数转换为智能体可用的工具,并通过 Hugging Face Hub 共享和加载这些工具。此外,Small Agents 支持任何大型语言模型,无论是开源模型还是 API 模型,这为开发者提供了极大的灵活性。Small Agents 的主要特点包括简洁性、最小抽象、基于代码的行动、工具集成和共享、以及任何模型的支持和开箱即用的可用性。Small Agents 的应用场景非常广泛,例如复杂问答、旅行规划、数据分析等。它可以帮助企业更快速、更经济高效地实现 AI 自动化,为数据科学家提供一个强大而通用的工具,并为研究人员提供一个方便的平台来研究 AI 模型的行为。总而言之,Small Agents 是一个方便的新框架,它以一种小型、简单和易访问的形式将 AI 智能体的概念带入主流。虽然 Small Agents 功能强大,但它并非唯一的选择,还有其他一些框架可用于开发和部署 AI 智能体,例如 Langchain、Llama Index、Pydantic AI、Microsoft AutoGen 和 Crew AI,它们各有优缺点。

Deep Dive

Chapters
This chapter introduces Hugging Face's Small Agents, a new Python library that simplifies the creation of AI agents. It explains its core functionality, design principles (minimal complexity and ease of use), and its relationship to previous Hugging Face projects.
  • Small Agents is a Python library from Hugging Face.
  • It simplifies the creation of AI agents.
  • It's designed with minimal complexity, using only a few thousand lines of code.
  • It's the successor to Hugging Face's earlier Transformers.Agents module.
  • It aims to make building AI agents easier for developers and data scientists.

Shownotes Transcript

Translations:
中文

This is episode number 876 on Hugging Face's Small Agents. Welcome back to the Super Data Science Podcast. I'm your host, John Krohn. Today we're diving into Hugging Face's Small Agents, S-M-O-L, agents, one word,

A new development that gives AI models more autonomy. Hugging Face, the open source AI powerhouse behind technologies like the Transformers library, has now turned its attention to AI agents, programs where AI models can plan and execute tasks on their own. And their latest library, Small Agents, makes building these agents simpler than ever.

In this short episode, I'll break down what small agents are for you, how they work, and why they're a big deal for developers, businesses, and researchers alike. Alright, so let's start off by describing what exactly small agents is. In a nutshell, it's a new Python library from Hugging Face that simplifies the creation of AI agents, making them more accessible to developers and data scientists.

HuggingFace themselves describe small agents as a library that unlocks agentic capabilities for language models. It is exactly that. This means you can take an LLM, a large language model, such as a proprietary OpenAI model, an openweight LAMA model from Meta, or a fully open-source model from DeepSeq, and easily give it the ability to act, to use tools, call APIs, and perform multi-step reasoning to accomplish a task.

Under the hood, Small Agents is designed with minimal complexity. The core logic fits in only a few thousand lines of code, keeping abstractions light and above raw Python. The simplicity is intentional. It lets developers understand and tweak agent behaviors without wading through overly complex framework code. Small Agents is actually the successor to Hugging Face's earlier Transformers.Agents module, which it will eventually replace, reflecting lessons learned to make this library lean and user-friendly.

One of the standout features is its code agent approach. Unlike some agent frameworks that represent actions in abstract JSON or text, small agents

agents, small agents, agents, literally write Python code as their way of reasoning and taking actions. In other words, the AI agent decides what to do next by generating code, for example, calling a tool or performing a calculation, which is then executed. This code-centric approach is powerful because it leverages the full flexibility of Python for the agent's actions. To keep things safe, these code executions can be sandboxed

run in isolated environments so that the agent doesn't do anything harmful on your actual system. So you get the flexibility of letting the agent write code with safeguards in place. And if you prefer a more traditional style, Small Agent still supports a standard tool calling agent that uses structured text for actions so you've got options.

Small Agents also comes with first-class tool integrations. You can easily turn any Python function into a tool that the agents can use just by decorating it with @tool, that's a Python code decorator, @tool, and adding some type hints and doc strings into your function. These tool integrations could be anything from a web search function to a database query or a calculator. Even better, Hugging Face has integrated this with their Hugging Face Hub.

This means you can share and load tools from the Hugging Face Hub. And so a community of users can publish, is publishing useful agent tools, say a weather API fetcher or a text translator, and you can plug into those agents that they've created and upload it to the hub in seconds. It's kind of like an app store for AI agent tools.

Another key feature is that Small Agents is model agnostic. You're not locked into a single AI model or provider. It supports any large language model. You can use open source models from the Hugging Face hub that I just described with the library loading them via the Hugging Face Transformers library or via the Hugging Face inference API. Or you can use API-based models from, again, OpenAI, Anthropic, or others through an integration called LightLLM.

You could even hook up local models if you have them. Essentially, whether it's a 7 billion parameter open source model running on your laptop or a cutting edge model running via a cloud API, you can plug it into small agents.

This flexibility is great for developers who want to experiment or deploy agents in different environments. To recap the technical highlights, Small Agents offers the following five features: Simplicity - so a lightweight, clear code based on the order of thousands of lines that's easy to understand. Minimal abstraction - means you work almost directly with Python code, not obscure configuration. Two,

The agents that write and execute Python code to do things have code-based actions, enabling complex actions and multi-step reasoning in a familiar language with sandboxing or safety. This is a distinctive agents-that-write-code design.

Three, small agents has tool integrations and sharing. This is a convenient way to define tools, just Python functions, and an ability to share those tools or entire agents via the Hugging Face Hub. This fosters reusability and community collaboration.

Four, Small Agents offers any model support. So compatibility with a wide range of LLMs from local models to the most popular APIs through a unified interface. You choose the model that fits your needs or constraints. And then fifth, finally, Small Agents has out-of-the-box usability. So it even provides a command line interface

the small agent CLI to run an agent with one command and a specialized web agent for web browsing tasks. This allows you to quickly test and deploy agents, making it easy to get started without writing a lot of boilerplate code.

All right, so hopefully this sounds cool, but what can you actually do with small agents? Well, quite a lot. So effectively, limitless options, but let me get some ideas in your head. Because small agents lets an LLM use tools and perform multi-step reasoning, it opens up many real-world applications across industries. So here are a few interesting examples, and actually all of these apply to really any kind of agentic AI framework.

But yeah, specifically here we're going to be talking about small agents. So as a specific example, you could do complex question answering in research. You could build an agent that given a hard question will search the web, find information, and then compose an answer.

For instance, Hugging Face provided a demo that showed an agent using a search tool to figure out how many seconds would it take for a leopard at full speed to run through the Pont des Arts. That's, I think, in Paris. And Hugging Face, the founders are originally from Paris. You could use something like OpenAI's $200 per month deep research functionality to answer that kind of question out of the box.

or you could experiment with using small agents to be a kind of research assistant, fetching facts and data from various sources to answer your queries or to write reports.

As another example, because no piece of content on agents is complete without a travel planning example, here we go. Suppose you need to plan a trip or an event with many parameters. With small agents, you could create an agent that takes a high-level goal like plan a trip to Tokyo, Kyoto, and Osaka between March 28th and April 7th, and then the tool will call the agent

And then small agents will call tools to gather information, search for flights, check train schedules, look up hotel reviews, and so on. In fact, you can use the small agent command line interface to do this in a single line where you just type small agent, one word, and then in natural language say plan a trip to Tokyo, Kyoto, and Osaka between March 28th and April 7th. That's it.

The agent could break down the task, perhaps use a Maps API for distances or a web scraper for attractions and return an organized itinerary for you. This kind of multi-step planning agent

Could be useful for you, for travel agencies, event planners, or personal assistants. Yeah, again, kind of infinite possibilities there. In addition to calling APIs, small agents can also drive a web browser, like a graphical web browser, to perform actions. Hugging Face provides something called Web Agent, one word, to do that. And so it can take instructions like go to an e-commerce website, navigate to the sales section, click the first product, and get its details and price.

And then kind of final real world example for you here is that because small agents can execute Python code, you could have them perform data analysis on the fly. Imagine an agent given a prompt to analyze last month's sales figures and identify the top three products by growth.

It could load a CSV using pandas, a Python library for data frames for tabular data, and then it could compute the results and output a summary. It essentially can combine data processing and language generation together. That's pretty damn cool.

These examples barely scratched the surface. The key is that Small Agents allows LLMs to interact with the world through tools and code in a controlled way. This means any task that involves finding information, transforming data, or making decisions based on intermediate results could potentially be handled by an AI agent. And since Hugging Face has made it easy to share components, the community can rapidly build out a library of tools and agents for countless niche applications.

All right, now let's zoom out. How do small agents fit into the broader AI ecosystem? And what do they mean for businesses and data scientists? In 2024, and particularly 2025, there's been a lot of buzz about AI agents from autonomous research assistants to AI that can use software like humans do. Small agents is part of this movement, and its introduction is likely to have

you know, a non-negligible impact on all that. For businesses, small agents could lower the barrier to automating complex tasks with AI. Instead of needing a whole team of engineers to stitch together a custom solution, a company could use small agents to prototype an AI agent that, say, handles customer inquiries or performs market research with just a few lines of Python code. Because it supports local and open source models, companies worried about data privacy can keep everything in-house on their own secure servers, on-prem,

This flexibility means businesses can choose between using powerful proprietary models or cheaper, free open models, whatever suits their needs and budget, all within the same framework. In short, Small Agents can help companies inject AI-driven automation into their workflows faster and more cost-effectively. For data scientists and software developers, Small Agents is a new powerful tool in your toolbox that's both accessible and versatile. If

If you've ever used frameworks like Langchain or worked with OpenAI's function calling, you'll find Small Agents gives you similar capabilities, but it's also lightweight and transparent. It's all open source, so you can inspect how it works, debug it, or extend it. The minimalist design means you can probably learn it quickly as well.

This means that you as an individual, not just big teams, can experiment with building your own agents. Finally, for researchers, small agents provides a convenient platform to study how AI models behave when given more autonomy. Researchers interested in reasoning, tool use, and multi-step decision making can use the library to test new ideas. And the fact that you can swap in any model means it's great for benchmarking. For example, how does a smaller open model versus a larger proprietary model perform in an agent role? That

That also sounds like a useful kind of question for benchmarking any kind of tools you're building commercially. All right, to sum things up here, Hugging Face's Small Agent is a convenient new framework that brings the concept of AI agents to the mainstream in a small, simple, and accessible form.

In today's small episode, I covered how small agents works and its key features from code writing agents and easy tool integration to support for any model you want. We explored examples of what you can build, like travel planners, web scrapers, and research assistants, all of which could be applied across any industry. If you've been waiting to get started with your own agentic AI application in your particular commercial or academic niche, with small agents now available, it could be the right time to get going.

Looking to brainstorm ideas on products or features that you could build with AI agent functionality? No problem. Talk to your colleagues or friends or your favorite conversational LLM like Claude 3.7 Sonnet, Google Gemini, or OpenAI's GPT 4.5.

And I should point out at the end of this episode, I'm just a big fan of this library. These are my own opinions. There's no Hugging Face sponsorship of this episode or actually any episode of this show ever. So yeah, I just think it's something great to check out. It could make getting AI agents out into the real world for you very

Very easy. And on the note of not being tied to Hugging Face in particular as the agentic framework that you should be working with, there are lots of other options out there for you for developing and deploying AI agents. So

Earlier in this episode, I already mentioned Langchain, which is the most popular agentic framework today. Robust and feature-rich, Langchain surpasses small agents in scalability, memory management, and built-in integrations, making it ideal for complex agentic workflows. Lama Index is another solid option. It excels at managing large datasets and memory-intensive retrieval tasks, offering out-of-the-box data integration capabilities not present in comparatively lightweight small agents.

Pydantic AI provides structured, typesafe agent outputs through explicit schema validation, contrasting small agents' simpler but less controlled output handling. And then in terms of multi-agent systems, Microsoft AutoGen specializes in collaborative multi-agent systems with dynamic coordination and communication, whereas small agents focuses primarily on single-agent tasks. And finally, you can't talk about multi-agent.

agentic systems without the popular crew AI framework, which was built explicitly for orchestrating multi-agent teams through clearly defined roles and tasks, making it superior to small agents in coordinated agent collaboration.

collaborations. We've got a link to all of these frameworks, of course, Small Agents, Langchain, Llama Index, Pydantic, Microsoft, Autogen, and Crew, all in the show notes. All right, that's it for today's episode. If you enjoyed it or know someone who might consider sharing this episode with them, leave a review of the show on your favorite podcasting platform. Tag me in a LinkedIn or Twitter post with your thoughts. And if you aren't already, obviously subscribe to the show.

The most important thing, though, is that I hope you'll just keep on listening. Until next time, keep on rocking it out there, and I'm looking forward to enjoying another round of the Super Data Science Podcast with you very soon.