1
Curious builder0 XP earned · 300 to level 2
0 daysFinish a lesson to begin
Badge collection0 of 6 unlocked
14 small wins to finish your pathNext lesson →
Functions as tools
Write a normal function, add type hints and a docstring, and pass it in the tools list.
def get_current_time(city: str) -> dict:
"""Returns the current time in a specified city."""
return {"status": "success", "city": city, "time": "10:30 AM"}
root_agent = Agent(
model="gemini-flash-latest",
name="root_agent",
instruction="Tell people the time. Use get_current_time.",
tools=[get_current_time],
)The docstring is the interface
The model picks tools by reading the name, the type hints and the docstring. A vague docstring means a tool that never gets called, or gets called at the wrong moment.
You understood something today that you didn't yesterday.