Intermediate54m

Building Code Agents with Hugging Face smolagents

Instructors: Thomas Wolf, Aymeric Roucher

Hugging Face logo

Earn an accomplishment with PRO · Updated Oct 7, 2025

  • Intermediate
  • 54m
  • 7 Video Lessons
  • 4 Code Examples
  • 1 Graded Assignment PRO
  • Earn an accomplishment with PRO
  • Updated Oct 7, 2025
  • Instructors: Thomas Wolf, Aymeric Roucher
  • Hugging FaceHugging Face
  • Learn more aboutMembership PRO Plan

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.

Course recap

PRO

This course, built in partnership with Hugging Face, teaches how to build code agents -- agents that write and execute Python code to perform actions, as opposed to coding agents that write code for humans to run. The smolagents library makes code agents first-class citizens, demonstrating that writing actions as code rather than JSON tool calls is more efficient, more reliable, and enables features like loops, variable assignment, and on-the-fly tool creation.

Concept map

Concepts in Building Code Agents with Hugging Face smolagents and the courses that connect to themBuilding Code Agents with Hugging Face smolagentsBuilding Code Agents with…AI AgentsCode actions vs JSON actionsCode actions vs JSON acti…Secure code executionMulti-agent systemsAgent tracingBuilding Coding Agents with Tool ExecutionBuilding Coding Agents wi…Building AI Browser AgentsDesign, Develop, and Deploy Multi-Agent Systems with CrewAIDesign, Develop, and Depl…AI Agents for Image and Video GenerationAI Agents for Image and V…Concepts in Building Code Agents with Hugging Face smolagents and the courses that connect to themBuilding Code Agents with Hugging Face smolagentsBuilding Code A…AI AgentsCode actions vs JSON actionsCode actions vs…Secure code executionSecure code exe…Multi-agent systemsMulti-agent sys…Agent tracing

Key concepts

  • AI AgentsCode agents write Python snippets to perform actions, consolidating multiple tool calls into single code blocks
  • Code actions vs JSON actionsCode agents achieve higher success rates with fewer LLM calls by leveraging loops, variables, and function definitions
  • Secure code executionConstrained Python interpreter with AST-based execution, import whitelisting, and infinite loop prevention
  • Multi-agent systemsManager agents that delegate to specialized sub-agents (e.g., web search agent) with separated memory contexts
  • Agent tracingRecording and monitoring agent runs for production evaluation

Lesson highlights

  1. 1.Introduction — What code agents are and why they outperform JSON-based tool calling
  2. 2.A Brief History of Agents — Levels of agency, evolution of LLM capabilities, and future directions
  3. 3.Introduction to Code Agents — Head-to-head comparison of code vs tool-calling agents using smolagents
  4. 4.Secure Code Execution — Constrained Python interpreter and E2B remote sandboxes
  5. 5.Monitoring and Evaluating your Agent — Tracing agent runs with Phoenix for production monitoring
  6. 6.Build a Deep-Research Agent — Multi-agent system with manager and web search agents producing interactive reports
  7. 7.Conclusion — Course recap

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・4 Code Examples
Unlock certificates

Elevate your learning experience with Pro

Upgrade to Pro and gain unlimited accomplishments on your resume

Learn More

Instructors

Thomas Wolf

Thomas Wolf

Aymeric Roucher

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!