Skip to content
Simon Place
FR EN
Book a Meet call

Module 1 of 10, lesson 4 of 5

Practice

What an agent really is

Write the code

Runs in your browser, with no install, account or API key. The model is scripted, so the results are repeatable.

async function runAgent({ model, tools, prompt }) {  const messages = [{ role: 'user', content: prompt }];  while (true) {    const response = await model.create({ messages });    messages.push({ role: 'assistant', content: response.content });    if (response.stop_reason === 'end_turn') {      return response.content.find((b) => b.type === 'text').text;
Repair the agentFix the tool loop
Open in the editor
async function runAgent({ model, tools, prompt }) {  const messages = [{ role: 'user', content: prompt }];  while (true) {    const response = await model.create({ messages });    messages.push({ role: 'assistant', content: response.content });    if (response.stop_reason === 'end_turn') {      return response.content.find((b) => b.type === 'text').text;
Give the agent a skillBound the loop
Open in the editor

Running project

Running project: a customer service team receives refund requests. Write the process as a regular program. Mark each place where your code gets stuck because the path depends on the customer’s free text. Those places are the only reasons to use an agent here.

Practice

  • How to Build an Agent Amp
    Write a working code-editing agent in under 400 lines of Go.
  • AI Agents Course Hugging Face
    Free course with quizzes and assignments, from basics to a certificate.

Some of these need a free account or an API key, which may be paid.

Legal notice and privacy