

0 / 2 embers
0 / 3000 xp
click for more info
Complete a lesson to start your streak
click for more info
Still calibrating
click for more info
Not enough gems
Cost: 6 gems
1: Agent Loop
incomplete
2: Update Code
incomplete
3: Submit Your Repo
incomplete
This lesson's interactive features are locked, please to keep using them
So we've got some function-calling working, but it's not fair to call our program an "agent" yet for one simple reason:
It has no feedback loop.
A key part of an "agent," as defined by AI-influencer-hype-bros, is that it can continuously use its tools to iterate on its own results. So we're going to build two things:
This is a big step; take your time. (But you're also really close to the finish line now!)
chat.completions.create request into a dedicated function, you'll be calling that function in the loop. If you're doing everything in main(), that's also fine – just take care that the loop is scoped correctly.for loop for this:
for _ in range(20):
# call the model, handle responses, etc.
message = response.choices[0].message
messages.append(message)
This is the "assistant" turn in the conversation. If the model requested any tool calls, they're attached to this message, so adding it to the history keeps the conversation in sync.
"role": "tool""tool_call_id" set to that tool call's .id (this is how the model matches a result to its request)"content" set to the string your function returnedmessages.append(result_message)
Order matters: first append the assistant's message, then append one tool message per tool call. The OpenAI-style API requires every tool call to be answered by a matching tool message before the next assistant turn.
(aiagent) wagslane@MacBook-Pro-2 aiagent % uv run main.py "how does the calculator render results to the console?"
- Calling function: get_files_info
- Calling function: get_file_content
Final response:
The calculator evaluates the expression, formats the result (along with the
original expression) into a JSON-like string, and then prints that string to
the console.
You may or may not need to make adjustments to your system prompt to get the LLM to behave the way you want. You're a prompt engineer now, so act like one!
Submit the CLI tests.