For the complete documentation index, see llms.txt. This page is also available as Markdown.

Create a Simple AI Agent Rule

Use Case: The rules in this tutorial are designed to be called by a user when a new NDA arrives and the team needs to determine necessary redlines in real time.

Goal: The goal is to automate the process so the system sends the NDA to DecisionRules and retrieves data identifying the redlines that must be addressed.

The primary features in DecisionRules used to achieve this goal are the AI Agent Rule and the Decision Flow. In this detailed end-to-end tutorial, we will guide you through building an AI Agent Rule to analyze the unstructured data in a new NDA and return it in a structured JSON format. In the second part, we will model a Decision Flow that integrates the AI Agent Rule to achieve the goal in a predictable, deterministic way.

We will cover navigating the creation process, configuring Decision Flow nodes, and generating the final output. This includes: Identifying redlines based on rule evaluations, providing text references for those redlines, and creating personalized messages in case of misbehaviour because the unstructured data is inconsistent.

At the end weโ€™ll test our new rule with one mock example. This tutorial will help you understand key AI Agent Rule practices and data manipulation techniques.

1st Part: How to create a simple AI agent rule

Let's advance one step at a time.

1. Create a new AI Agent Rule

To display the rules creation list, click the + Create button on the search bar. Select your rule and you will be prompted to provide a name. For this example, we will create a AI Agent Rule for analysing a new NDA, select a name for your rule as you wish and press "Confirm". The new rule will be created and its design interface will be displayed.

2. Create the input and output (I/O) model

We will now create the Input/Output model which is used to set the instructions for the AI and the fields of the output. Similar to the other rules, there are two ways to write these models:

Using the simple editor

First, you can switch from "Designer" to "Model" at the centre of the top bar.

Delete the default attribute "input" by clicking the trash can icon next to the name. Then, add your own attributes: First create the root of your attributes clicking the +Add button. For this example, you will only need one root: nda. AAfterward, you can add all the data required for the analysis of that nda object: originatingParty, disclosingParty, receivingParty, and text.

Now, let's proceed with the output model. It is configured in the same way. Add two root attributes: terms and reference. Then, add identical child attributes to both roots, as they are logically connected.

  • The terms fields are designed to capture the precise data, indicating whether the information exists and providing the exact number, name, or sentence.

  • The reference fields will store the exact words from the text that the AI used to generate the corresponding "terms" report.

Rename the new attributes according to the information you wish to obtain. A comprehensive list of attributes that will be useful for future examples and exercises includes:

  • scope_and_definition, confidentiality_period_years, governing_law, notice_period_days, reciprocity, exclusions, permitted_disclosures, liability_cap_usd, return_of_information_required, return_deadline_days, and residuals_clause.

Using the JSON editor

Alternatively, the JSON editor can reduce the time required to define your I/O model through simple copying and pasting. You can provide the input and output models in JSON format from any external source. For this tutorial, use the following format to copy and paste into your editor:

For now, we are done!

More information on the JSON editor can be found here.

3. Set the configurations of the background

To set up the environment where your LLM will operate, switch back from the "Model" view to the "Designer" view. Use the left sidebar to configure the settings according to your requirements:

  • AI Model: We will use Gemini 1.5 Flash as an example. You can, of course, select any other available model from the dropdown list in your rule.

  • Connector: For this example, our LLM is connected via a connector named gemini (connection-vhksg). The options shown to you will depend on the connectors you have already created in your Space.

  • Cache AI Response (Toggle): During the creation and testing of this new rule, you should activate the Cache.

  • Explainable AI (Toggle): For this tutorial, Explainable AI is not necessary. It is better suited for more advanced exercises.

  • Data Dictionary: Briefly check this panel to ensure you have all the information required to build your prompt.

4. Build the Prompt

Prompt engineering practices evolve rapidly; therefore, the suggestions in this section will be continuously improved. What is relevant to notice is to apply the best DecisionRules practices for instructions: Ensure your input model is framed with precision, use the Data Dictionary as direct reference, and write with your best clarity.

For this example, we will explicitly define the Role assumed by the AI, the Context of the analysis, and the Task required from the model.

The placeholders in the form {a.b} (such as {nda.text}) are dynamic attributes. At runtime, DecisionRules replaces these placeholders with the actual content of your input payload. This allows a single AI Agent rule to analyze thousands of different NDAs.

Remark: If your analysis requires a reference document (such as a company standard or a regulatory guideline), you can use the Attachments feature:

  1. Navigate to the Attachments tab and click Add Attachment to upload your file (PDF, TXT, etc.).

  2. Return to the Prompt/Instruction editor.

  3. Drag the file from the Data Dictionary into your prompt. The AI will now be able to reason across both the input data and the attached document.

5. Edit the Annotations

Annotations are the most critical part of the AI Agent rule because they define the conditions of engagement for the model's response. Here you will find the most extensive work. We will cover each detail.

In the main panel, navigate to the "Annotations" tab. The interface is organised into three columns:

The first column reflects your output model. The second column is for the specification of the data types expected in each particular output attribute. The third column is a description of what exactly you are expecting and how.

Setting Data Types: Root attributes (like terms and reference ) will always be of the {} Object type. For the "child" attributes under terms, select the type that best fits the logic. For instance, using Number for years or Boolean for the presence of a clause. This ensures your downstream Decision Flows can process the data without errors.

Attribute
Data Type

scope_and_definition

Text

confidentiality_period_years

Number

governing_law

Text

liability_cap_usd

Number

permitted_disclosures

Boolean

residuals_clause

Boolean

Writing Effective Descriptions: Your descriptions should be treated as "mini-prompts." A good description includes the conditions required to satisfy the field. To exemplify this feature, we will focus on the reference root, and the description of its "child" attributes.

First, ensure all its child attributes are set to the Text data type. These descriptions should follow a consistent pattern, instructing the AI to provide the verbatim evidence from the NDA. For instance:

Attribute
Description

scope_and_definition

Return a string with the exact words in the text of the nda, where you extracted the info for the ouput above: terms.scope_and_definition.

confidentiality_period_years

Return a string with the exact words in the text of the nda, where you extracted the info for the ouput above: terms.confidentiality_period_years.

6. Test the Agent

Now we can test our rule in the Test Bench. Click the Test Bench icon on the far left of the bottom bar. Once clicked, the Test Bench will appear at the bottom of the page.

You can then fill in some mock data using the sample NDA provided below. Use the specifications from the document to complete the input fields, and remember to paste the full text of the NDA into the nda.text field. Click the Run button, and the results will be displayed on the right-hand side of the Bench. Note that you can switch between the Simple Bench and the JSON Bench to view the output.

58KB
Open

2nd Part: How to integrate the AI Agent Rule into a Decision Flow

In this section, we will create a Decision Flow that uses the structured data provided by the AI Agent rule to validate NDA parameters against company standards and determine which redlines are pertinent.

Intro: Logic of the flow

IO Model

Our Input Model captures the data required to run the AI Agent rule from Part 1; therefore, it will replicate that rule's input model. This design is due to the fact that the results from the AI node contain all the information necessary to drive the other rules and nodes in the flow, and it will be the first node.

Our Output Model is constructed slightly different. It includes redline validation, the specific text reference used to accept or reject those redlines, and error handling options to manage potential drawbacks. In this sample, the company evaluates four minimal standards for accepting an NDA (more complex sets of standards will be handled in future examples).

Flow of the Process

When designing the Decision Flow as a decision process, establishing a logical steps ensures a faster selection and location of the nodes.

  1. AI Analysis: Start by converting the unstructured data of the NDA text into a typed JSON response. This step enables the precise extraction of attributes from the NDA for evaluation. At this stage, the AI analysis is key to using other strong, predictable rules over the NDA.

  2. Validation of Company Standards: This is the core of the flow; the company's standards are saved as Rules within the Space. The flow will call four rules to evaluate a set of four minimal standards: the confidentiality period, the governing law country, the notice period, and the reciprocity of the agreement. Based on these rules, the system decides which sections of the NDA should be redlined.

  3. Error Handling: Due to the nature of AI, it is not guaranteed that the NDA will provide all necessary data in the first call, and LLM response times can vary. With a couple of nodes, we design a path to follow in case the NDA is missing information or the LLM request times out. These nodes provide a warning and a message to help resolve the issues quickly.

  4. Generating the Final Redlines: Use the values from the previous steps to populate the properties specified in the output model. Additionally, if there are errors, an appropriate error message is sent.

1. AI Analysis

It is time to add the first node to the canvas. Begin by adding an AI Agent node and connecting the Start node to it. Open the node settings, click the Select Agent dropdown, and choose the AI Agent rule you created to analyze the NDA. Once selected, the rule's input model will be displayed. You now need to map the data from the Data Dictionary to the rule's input: drag and drop the nda root from the Data Dictionary into the Rule Inputs section for the attribute named nda . Save the values in the modal.

Adding the AI Agent node

2. Validation of Company Standards

Drag and drop four Business Rule nodes onto the canvas and position them in parallel to the right of the AI Agent node.

In the first Business Rule we will use the Reciprocity tree (A JSON file with the design of the rule is here below). The standard is simple: The NDA must be reciprocal. The logic of the standard can be expressed in a Decision Tree keeping the simplicity:

  1. Missed information: IF the field for the NDA reciprocity report is empty, THEN return error message (Remember the AI can result null if the NDA is not clear).

  2. Reciprocal NDA: IF the NDA reciprocity report contains true, THEN return passed.

  3. No Reciprocal NDA: IF the NDA reciprocity report contains false, THEN return failed and the reason.

In the second Business Rule we will use the Notice Period tree (A JSON file with the design of the rule is here below). The standard is simple: We must have minimum 30 days to solve and communicate leaks. The logic of the standard can be expressed in a Decision Tree keeping the simplicity:

  1. Missed information: IF the field for the NDA notice period is empty, THEN return error message (Remember the AI result null if the NDA misses this information).

  2. Enough Notice Period: IF the NDA notice period is greater or equal to 30 days, THEN return passed.

  3. Not Enough Notice Period: IF the NDA notice period is less than 30 days, THEN return failed and the reason.

In the third Business Rule we will use the Confidentiality Period tree (A JSON file with the design of the rule is here below). The standard is simple: We must have maximum 15 years for confidentiality. The logic of the standard can be expressed in a Decision Tree keeping the simplicity:

  1. Missed information: IF the field for the NDA confidentiality period is empty, THEN return error message (Remember the AI result null if the NDA misses this information).

  2. Under the limit period: IF the NDA confidentiality period is less or equal to 15 years, THEN return passed.

  3. Over the limit period: IF the NDA confidentiality period is greater than 15 years, THEN return failed and the reason.

In the fourth Business Rule we will use the Governing Law tree (A JSON file with the design of the rule is here below). The standard is simple: We only accept the governing law from United States. The logic of the standard can be expressed in a Decision Tree keeping the simplicity:

  1. Missed information: IF the field for the NDA governing law is empty, THEN return error message (Remember the AI can result null if the NDA is not clear).

  2. Under the limit period: IF the NDA governing law is from US, THEN return passed.

  3. Over the limit period: IF the NDA governing law is from any other country, THEN return failed and the reason.

The AI Agent node features two output ports; connect the green (success) port to each of the four Decision Trees you just configured.

3. Error handle

Place an Assign node below the column of Business Rule nodes and connect the red (failure) anchor of the AI Agent node to it. The red path is triggered if the AI request times out or fails. Open the Assign node and create a target to report the LLM error (e.g. AnalyzerError.code ). Then, assign a static error code such as AI_PROCESSING_ERROR.

Add an Append node to the right of your design and connect it to all the nodes in the preceding parallel column (the four Business Rule nodes and the error-handling Assign node). So far, we have identified two types of errors: AI timeouts and empty fields within the NDA report. This node will store a single array containing all potential issues. In the node settings, create a target array called errors and drag all attributes that report errors into the "Values to Append" section.

Finally, place a Switch node on the canvas and connect the output of the Append node to it. Open the Switch settings and create a case for "Errors in evaluation". The logic is as follows: IF the errors array from the Append node is not empty, THEN follow the path for error mapping; OTHERWISE, proceed to the redline mapping.

To configure this, drag and drop the errors object created in the Append node into the Condition field. Select the Contains Text function and enter the value: ERROR. The Default case will automatically handle the "otherwise" scenario, directing the flow when no errors are present.

4. Generating the final redlines

Now that all necessary values have been gathered, we can generate the final redlines, including the validation results for the four minimal standards and their corresponding text references. To map these for the final output, we will use an Assign node.

  1. Success Path: Connect the Default port of the Switch node to a new Assign node. Open the configuration.

  2. Map Results: On the Target side, add all eight output attributes for redlines and references. For the redlines, map the results from the four Decision Trees as the Source. For the references, map the corresponding data from the AI Agent rule.

Assigning values to Decision Flow Output

To manage exceptions, add a second Assign node. Connect the "AI error in the evaluation" port of the Switch node to this new node.

Note: If errors are stored in our array, the Switch node can direct the flow to both the success Assign node (to provide any partially processed info) and the error Assign node simultaneously.

In the error Assign node, set the Target to your two error output attributes:

  • output.errors.types: Map the errors array from the Append node.

  • output.errors.message: Enter a customized message such as:

Detail of Switch node directing the process

Congratulations! ๐ŸŽ‰ You've completed the Decision Flow, which might look something like this:

Decision Flow overview

In the next section, weโ€™ll test the Decision Flow with some inputs to ensure itโ€™s functioning correctly. Before proceeding, please double-check that all Decision Flow nodes are fully configured and properly connected.

5. Testing the Decision Flow and the AI Agent Rule

Now we can test our rule in Test Bench.

We can click the Test Bench icon at the beginning of the bottombar. After clicking the icon, the Test Bench will show up at the bottom of the page.

Then we can fill in some mock data. We can use the same mock example from above. You can download the document here below as well. Use the specifications of the document to complete the input, and remember to paste the entire text of the NDA in nda.text. Click the Run button and the result will be displayed in right hand side of the Test Bench. Note that you can switch between the Simple Bench and the JSON Bench.

58KB
Open

Summary

The rules of this tutorial were designed to be called by a user when a new NDA arrives and the team want to decide the necessary redlines in real time. The goal was to automate the process such that the system sends the NDA to DecisionRules and retrieve the evaluation of the document with the redlines that must be pointed out. The main features in DecisionRules to achieve this goal are the AI Agent Rule and the Decision Flow. In this tutorial, we built an AI Agent Rule for the analysis of the unstructured data given in the new NDA, getting back the data of the NDA in structured JSON format. The attributes of the JSON were designed to be precise and some of them required by the standards to be evaluated. The second part of this section was the elaboration of a Decision Flow to complete the goal in a predictable way. The flow uses the results of the AI rule and runs:

  • The evaluation of precise NDA attributes, according to the standards of the company, using Decision Trees.

  • Because the original NDA is unstructured, the data in the flow may misbehave, and so, the detection of information gaps and the report of times out.

  • The presentation of the redlines, with the corresponding references, and in case of misbehaviours, error messages for the solution of relevant gaps or the solution of the connected LLM performance.

To wrap up, letโ€™s go over the management and maintenance of this Decision Flow. Once the rules are built, the Business Users only have to manage the Decision Trees. In fact, the Business User not just know the company's standards, but these users have the decision capacity and knowledge to change those standards, so when some of the standards must be changed, for example:

  • The NDA must be reciprocal - to - It is not relevant if the NDA is reciprocal.

  • We must have minimum 30 days to solve and communicate leaks - to - 20 days.

  • We must have maximum 15 years for confidentiality - to - 20 years.

  • We only accept the governing law from United States - to - the law from Australia.

These changes can be done directly by them, just changing values on Decision Trees, for instance from 15 to 20. See that the roles of the users can be very different, but everyone collaborate to directly on the hand of the right expert, the capacity to make changes in the company's applications for prediction, transparency and velocity.

Last updated