Building Code Agents with Hugging Face smolagents
Instructors: Thomas Wolf, Aymeric Roucher

- Intermediate
- 44 Minutes
- 7 Video Lessons
- 5 Code Examples
- Instructors: Thomas Wolf, Aymeric Roucher
What you'll learn
Understand the architecture and benefits of code agents that write code to perform tasks, compare them to traditional tool-calling agents, and learn when to use each approach.
Build and deploy secure code agents using Hugging Face’s smolagents, including techniques for sandboxing and safe execution of LLM-generated code.
Design, monitor, and evaluate single and multi-agent systems capable of handling tasks like web browsing, data extraction, and multi-step reasoning.
About this course
Learn how to build code agents in Building Code Agents with Hugging Face smolagents, created in collaboration with Hugging Face, and taught by Thomas Wolf, co-founder and CSO, and Aymeric Roucher, Project Lead.
Tool-calling agents use large language models to write out multiple function calls sequentially to complete a complex sequence of tasks. They generate one function call, execute it, observe, reason, and then decide what to do next. Code agents take a different approach. They consolidate all these calls into a single block or snippet of code, letting the LLM lay out an entire plan of action at once. That block can be executed efficiently, providing more reliable results.
In this short course, you’ll learn how to build your own code agents using smolagents, a lightweight agentic framework from Hugging Face. Along the way, you’ll explore real-world use cases, learn how to run LLM-generated code safely, and build an evaluation system that optimizes your code agent for production.
In detail, you’ll learn:
- How agentic systems have evolved, gaining greater levels of agency over time—and why code agents are the next big step.
- The core idea of code agents and how they write their actions in code.
- The benefits of code agents by comparing their performance to function-calling agents.
- How to run code agents safely in your system using a constrained Python interpreter and sandboxing using E2B.
- To trace, debug, and assess the code agent to optimize its behaviour as it handles a flow of complex requests.
- How to build a research multi-agent system that can find information online and organize it into an interactive report.
By the end of this course, you’ll know how to build and run code agents using smolagents, understand their advantages over tool-calling agents, and be ready to deploy them safely with a structured evaluation system in your projects.
Who should join?
This course is for anyone interested in agentic workflows, especially those looking to go beyond tool-calling and experiment with LLMs that plan and execute tasks autonomously. Basic Python knowledge and familiarity with LLMs is recommended.
Course Outline
7 Lessons・5 Code ExamplesIntroduction
Video・2 mins
A Brief History of Agents
Video・5 mins
Introduction to Code Agents
Video with code examples・11 mins
Secure Code Execution
Video with code examples・9 mins
Monitoring and Evalutating your Agent
Video with code examples・6 mins
Build a Deep-Research Agent
Video with code examples・7 mins
Conclusion
Video・1 min
Appendix - Tips and Helps
Code examples・1 min
Instructors
Building Code Agents with Hugging Face smolagents
- Intermediate
- 44 Minutes
- 7 Video Lessons
- 5 Code Examples
- Instructors: Thomas Wolf, Aymeric Roucher
Course access is free for a limited time during the DeepLearning.AI learning platform beta!
Want to learn more about Generative AI?
Keep learning with updates on curated AI news, courses, and events, as well as Andrew’s thoughts from DeepLearning.AI!