Live LabsComing soon10 min

Build Your First AI Agent in Python

What an agent is, in code: a model, a list of tools and a loop that decides when to stop. Built from the Hugging Face and Microsoft beginner courses.

Out on Monday 12 October10 minutes, one build start to finish

Get it in your inbox the day it is out

One email when the recording is live, then the newsletter. Unsubscribe in one click.

We email you each new issue. You can leave at any time. Privacy

Why this matters

Most agent tutorials start with a framework and hide the part that matters. Under every agent is a model, a list of tools and a loop that decides when to stop. Seeing that loop once in plain Python makes every framework easier to understand and every agent bug easier to find.

What you build

An agent that calls your own tools in a loop, in about a hundred lines of Python.

  1. Install smolagents and connect it to a model.
  2. Write two tools as plain Python functions with the tool decorator.
  3. Run the loop: the model picks a tool, reads the result and decides whether it is done.
  4. Read the steps it took, and see how a vague tool description sends it the wrong way.

The ideas behind it

  • The agent loop

    The model reads the task, picks a tool, reads the result and decides whether it is done. That repeats until it stops.

  • Tools as functions

    A tool is a Python function with a clear name and description. The model chooses it from the description alone.

  • Why descriptions matter

    A vague description sends the model to the wrong tool. Better descriptions fix more agents than better models.

Before you start

You need
Python 3.10 or later, and an API key for a model provider or a free Hugging Face token.
Length
About 10 minutes, one build start to finish.

Questions

Which model do I need?

Any model with tool calling. A free Hugging Face token is enough to follow along.

Why smolagents?

It is small enough to read, so the loop stays visible. The same ideas apply to every agent framework.

What should I build next?

Give the agent a real tool from your work, then trace a run to see each decision it makes.

Is the recorded lab free?

Yes. Watch it any time, follow the steps and keep the code you build.

How is it different from a Live Lab?

A recorded lab is one short build you follow on your own. A Live Lab builds a bigger part of the system in an hour, with time for your questions.

Then take it further

This build is one piece. The Live Lab Build an AI Mission Control App goes from here to a working part of a real system.

Build the board
Backlog, Needs you, In flight and Done, with each agent's role and tools.
Ask a human first
An agent pauses and asks on Telegram before an action it cannot undo.
Map it to your company
Swap the connectors for the tools your team already uses.

The parts of a production agent system that lab builds, lit on the map:

Week 1Architect
  • Roles and modelsOne job per agent, a model chosen for that job, and a token budget.
  • OrchestrationA queue agents pick work from, with hand-offs a person can follow.
  • Context and memoryRetrieval with sources, memory across sessions, prompts laid out for the cache.
  • Tool callingTyped tools that act in GitHub, Linear and Google.
Week 2Build
  • MCP serversEvery tool behind an MCP gateway, scoped to the role that needs it.
  • Durable executionRuns that resume after a crash and never repeat a write.
  • Human in the loopA person approves anything that cannot be undone.
Week 3Secure and deploy
  • Identity and permissionsEach agent signs in as itself and acts on behalf of a user.
  • LLM gatewayRouting, caching and a budget on every model call.
  • Traces, evals and costEvery run traced, scored and charged to the agent that made it.
  • Multi-tenancyEach team or customer kept apart, in data and in the bill.
Week 4Govern and extend
  • Policy as codeRules checked on every action, not written in a document.
  • Signed skillsNew roles built from reviewed, signed skills.