use @function_tool decorator in docs
This commit is contained in:
parent
c8f3cdd6c8
commit
a373162bb0
2 changed files with 4 additions and 2 deletions
|
|
@ -13,6 +13,7 @@ The most common properties of an agent you'll configure are:
|
||||||
```python
|
```python
|
||||||
from agents import Agent, ModelSettings, function_tool
|
from agents import Agent, ModelSettings, function_tool
|
||||||
|
|
||||||
|
@function_tool
|
||||||
def get_weather(city: str) -> str:
|
def get_weather(city: str) -> str:
|
||||||
return f"The weather in {city} is sunny"
|
return f"The weather in {city} is sunny"
|
||||||
|
|
||||||
|
|
@ -20,7 +21,7 @@ agent = Agent(
|
||||||
name="Haiku agent",
|
name="Haiku agent",
|
||||||
instructions="Always respond in haiku form",
|
instructions="Always respond in haiku form",
|
||||||
model="o3-mini",
|
model="o3-mini",
|
||||||
tools=[function_tool(get_weather)],
|
tools=[get_weather],
|
||||||
)
|
)
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -36,6 +36,7 @@ class UserInfo: # (1)!
|
||||||
name: str
|
name: str
|
||||||
uid: int
|
uid: int
|
||||||
|
|
||||||
|
@function_tool
|
||||||
async def fetch_user_age(wrapper: RunContextWrapper[UserInfo]) -> str: # (2)!
|
async def fetch_user_age(wrapper: RunContextWrapper[UserInfo]) -> str: # (2)!
|
||||||
return f"User {wrapper.context.name} is 47 years old"
|
return f"User {wrapper.context.name} is 47 years old"
|
||||||
|
|
||||||
|
|
@ -44,7 +45,7 @@ async def main():
|
||||||
|
|
||||||
agent = Agent[UserInfo]( # (4)!
|
agent = Agent[UserInfo]( # (4)!
|
||||||
name="Assistant",
|
name="Assistant",
|
||||||
tools=[function_tool(fetch_user_age)],
|
tools=[fetch_user_age],
|
||||||
)
|
)
|
||||||
|
|
||||||
result = await Runner.run(
|
result = await Runner.run(
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue