Build a Python research assistant that executes a think-act-observe loop using smolagents, Claude, and Hugging Face tools to search the web, retrieve from private knowledge bases, and cite sources. Deploy the final agent as an interactive web application on Hugging Face Spaces, learning to implement custom tools, multi-agent delegation, retrieval-augmented generation, and observability along the way.
You are going to build, module by module, a Python program that starts as a five-line agent and ends as a deployable web application: a "research assistant" that searches the open web, reads pages it finds, and answers questions from a private knowledge base — citing its sources — running as a Hugging Face Space anyone can visit in a browser.
Every module adds one capability to the same underlying idea. By the end you will be able to explain, and not just recite, why each design choice in the finished agent is there.
A chatbot answers a prompt once and stops. An agent is different: it repeats a loop —
until it decides it has enough information to give a final answer. "Think" is the language model reasoning about what to do next. "Act" is running a tool — a function the model chooses to call, such as a web search or a lookup in a knowledge base. "Observe" is feeding the tool's result back to the model so it can decide the next step.
The think-act-observe loop: the model reasons, chooses and runs a tool, reads the result, and repeats until it can answer.
Everything in this course is a variation on that loop: which tools are available, how many agents share the work, how the loop is instrumented, and how it is exposed to a user.
smolagents is Hugging Face's open-source Python library for building agents like the one above. It is deliberately small — its core logic is on the order of a thousand lines — which matters for you as a learner: you can read and reason about what it does rather than treating it as a black box.
Its signature idea is the CodeAgent. Many agent frameworks have the model emit a tool call as a block of JSON, which a runtime then parses and executes. CodeAgent instead has the model write and execute actual Python code to call its tools. This means the model can use loops, conditionals, and variables to combine tools within a single step, instead of being limited to one tool call per round trip — which tends to mean fewer steps and lower cost for multi-tool tasks. You will meet CodeAgent's alternative, ToolCallingAgent, which does use the more conventional JSON-call approach, and see concretely where each one is the better fit.
The "think" step needs a language model to do the reasoning. This course uses Anthropic's Claude Sonnet as that model. smolagents does not talk to Anthropic directly; it goes through an adapter called LiteLLMModel, which gives smolagents a uniform way to call many different model providers. Hugging Face's role in this course is not to host the reasoning model — it is the agent framework (smolagents), a Hub-hosted embedding model you will use for retrieval, tool loading over MCP, the Gradio UI library, and Spaces as the deployment target.
You will need an Anthropic API key to run any of the agents in this course, and Anthropic bills per token — running the exercises will incur small, usage-based charges on your account.
Working through the course in order, you will layer in:
@tool, and learning that the function's docstring, especially its Args: section, is not documentation for humans but the literal contract the model reads to decide how to call it.CodeAgent's Python sandbox and its additional_authorized_imports setting (which has no equivalent for ToolCallingAgent, since there is no code interpreter to import into) shape what each agent can safely do.ToolCollection.from_mcp, and the explicit trust decision (trust_remote_code) that loading someone else's code requires.GradioUI so its steps stream live to a browser instead of only printing to a terminal.step_callbacks, the agent's memory, and its monitor's token counts to see what an agent actually did and what it cost, plus max_steps as a guard rail against runaway loops.The course closes with the capstone: a single agent combining web search, a webpage-reading tool, and retrieval over a private knowledge base, instructed to prefer the knowledge base and always cite its sources — deployed as a working Hugging Face Space.
The finished, working version of everything you will build lives at https://github.com/ChuckIrvine/hf_agent_tutorial. You do not need to clone it or browse its source to follow this course — every file a lesson needs is pulled from that repository and given to you directly at the point you need it. Instead, you will create your own project directory on your machine and build up the same modules yourself, file by file, running each one from your terminal as you go. If you want to explore beyond what a lesson covers, the repository is there and freely licensed (Apache-2.0) for you to read.