Skip to content

Commit 20f5c7b

Browse files
committed
Add a sample for @function_tool
1 parent f5f3a94 commit 20f5c7b

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

samples-v2/openai_agents/function_app.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import os
33
import azure.functions as func
44
from openai import AsyncAzureOpenAI
5-
from agents import Agent, Runner, set_default_openai_client
5+
from agents import Agent, Runner, set_default_openai_client, function_tool
66
from durable_decorators import durable_openai_agent_orchestrator
77
from model_activity import create_invoke_model_activity
88
from azure.identity import DefaultAzureCredential
@@ -146,6 +146,25 @@ async def get_weather(city: str) -> str:
146146
return f"Weather in {weather.city}: {weather.temperature_range}, {weather.conditions}"
147147

148148

149+
150+
@function_tool
151+
def calculate_circle_area(radius: float) -> float:
152+
"""Calculate the area of a circle given its radius."""
153+
import math
154+
return math.pi * radius ** 2
155+
156+
@app.orchestration_trigger(context_name="context")
157+
@durable_openai_agent_orchestrator
158+
def math_assistant(context):
159+
agent = Agent(
160+
name="Math Assistant",
161+
instructions="You are a helpful math assistant. Use the available tools to help with calculations.",
162+
tools=[calculate_circle_area],
163+
)
164+
result = Runner.run_sync(agent, input="What is the area of a circle with radius 5?")
165+
return result.final_output
166+
167+
149168
#region Implementation details
150169

151170
create_invoke_model_activity(app) # TODO: Can we hide this line?

0 commit comments

Comments
 (0)