|
| 1 | +--- |
| 2 | +title: "Quickstart: Use task adherence with the REST API" |
| 3 | +author: PatrickFarley |
| 4 | +manager: nitinme |
| 5 | +ms.service: azure-ai-content-safety |
| 6 | +ms.custom: |
| 7 | +ms.topic: include |
| 8 | +ms.date: 04/10/2025 |
| 9 | +ms.author: pafarley |
| 10 | +--- |
| 11 | + |
| 12 | +## Prerequisites |
| 13 | + |
| 14 | +* An Azure subscription - [Create one for free](https://azure.microsoft.com/free/cognitive-services/) |
| 15 | +* Once you have your Azure subscription, <a href="https://aka.ms/acs-create" title="Create a Content Safety resource" target="_blank">create a Content Safety resource </a> in the Azure portal to get your key and endpoint. Enter a unique name for your resource, select your subscription, and select a resource group, region, and supported pricing tier. Then select **Create**. |
| 16 | + * The resource takes a few minutes to deploy. After it finishes, select **go to resource**. In the left pane, under **Resource Management**, select **Subscription Key and Endpoint**. The endpoint and either of the keys are used to call APIs. |
| 17 | +* [cURL](https://curl.haxx.se/) installed |
| 18 | + |
| 19 | +## Use Task Adherence |
| 20 | + |
| 21 | +The following section walks through a sample request with cURL. |
| 22 | + |
| 23 | +Paste the command below into a text editor, and make the following changes. |
| 24 | + |
| 25 | +1. Replace `<endpoint>` with your resource endpoint URL. |
| 26 | +1. Replace `<your_subscription_key>` with your key. |
| 27 | +1. Optionally change the text in the `"messages"` field in the body to test different scenarios. |
| 28 | + |
| 29 | +```shell |
| 30 | +curl --request POST \ |
| 31 | + --url '<endpoint>/contentsafety/agent:analyzeTaskAdherence?api-version=2024-12-15-preview' \ |
| 32 | + --header 'Ocp-Apim-Subscription-Key: <your_subscription_key>' \ |
| 33 | + --header 'Content-Type: application/json' \ |
| 34 | + --data '{ |
| 35 | + "tools": [ |
| 36 | + { |
| 37 | + "type": "function", |
| 38 | + "function": { |
| 39 | + "name": "get_credit_card_limit", |
| 40 | + "description": "Get credit card limit of the user" |
| 41 | + } |
| 42 | + }, |
| 43 | + { |
| 44 | + "type": "function", |
| 45 | + "function": { |
| 46 | + "name": "get_car_price", |
| 47 | + "description": "Get car price of a particular model" |
| 48 | + } |
| 49 | + }, |
| 50 | + { |
| 51 | + "type": "function", |
| 52 | + "function": { |
| 53 | + "name": "order_car", |
| 54 | + "description": "Buy a particular car model instantaneously" |
| 55 | + } |
| 56 | + } |
| 57 | + ], |
| 58 | + "messages": [ |
| 59 | + { |
| 60 | + "source": "Prompt", |
| 61 | + "role": "User", |
| 62 | + "contents": "How many mahindra be6e can i buy with my credit card limit?" |
| 63 | + }, |
| 64 | + { |
| 65 | + "source": "Completion", |
| 66 | + "role": "Assistant", |
| 67 | + "contents": "Getting the required information", |
| 68 | + "toolCalls": [ |
| 69 | + { |
| 70 | + "type": "function", |
| 71 | + "function": { |
| 72 | + "name": "get_credit_card_limit", |
| 73 | + "arguments": "" |
| 74 | + }, |
| 75 | + "id": "call_001" |
| 76 | + }, |
| 77 | + { |
| 78 | + "type": "function", |
| 79 | + "function": { |
| 80 | + "name": "get_car_price", |
| 81 | + "arguments": "" |
| 82 | + }, |
| 83 | + "id": "call_002" |
| 84 | + } |
| 85 | + ] |
| 86 | + }, |
| 87 | + { |
| 88 | + "source": "Completion", |
| 89 | + "role": "Tool", |
| 90 | + "toolCallId": "call_001", |
| 91 | + "contents": "100000" |
| 92 | + }, |
| 93 | + { |
| 94 | + "source": "Completion", |
| 95 | + "role": "Tool", |
| 96 | + "toolCallId": "call_002", |
| 97 | + "contents": "10000" |
| 98 | + }, |
| 99 | + { |
| 100 | + "source" : "Completion", |
| 101 | + "role" : "Assistant", |
| 102 | + "contents" : "The price of a be6e is 10000 and your credit limit is 100000, so you can buy 10 be6e from your credit card." |
| 103 | + } |
| 104 | + ] |
| 105 | +}' |
| 106 | +``` |
| 107 | + |
| 108 | + |
| 109 | +The below fields must be included in the URL: |
| 110 | + |
| 111 | +| Name |Required? | Description | Type | |
| 112 | +| :------- |-------- |:--------------- | ------ | |
| 113 | +| **API Version** |Required |This is the API version to be checked. Current version is: `api-version=2024-09-01`. Example: `<endpoint>/contentsafety/image:analyze?api-version=2024-09-01` | String | |
| 114 | + |
| 115 | +The parameters in the request body are defined in this table: |
| 116 | + |
| 117 | +| Name | Required? | Description | Type | |
| 118 | +| :---------- | ----------- | :------------ | ------- | |
| 119 | +|tools | Yes | A list of tools that define functions to be used in the task. Each tool includes a `type` (for example, "function") and details about the function, including its `name` and `description`. |Array of JSON objects | |
| 120 | +|messages |Yes |A list of messages exchanged between the user, assistant, and tools. Each message includes the `source` (for example, "Prompt", "Completion"), `role` (for example, "User", "Assistant", "Tool"), `contents` (message text), and optionally `toolCalls` or `toolCallId`. |Array of JSON objects| |
| 121 | + |
| 122 | +Open a command prompt window and run the cURL command. |
| 123 | + |
| 124 | +### Output |
| 125 | + |
| 126 | +After you submit your request, you'll receive JSON data reflecting the analysis performed by Task Adherence. This data flags potential vulnerabilities within your agent workflow. Here’s what a typical output looks like: |
| 127 | + |
| 128 | +```json |
| 129 | +{ |
| 130 | + "taskRiskDetected": true, |
| 131 | + "details": "Agent attempts to share a document externally without user request or confirmation." |
| 132 | +} |
| 133 | +``` |
| 134 | + |
| 135 | +The JSON fields in the output are defined here: |
| 136 | + |
| 137 | +| Name | Description | Type | |
| 138 | +| :------------- | :--------------- | ------ | |
| 139 | +| taskRiskDetected | Contains risk detection results for the input. |Boolean | |
| 140 | +|details | Returns reasoning, when a risk is detected | String | |
| 141 | + |
| 142 | +A `taskRiskDetected` value of `true` signifies a detected risk, in which case we recommend review and action, such as blocking the tool invocation request or human-in-the-loop escalation. |
0 commit comments