Locked learning resources

Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Locked learning resources

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

The Agent Loop

An agent is the model and the harness working together on a task over many steps. When an assistant, the app you chat with, works through a task on its own like this, it’s acting as an agent. Each of its steps follows the same cycle, called the agent loop:

  1. The app gathers what the model needs: your message, instructions, and results so far.
  2. The model reads all of it and either replies or asks for an action.
  3. The app checks whether it should go ahead, carries out the action, and passes the result back.
  4. The cycle repeats until the model has an answer for you.

Now you can try the loop from the app’s side. In the game below, you play the app. Someone has asked for a business trip to a client meeting, and the model’s requests arrive one at a time. You decide what to do with each one:

Interactive diagram — enable JavaScript to view.

Who Asks Permission

Locked learning resources

Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Already a member? Sign-In

Locked learning resources

The full lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Already a member? Sign-In

00:00 The Agent Loop. An agent is the model and the harness working together on a task, over many steps. When an assistant works through a task on its own like this, it’s acting as an agent.

00:13 Each of its steps follows the same cycle, called the agent loop.

00:18 Here’s the cycle. First, the app gathers what the model needs. That’s your message, the instructions, and the results so far. Next, the model reads all of it, and it either replies or asks for an action.

00:30 Then the app checks whether it should go ahead. It carries out the action, and it passes the result back. The cycle repeats until the model has an answer for you.

00:40 Here’s one trip, step by step. Say someone asks for help with a trip to a client meeting next week. The app gathers that request and sends it to the model.

00:49 The model asks to read their calendar for next week. The app checks whether it should go ahead, reads the calendar, and passes the result back. Then the next trip starts from there.

01:00 When your assistant asks you to allow something, the model has already asked for the action. The app is checking with you before it carries it out.

01:09 Apps draw the line in different places. Reading and searching usually go ahead. Sending, buying, and deleting are more likely to wait for your OK. Many apps let you change these settings.

01:21 Either way, it’s the app that handles permissions. Some jobs take one trip through the loop. Say you paste an article into your message, and you ask for a one-paragraph summary.

01:32 Everything the model needs is already in front of it. The app gathers your message and the article. The model reads them, and it replies right away. That’s one trip.

01:43 Comparing hotel prices for a conference across several websites takes many trips. The agent has to search. It opens each site, and it reads the prices. Each of those steps is another trip around the loop.

01:57 The model asks, the app carries it out, and the result comes back. Then it keeps going, until it has what it needs.

02:05 The more a job needs the agent to look things up, open files, or change something, the more trips it takes. And the longer you wait for a reply. When you already have the text the model needs, pasting it into your message saves those trips.

02:19 So every step of an agent is one trip around the same loop, and the app decides what gets carried out. Below this video, you can play the app yourself. Someone has asked for a business trip to a client meeting.

02:31 The model’s requests arrive one at a time, and you decide what to do with each one.

Become a Member to join the conversation.