|
2 | 2 | import os
|
3 | 3 | import azure.functions as func
|
4 | 4 | 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 |
6 | 6 | from durable_decorators import durable_openai_agent_orchestrator
|
7 | 7 | from model_activity import create_invoke_model_activity
|
8 | 8 | from azure.identity import DefaultAzureCredential
|
@@ -146,6 +146,25 @@ async def get_weather(city: str) -> str:
|
146 | 146 | return f"Weather in {weather.city}: {weather.temperature_range}, {weather.conditions}"
|
147 | 147 |
|
148 | 148 |
|
| 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 | + |
149 | 168 | #region Implementation details
|
150 | 169 |
|
151 | 170 | create_invoke_model_activity(app) # TODO: Can we hide this line?
|
|
0 commit comments