Merge pull request #99 from openai/update_docs

use @function_tool decorator in docs
This commit is contained in:
Rohan Mehta 2025-03-12 11:29:26 -07:00 committed by GitHub
commit e86e5e2e6d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 4 additions and 2 deletions

View file

@ -13,6 +13,7 @@ The most common properties of an agent you'll configure are:
```python
from agents import Agent, ModelSettings, function_tool
@function_tool
def get_weather(city: str) -> str:
return f"The weather in {city} is sunny"
@ -20,7 +21,7 @@ agent = Agent(
name="Haiku agent",
instructions="Always respond in haiku form",
model="o3-mini",
tools=[function_tool(get_weather)],
tools=[get_weather],
)
```

View file

@ -36,6 +36,7 @@ class UserInfo: # (1)!
name: str
uid: int
@function_tool
async def fetch_user_age(wrapper: RunContextWrapper[UserInfo]) -> str: # (2)!
return f"User {wrapper.context.name} is 47 years old"
@ -44,7 +45,7 @@ async def main():
agent = Agent[UserInfo]( # (4)!
name="Assistant",
tools=[function_tool(fetch_user_age)],
tools=[fetch_user_age],
)
result = await Runner.run(