Skip to content

Commit b9ec7ac

Browse files
committed
Add weather_expert sample
1 parent 7ecbcd2 commit b9ec7ac

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

samples-v2/openai_agents/function_app.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
1+
from dataclasses import dataclass
12
import os
23
import azure.functions as func
34
from openai import AsyncAzureOpenAI
45
from agents import Agent, Runner, set_default_openai_client
56
from durable_decorators import durable_openai_agent_orchestrator
67
from model_activity import create_invoke_model_activity
78
from azure.identity import DefaultAzureCredential
9+
from tools import activity_as_tool
810

911

1012
#region Regular Azure OpenAI setup
@@ -115,6 +117,34 @@ async def hello(name: str):
115117
return f"Hello {name}!"
116118

117119

120+
@app.orchestration_trigger(context_name="context")
121+
@durable_openai_agent_orchestrator
122+
def weather_expert(context):
123+
agent = Agent(
124+
name="Hello world",
125+
instructions="You are a helpful agent.",
126+
tools=[
127+
activity_as_tool(get_weather)
128+
],
129+
)
130+
131+
result = Runner.run_sync(agent, "What is the weather in Tokio?")
132+
return result.final_output
133+
134+
@dataclass
135+
class Weather:
136+
city: str
137+
temperature_range: str
138+
conditions: str
139+
140+
@app.activity_trigger(input_name="city")
141+
async def get_weather(city: str) -> Weather:
142+
"""
143+
Get the weather for a given city.
144+
"""
145+
return Weather(city=city, temperature_range="14-20C", conditions="Sunny with wind.")
146+
147+
118148
#region Implementation details
119149

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

samples-v2/openai_agents/tools.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from agents import Tool
2+
3+
4+
def activity_as_tool(activity_func) -> Tool:
5+
"""
6+
Convert an Azure Durable Functions activity to an OpenAI Agents SDK Tool.
7+
8+
Args:
9+
activity_func: The Azure Functions activity function to convert
10+
11+
Returns:
12+
Tool: An OpenAI Agents SDK Tool object
13+
"""
14+
# TODO: Implement the conversion logic
15+
raise NotImplementedError("activity_as_tool is not yet implemented")

0 commit comments

Comments
 (0)