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.
Give the agent the other two
This is the first time an agent has been handed a model and a tool. It is still only a description, and nothing has run.
support = Agent(
name="Support",
instructions="Answer using the tools you have. Be brief.",
model=PretendModel(),
tools=[lookup_order],
)One line does the rest
result = await Runner.run(support, "Where is order A17?")Runner.run is asynchronous, which is why there is an await. The panel can run that directly. On your own machine you would wrap it in asyncio.run, or use Runner.run_sync instead.
result = await Runner.run(support, "Where is order A17?")
print("answer:", result.final_output)
for item in result.new_items:
print(" ", type(item).__name__)Read the three items
The output ends with a list of what happened, and it repays 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, with words this time, having seen the tool's answer. |
Those three items are the agent loop. Every agent 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.