Skip to content

Commit ad28ee7

Browse files
Merge pull request #5601 from aahill/enterprise-setup
openapi doc updates
2 parents d02b547 + f5104ab commit ad28ee7

File tree

1 file changed

+11
-17
lines changed

1 file changed

+11
-17
lines changed

articles/ai-foundry/agents/how-to/tools/openapi-spec-samples.md

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: Find code samples to use OpenAPI tools with agents.
55
author: aahill
66
ms.author: aahi
77
manager: nitinme
8-
ms.date: 04/09/2025
8+
ms.date: 06/18/2025
99
ms.service: azure-ai-agent-service
1010
ms.topic: how-to
1111
ms.custom:
@@ -33,8 +33,8 @@ Use this article to find step-by-step instructions and code samples for using Op
3333

3434
:::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":::
3535

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.
3838
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).
3939

4040
1. Copy and paste your OpenAPI specification in the text box.
@@ -70,18 +70,14 @@ with AIProjectClient(
7070
) as project_client:
7171
```
7272

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).
7575

7676
```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
7878
with open(os.path.join(os.path.dirname(__file__), "weather.json"), "r") as f:
7979
openapi_weather = jsonref.loads(f.read())
8080

81-
# Load the OpenAPI specification for the countries service from a local JSON file
82-
with open(os.path.join(os.path.dirname(__file__), "countries.json"), "r") as f:
83-
openapi_countries = jsonref.loads(f.read())
84-
8581
# Create Auth object for the OpenApiTool (note: using anonymous auth here; connection or managed identity requires additional setup)
8682
auth = OpenApiAnonymousAuthDetails()
8783
# for connection setup
@@ -93,10 +89,6 @@ Similarly, the OpenAPI specification for the countries service is loaded from `c
9389
openapi_tool = OpenApiTool(
9490
name="get_weather", spec=openapi_weather, description="Retrieve weather information for a location", auth=auth
9591
)
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-
)
10092
```
10193

10294
## Agent Creation
@@ -125,7 +117,7 @@ Create the thread and add the initial user message.
125117
message = project_client.agents.messages.create(
126118
thread_id=thread.id,
127119
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?",
129121
)
130122
print(f"Created message, ID: {message.id}")
131123
```
@@ -201,6 +193,8 @@ const client = new AgentsClient(projectEndpoint, new DefaultAzureCredential());
201193

202194
## Read in the OpenAPI spec
203195

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).
197+
204198
```javascript
205199
// Read in OpenApi spec
206200
const filePath = "./data/weatherOpenApi.json";
@@ -283,7 +277,7 @@ console.log(`Deleted agent, agent ID: ${agent.id}`);
283277
:::zone pivot="csharp"
284278

285279
## Configure client and OpenAPI tool
286-
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).
287281

288282
```csharp
289283
using Azure;
@@ -392,7 +386,7 @@ Follow the [REST API Quickstart](../../quickstart.md?pivots=rest-api#api-call-in
392386

393387
## Create the OpenAPI Spec tool definition, agent, and thread
394388

395-
You might want to store the OpenAPI specification in another file and import the content to initialize the tool. This example is using `anonymous` as the authentication type.
389+
You might want to store the OpenAPI specification in another file and import the content to initialize the tool. This example is using `anonymous` as the authentication type. 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).
396390
397391
```bash
398392
curl --request POST \

0 commit comments

Comments
 (0)