@@ -22,6 +22,8 @@ Azure AI Agents supports function calling, which allows you to describe the stru
2222
2323* A prepared environment. See the [ overview] ( ./azure-functions.md ) article for details.
2424
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.
2527
2628::: zone pivot="python"
2729
@@ -30,38 +32,30 @@ Azure AI Agents supports function calling, which allows you to describe the stru
3032
3133## Define a function for your agent to call
3234
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:
3436
3537``` 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)} ' )
5654
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))
6356
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} " )
6559```
6660
6761## Configure the Azure Function tool
@@ -93,7 +87,7 @@ azure_function_tool = AzureFunctionTool(
9387 storage_service_endpoint = storage_service_endpoint,
9488 ),
9589 output_queue = AzureFunctionStorageQueue( # Output queue configuration
96- queue_name = " azure-function-tool -output" ,
90+ queue_name = " azure-function-foo -output" ,
9791 storage_service_endpoint = storage_service_endpoint,
9892 ),
9993)
0 commit comments