Code agents with smolagents: one code block instead of many tool calls
- Source
- deeplearning.ai
- Publisher
- DeepLearning.AI
- Author
- Andrew Ng
- Date

Context
A code agent writes its plan as a short and runs it, where a tool-calling agent makes one call at a time and pauses after each to decide the next. Andrew Ng explained the idea in announcing Building Code Agents with Hugging Face smolagents, and separated it from coding agents such as Windsurf or Cursor, which write code for you. Ng's example is a weather forecast for your current location. A tool-calling agent asks for a GPS lookup, waits for the runtime to execute it, then forms a second call to a weather service, waits again and formats the answer. A code agent writes one block that calls both functions, the runtime executes it in a single step, and the model formats the result.
That example saves only one step, and Ng's broader claim is qualitative: in more complex scenarios, a chunk of code "can be much more reliable and concise" than a sequence of function calls. The course page says students compare code agents' performance with function-calling agents, but neither source gives figures. Running code that a model wrote is the cost of this design, so the course covers a constrained Python interpreter and with E2B, plus tracing and evaluation to debug the agent. It is taught by Hugging Face co-founder and chief science officer Thomas Wolf and agents project lead Aymeric Roucher, runs seven lessons in 54 minutes, and ends with a research that searches online and organizes what it finds into an interactive report.
- Program — A set of instructions stored so that a computer can run it.
- Function — A named block of instructions that takes inputs, called arguments, and hands back a result, called its return value.
- Sandbox — An enforced restriction that confines a process to specified files, network destinations and other resources, applied by the operating system, a container or a virtual machine.
- multi-agent — Using several AI agents on one problem — splitting work in parallel, checking each other, or filling different roles like planner and reviewer.






