You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/ai-foundry/agents/how-to/tools/openapi-spec-samples.md
+11-17Lines changed: 11 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@ description: Find code samples to use OpenAPI tools with agents.
5
5
author: aahill
6
6
ms.author: aahi
7
7
manager: nitinme
8
-
ms.date: 04/09/2025
8
+
ms.date: 06/18/2025
9
9
ms.service: azure-ai-agent-service
10
10
ms.topic: how-to
11
11
ms.custom:
@@ -33,8 +33,8 @@ Use this article to find step-by-step instructions and code samples for using Op
33
33
34
34
:::image type="content" source="../../media\tools\open-api-details.png" alt-text="A screenshot showing the openAPI tool details in the Azure AI Foundry portal." lightbox="../../media\tools\open-api-details.png":::
35
35
36
-
1. Select **Next** and select your authentication method. Choose `connection` for `API key`.
37
-
1. If you choose `connection`, you need to select the custom keys connection you have created before.
36
+
1. Select **Next** and select your authentication method.
37
+
1. If you choose `connection`, you need to select the custom connection you have created before.
38
38
1. If you choose `managed identity`, you need to input the audience to get your token. An example of an audience would be `https://cognitiveservices.azure.com/` to connect to Azure AI Services. Make sure you have already set up authentication and role assignment (as described in the [section](./openapi-spec.md#authenticating-with-managed-identity-microsoft-entra-id) above).
39
39
40
40
1. Copy and paste your OpenAPI specification in the text box.
@@ -70,18 +70,14 @@ with AIProjectClient(
70
70
) as project_client:
71
71
```
72
72
73
-
## Countries Tool Setup
74
-
Similarly, the OpenAPI specification for the countries service is loaded from `countries.json`. An anonymous authentication object (`OpenApiAnonymousAuthDetails`) is created, as this specific API doesn't require authentication in this example.
73
+
## Tool setup
74
+
Similarly, the OpenAPI specification is loaded from `weather.json`. An anonymous authentication object (`OpenApiAnonymousAuthDetails`) is created, as this specific API doesn't require authentication in this example. You can find an example OpenAPI spec on [GitHub](https://github.com/azure-ai-foundry/foundry-samples/blob/main/samples/microsoft/python/getting-started-agents/openapi/weather_openapi.json).
75
75
76
76
```python
77
-
# Load the OpenAPI specification for the countries service from a local JSON file
77
+
# Load the OpenAPI specification for the weather service from a local JSON file
78
78
withopen(os.path.join(os.path.dirname(__file__), "weather.json"), "r") as f:
79
79
openapi_weather = jsonref.loads(f.read())
80
80
81
-
# Load the OpenAPI specification for the countries service from a local JSON file
82
-
withopen(os.path.join(os.path.dirname(__file__), "countries.json"), "r") as f:
83
-
openapi_countries = jsonref.loads(f.read())
84
-
85
81
# Create Auth object for the OpenApiTool (note: using anonymous auth here; connection or managed identity requires additional setup)
86
82
auth = OpenApiAnonymousAuthDetails()
87
83
# for connection setup
@@ -93,10 +89,6 @@ Similarly, the OpenAPI specification for the countries service is loaded from `c
93
89
openapi_tool = OpenApiTool(
94
90
name="get_weather", spec=openapi_weather, description="Retrieve weather information for a location", auth=auth
95
91
)
96
-
# Add the countries API definition to the same tool object
97
-
openapi_tool.add_definition(
98
-
name="get_countries", spec=openapi_countries, description="Retrieve a list of countries", auth=auth
99
-
)
100
92
```
101
93
102
94
## Agent Creation
@@ -125,7 +117,7 @@ Create the thread and add the initial user message.
125
117
message = project_client.agents.messages.create(
126
118
thread_id=thread.id,
127
119
role="user",
128
-
content="What's the weather in Seattle and What is the name and population of the country that uses currency with abbreviation THB?",
120
+
content="What's the weather in Seattle?",
129
121
)
130
122
print(f"Created message, ID: {message.id}")
131
123
```
@@ -201,6 +193,8 @@ const client = new AgentsClient(projectEndpoint, new DefaultAzureCredential());
201
193
202
194
## Read in the OpenAPI spec
203
195
196
+
You can find an example OpenAPI spec on [GitHub](https://github.com/azure-ai-foundry/foundry-samples/blob/main/samples/microsoft/python/getting-started-agents/openapi/weather_openapi.json).
First, retrieve configuration details and create a `PersistentAgentsClient`, then define the `OpenApiToolDefinition` using the OpenAPI specification.
280
+
First, retrieve configuration details and create a `PersistentAgentsClient`, then define the `OpenApiToolDefinition` using the OpenAPI specification. You can find an example OpenAPI spec on [GitHub](https://github.com/azure-ai-foundry/foundry-samples/blob/main/samples/microsoft/python/getting-started-agents/openapi/weather_openapi.json).
287
281
288
282
```csharp
289
283
usingAzure;
@@ -392,7 +386,7 @@ Follow the [REST API Quickstart](../../quickstart.md?pivots=rest-api#api-call-in
392
386
393
387
## Create the OpenAPI Spec tool definition, agent, and thread
0 commit comments