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 →
An agent as a tool
Sometimes you want another agent's answer, not another agent's conversation. Turn it into a tool and it reports back.
writer = Agent(
name="Writer",
instructions="Write one polite sentence.",
model=PretendModel(["We are sorry about the delay and are looking into it."]),
)write_reply = writer.as_tool(
tool_name="write_reply",
tool_description="Write a polite reply to a customer.",
)as_tool gives you an ordinary tool. The name and description are yours to write, and they matter exactly as much as they did in lesson 2, because this is what the calling agent reads when it decides.
result = await Runner.run(support, "The order is late, tell them something")
print("tool the agent had:", [t.name for t in support.tools])
print("answer: ", result.final_output)Support stayed in charge the whole time. Writer ran, returned its sentence, and Support used it and wrote the final answer. Compare that with lesson 13, where Billing answered the customer itself.
What it is good for
- A second opinion. Ask a checker agent whether a draft is acceptable, then act on the answer.
- A narrow skill. Translation, summarising, formatting. Things with an input and an output.
- Fan out. One agent can call three others and combine what they say, which a handoff cannot do.
It is a real run
The inner agent gets its own run, its own turns and its own tools. It is not a function call, it is an agent, so give it small instructions and keep it fast.
Try it yourself
- Change the tool description and think about when a real model would pick it.
- Give Writer a tool of its own and watch it run inside the outer run.
- Add a second agent as a tool and script a call to it.
This is what real progress feels like.