Bitpath

Lesson 1 · Unit 01

An agent is a loop

Call the model, run its tool, append, repeat until it answers

12 exercisesabout 3 min

What you practise

  • Call the model, run the tool it asked for, append the result, repeat until it answers
  • Stop conditions and step limits
  • The loop traced on a scripted model

Try a question from this lesson

Pick one

A model can ask for one tool call per reply. To total the sizes of 3 files it needs size(file) three times. How many model calls until it can answer, at least?

Hint

A reply can ask for an action, but the result only arrives with the next call.

The ideas

Concept cards are short on purpose. In the app they appear between questions, after you have met the idea.

Concept

The whole agent

An agent is a model in a loop. The program calls the model. If the reply asks for a tool, the program runs it, appends the request and the result to the message list, and calls the model again. If the reply is an answer, the loop ends.

The model decides what to do. The program does it.

Python
def run(model, tools, task):
    msgs = [task]
    while True:
        reply = model(msgs)
        if "answer" in reply:
            return reply["answer"]
        fn = tools[reply["tool"]]
        out = fn(reply["arg"])
        msgs += [reply, out]

Concept

Ways out of the loop

A loop needs more than one exit. The happy one is an answer. The others protect you: a step limit, a budget of tokens or time, and a stop when the same failing call keeps coming back.

When a limit ends the run, say so. "Stopped after 20 steps" is honest. A made-up answer is not.

9 more exercises in the app

  • 3× type the answer
  • 1× true or false
  • 1× order the lines
  • 2× multiple choice
  • 1× fill the blanks
  • 1× match the pairs

Bitpath is an iOS app in development. Join the waitlist and you get one email when it is ready to try.

One email when Bitpath is ready to try. Nothing else. Privacy