1
Curious builder0 XP earned · 300 to level 2
0 daysFinish a lesson to begin
Badge collection0 of 6 unlocked
25 small wins to finish your pathNext lesson →
Running the agent
You have an agent, a tool and a model. Runner is the thing that puts them together and keeps going until there is an answer.
Putting the three together
support = Agent(
name="Support",
instructions="Answer using the tools you have. Be brief.",
model=PretendModel(),
tools=[lookup_order],
)This is the first time an agent has been given a model and a tool. Nothing has run yet, it is still a description.
result = await Runner.run(support, "Where is order A17?")One line, and everything happens inside it. Runner.run is asynchronous, which is why there is an await, and the panel can run that directly.
Read the three items
The output ends with a list of what happened, and it is worth reading slowly.
| Item | What it was |
|---|---|
ToolCallItem | The model asking for lookup_order. Not an answer, a request. |
ToolCallOutputItem | Your function's return value, put back into the conversation. |
MessageOutputItem | The model again, this time with words, having seen the tool's answer. |
Those three items are the agent loop. Every framework you read about is that shape with more comfort on top, and once it makes sense, agents make sense.
Break it on purpose
Take
tools=[lookup_order] out and run it again. The model has nothing to ask for, so you get one item instead of three, and the answer comes straight from the model.Try it yourself
- Remove the tool and count the items.
- Ask something without
A17in it and see which rule the model follows. - Print
result.final_outputonly, and nothing else.
This is what real progress feels like.