function agent_loop(goal, tools, max_steps):

   for step in range(max_steps):
      thought = model.think(goal, history)
      if thought.is_final_answer:
        return thought.answer
      observation = tools[thought.tool_name].call(thought.tool_input)
      history.append((thought, observation)) # think -> act -> observe -
 > repeat
