Skip to content

Commit 333df48

Browse files
authored
Merge pull request #3908 from diberry/diberry/0403-agents-functions-tool
AI Agent tool: Functions
2 parents 81c7e68 + 6c3baca commit 333df48

File tree

2 files changed

+66
-3
lines changed

2 files changed

+66
-3
lines changed

.openpublishing.publish.config.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,12 @@
9292
"branch": "main",
9393
"branch_mapping": {}
9494
},
95+
{
96+
"path_to_root": "azure-functions-ai-services-agent-javascript",
97+
"url": "https://github.com/Azure-Samples/azure-functions-ai-services-agent-javascript",
98+
"branch": "main",
99+
"branch_mapping": {}
100+
},
95101
{
96102
"path_to_root": "samples-cognitive-services-speech-sdk",
97103
"url": "https://github.com/Azure-Samples/cognitive-services-speech-sdk",

articles/ai-services/agents/how-to/tools/azure-functions.md

Lines changed: 60 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ services: azure-ai-agent-service
66
manager: nitinme
77
ms.service: azure-ai-agent-service
88
ms.topic: how-to
9-
ms.date: 01/30/2025
9+
ms.date: 04/15/2025
1010
author: aahill
1111
ms.author: aahi
1212
ms.custom: azure-ai-agents
@@ -138,7 +138,9 @@ To use all features of function calling including parallel functions, you need t
138138

139139
## Define a function for your agent to call
140140

141-
Start by defining an Azure Function queue trigger function that will process function calls from the queue.
141+
Start by defining an Azure Function queue trigger function that will process AI function calls from the queue.
142+
143+
# [Python](#tab/python)
142144

143145
```python
144146
# Function to get the weather from an Azure Storage queue where the AI Agent will send function call information
@@ -172,12 +174,27 @@ def process_queue_message(msg: func.QueueMessage) -> None:
172174
logging.info(f"Sent message to output queue with message {result_message}")
173175
```
174176

177+
# [TypeScript](#tab/typescript)
178+
179+
:::code language="TypeScript" source="~/azure-functions-ai-services-agent-javascript/app/src/functions/queueGetWeather.ts" :::
180+
181+
# [REST API](#tab/rest)
182+
183+
No REST equivalent provided.
184+
185+
186+
---
187+
175188

176189
## Create an AI project client and agent
177190

178-
In the sample below we create a client and an agent that has the tools definition for the Azure Function
191+
In the sample below we create a client and an agent that has the AI tools definition for the Azure Function. The term `function` is used in two contexts within the AI tool definition:
192+
193+
* Azure Function: the type of tool. This is the Azure Functions app.
194+
* Function: the Http trigger function `GetWeather` within the Azure Function to call when the tool is invoked in the AI Project.
179195

180196
# [Python](#tab/python)
197+
181198
```python
182199
# Initialize the client and create agent for the tools Azure Functions that the agent can use
183200

@@ -231,7 +248,12 @@ agent = project_client.agents.create_agent(
231248
)
232249
```
233250

251+
# [TypeScript](#tab/typescript)
252+
253+
:::code language="TypeScript" source="~/azure-functions-ai-services-agent-javascript/app/src/azureProjectInit.ts" id="CreateAgent" :::
254+
234255
# [REST API](#tab/rest)
256+
235257
Follow the [REST API Quickstart](../../quickstart.md?pivots=rest-api) to set the right values for the environment variables `AZURE_AI_AGENTS_TOKEN` and `AZURE_AI_AGENTS_ENDPOINT`. Then create the agent using:
236258
```console
237259
curl $AZURE_AI_AGENTS_ENDPOINT/assistants?api-version=2024-12-01-preview \
@@ -276,6 +298,7 @@ curl $AZURE_AI_AGENTS_ENDPOINT/assistants?api-version=2024-12-01-preview \
276298
}'
277299
```
278300

301+
279302
---
280303

281304
## Create a thread for the agent
@@ -287,13 +310,18 @@ thread = project_client.agents.create_thread()
287310
print(f"Created thread, thread ID: {thread.id}")
288311
```
289312

313+
# [TypeScript](#tab/typescript)
314+
315+
:::code language="TypeScript" source="~/azure-functions-ai-services-agent-javascript/app/src/azureProjectInit.ts" id="CreateThread" :::
316+
290317
# [REST API](#tab/rest)
291318
```console
292319
curl $AZURE_AI_AGENTS_ENDPOINT/threads?api-version=2024-12-01-preview \
293320
-H "Authorization: Bearer $AZURE_AI_AGENTS_TOKEN" \
294321
-H "Content-Type: application/json" \
295322
-d ''
296323
```
324+
297325
---
298326

299327
## Create a run and check the output
@@ -320,6 +348,11 @@ while run.status in ["queued", "in_progress", "requires_action"]:
320348

321349
print(f"Run finished with status: {run.status}")
322350
```
351+
352+
# [TypeScript](#tab/typescript)
353+
354+
:::code language="TypeScript" source="~/azure-functions-ai-services-agent-javascript/app/src/functions/httpPrompt.ts" id="CreateMessage" :::
355+
323356
# [REST API](#tab/rest)
324357
```console
325358
curl $AZURE_AI_AGENTS_ENDPOINT/threads/thread_abc123/messages?api-version=2024-12-01-preview \
@@ -364,10 +397,34 @@ project_client.agents.delete_agent(agent.id)
364397
print("Deleted agent")
365398
```
366399

400+
# [TypeScript](#tab/typescript)
401+
402+
:::code language="TypeScript" source="~/azure-functions-ai-services-agent-javascript/app/src/functions/httpPrompt.ts" id="ListMessages" :::
403+
367404
# [REST API](#tab/rest)
368405
```console
369406
curl $AZURE_AI_AGENTS_ENDPOINT/threads/thread_abc123/messages?api-version=2024-12-01-preview \
370407
-H "Authorization: Bearer $AZURE_AI_AGENTS_TOKEN"
371408
```
372409

410+
---
411+
412+
## Troubleshooting
413+
414+
# [Python](#tab/python)
415+
416+
For any issues with the Python code, create an issue on the [sample code repository](https://github.com/Azure-Samples/azure-functions-ai-services-agent-python/issues)
417+
418+
# [TypeScript](#tab/typescript)
419+
420+
For any issues with the TypeScript code, create an issue on the [sample code repository](https://github.com/Azure-Samples/azure-functions-ai-services-agent-javascript/issues)
421+
422+
# [REST API](#tab/rest)
423+
424+
No REST equivalent provided.
425+
426+
---
427+
373428
::: zone-end
429+
430+

0 commit comments

Comments
 (0)