Introduce tool_use_behavior on agents

This commit is contained in:
Rohan Mehta
2025-03-18 21:43:02 -04:00
parent 6f7e801da0
commit 10aa5555af
12 changed files with 594 additions and 26 deletions
+34
View File
@@ -0,0 +1,34 @@
import asyncio
from pydantic import BaseModel
from agents import Agent, Runner, function_tool
class Weather(BaseModel):
city: str
temperature_range: str
conditions: str
@function_tool
def get_weather(city: str) -> Weather:
print("[debug] get_weather called")
return Weather(city=city, temperature_range="14-20C", conditions="Sunny with wind.")
agent = Agent(
name="Hello world",
instructions="You are a helpful agent.",
tools=[get_weather],
)
async def main():
result = await Runner.run(agent, input="What's the weather in Tokyo?")
print(result.final_output)
# The weather in Tokyo is sunny.
if __name__ == "__main__":
asyncio.run(main())