@@ -22,6 +22,8 @@ Azure AI Agents supports function calling, which allows you to describe the stru
22
22
23
23
* A prepared environment. See the [ overview] ( ./azure-functions.md ) article for details.
24
24
25
+ > [ !NOTE]
26
+ You must have a [ A deployed agent with the standard setup] ( ../../environment-setup.md#choose-your-setup ) . The basic agent setup is not supported.
25
27
26
28
::: zone pivot="python"
27
29
@@ -30,38 +32,30 @@ Azure AI Agents supports function calling, which allows you to describe the stru
30
32
31
33
## Define a function for your agent to call
32
34
33
- Start by defining an Azure Function queue trigger function that will process function calls from the queue. For example this sample in Python :
35
+ Start by defining an Azure Function queue trigger function that will process function calls from the queue. For example:
34
36
35
37
``` python
36
- # Function to get the weather from an Azure Storage queue where the AI Agent will send function call information
37
- # It returns the mock weather to an output queue with the correlation id for the Foundry Agent Service to pick up the result of the function call
38
- @app.function_name (name = " GetWeather" )
39
- @app.queue_trigger (arg_name = " msg" , queue_name = " input" , connection = " STORAGE_CONNECTION" )
40
- def process_queue_message (msg : func.QueueMessage) -> None :
41
- logging.info(' Python queue trigger function processed a queue item' )
42
-
43
- # Queue to send message to
44
- queue_client = QueueClient(
45
- os.environ[" STORAGE_CONNECTION__queueServiceUri" ],
46
- queue_name = " output" ,
47
- credential = DefaultAzureCredential(),
48
- message_encode_policy = BinaryBase64EncodePolicy(),
49
- message_decode_policy = BinaryBase64DecodePolicy()
50
- )
51
-
52
- # Get the content of the function call message
53
- messagepayload = json.loads(msg.get_body().decode(' utf-8' ))
54
- location = messagepayload[' location' ]
55
- correlation_id = messagepayload[' CorrelationId' ]
38
+ app = func.FunctionApp()
39
+
40
+ @app.queue_trigger (arg_name = " msg" , queue_name = " azure-function-foo-input" , connection = " STORAGE_CONNECTION" )
41
+ @app.queue_output (arg_name = " outputQueue" , queue_name = " azure-function-foo-output" , connection = " STORAGE_CONNECTION" )
42
+
43
+ def queue_trigger (inputQueue : func.QueueMessage, outputQueue : func.Out[str ]):
44
+ try :
45
+ messagepayload = json.loads(inputQueue.get_body().decode(" utf-8" ))
46
+ logging.info(f ' The function receives the following message: { json.dumps(messagepayload)} ' )
47
+ location = messagepayload[" location" ]
48
+ weather_result = f " Weather is { len (location)} degrees and sunny in { location} "
49
+ response_message = {
50
+ " Value" : weather_result,
51
+ " CorrelationId" : messagepayload[" CorrelationId" ]
52
+ }
53
+ logging.info(f ' The function returns the following message through the { outputQueue} queue: { json.dumps(response_message)} ' )
56
54
57
- # Send message to queue. Sends a mock message for the weather
58
- result_message = {
59
- ' Value' : ' Weather is 74 degrees and sunny in ' + location,
60
- ' CorrelationId' : correlation_id
61
- }
62
- queue_client.send_message(json.dumps(result_message).encode(' utf-8' ))
55
+ outputQueue.set(json.dumps(response_message))
63
56
64
- logging.info(f " Sent message to output queue with message { result_message} " )
57
+ except Exception as e:
58
+ logging.error(f " Error processing message: { e} " )
65
59
```
66
60
67
61
## Configure the Azure Function tool
@@ -93,7 +87,7 @@ azure_function_tool = AzureFunctionTool(
93
87
storage_service_endpoint = storage_service_endpoint,
94
88
),
95
89
output_queue = AzureFunctionStorageQueue( # Output queue configuration
96
- queue_name = " azure-function-tool -output" ,
90
+ queue_name = " azure-function-foo -output" ,
97
91
storage_service_endpoint = storage_service_endpoint,
98
92
),
99
93
)
0 commit comments