AI for contracts in Team assistant

This guide describes what needs to be done to make AI over Contracts work properly in any project .

It is suitable for consultants and partners who handle implementations in Team assistant.

Get an Azure API Key

First, you need to have functional access to Azure OpenAI:

  • Endpoint
  • Model (GPT-4o / GPT-4.1)
  • API Key

Best practice is to store these values ​​in: local.js (local configuration)

Add scripts to the instance

Scripts (calculations)

Used on tasks, they contain prompt logic and main AI API calls

They contain:

  • AI prompts – These functions create prompts — instructions for AI. They can be added to user queries or automated analyses.
  • AI scripts – It is a unified API gateway for all AI tasks. mode parameter determines how the AI ​​should work.

Scripts (CO React) - CaseOverview in React

They show AI chat window in React caseoverview

These scripts are intended only for CaseOverview , not for tasks.

They contain:

  • SendButtonCO – renders the “Send” button
  • AI ChatBox – component for displaying AI conversation history

Scripts (CO) - Dynamic Conditions

They insert a chat window into a task via dynamic conditions

These scripts are used to display the AI ​​window in the task itself , not in the CO.

They contain:

  • SendButtonDP – adds a “Send” button to the task section
  • AI ChatBox – renders a chat window inside a task

Add the necessary variables to the template

Minimum set:

Variable

Description

Variable type

promptField

input for user query

multi-line text

_arrayOfMessages

chat history

text

_arrayOfMessagesEvent

caseoverview chat history (caseoverview chat is displayed by user)

text

_sendButtonHolder

displaying the "Confirm" button to send the prompt to AI

text

responseWindow

chat history

multi-line text

Add AI call to template

Calling AI from caseoverview

  1. Add the "Ask AI about contract" event, map promptField variable to it. This will ensure that pressing the button will trigger the AI ​​query.
  2. Case Overview Editing

Chat window to task (approval tasks)

  1. Add an "AI" section to the task and map variables in the "W" (write) state to it.
    1. responseWindow
    2. promptField
    3. _sendButtonHolder
  2. Add dynamic conditions to the task
 // AI section
//----------------------------------------------------------------------------------------------------------------------------------------------------//
//set height for WYSIWIG editor and adjust the style
setEditorFontSizeAndHeight();

//create chat window
//if (vSync('_arrayOfMessages')) {
createChatBox({
addInfoVar: 'responseWindow',
configMessages: JSON.parse(vSync('_arrayOfMessages'))
})
//}
const onSendButtonFunction = (e) => {
e.preventDefault()


const taskRecalcButton = document.querySelector(`#task-recalc-btn`);
console.log("taskRecalcButton", {
taskRecalcButton
});
taskRecalcButton.click();

};
addSendButton({
message: "Send",
addInfoVar: '_sendButtonHolder',
})

varDefOn('_sendButtonHolder', true, () => {
return {
ivar_name_cs: '',
ivar_name: '',
ivar_name_sk: '',
ivar_name_pl: '',
ivar_name_hr: '',
ivar_name_ro: '',
ivar_name_en: '',
}
})
  1. Add a calculation to a task with an AI call

Add a calculation to the task that will be triggered by an event (button / calculation) and will make the call to Azure AI in chat mode:

 const response = callAzureAI({
mode: 'chat',
enteredText: vars['promptField'].getValue(),
selectedFiles: vars['contractCleanCopy'].getValue(), // smlouva
previousMessagesJson: vars['_arrayOfMessages'].getValue(),
defaultInstructionPrompt: generalContracts(),
config
});

// Uložení aktualizované konverzace
vars['_arrayOfMessages'].setValue(response.messagesJson);

// Reset vstupního pole pro další dotaz
vars['promptField'].setValue('');

// Zobrazení odpovědi v okně pro uživatele
vars['responseWindow'].setValue(response.reply);
Don't forget to map the calculation scripts

Reading the contract (DOCX, PDF) into variables (task "Insert contract copy")

  1. Add a calculation to a task with an AI call
 //** extract contract PDF in to the variables */
// 1) Call unified AI function (RAW mode)
const response = callAzureAI({
mode: 'raw',
enteredText: extractContractFile(),
selectedFiles: vars['contractCleanCopy'].getValue(),
config
});

// 2) Convert markdown → HTML (same as before)
const aiOutput = markdownToHtml(response.reply);

// 3) Clean and parse JSON (same as before)
const cleanedJson = aiOutput.replace(/<br>/g, "").trim();
const outputParsed = JSON.parse(cleanedJson);

// 4) Set variables
vars['contractTitle'].setValue(outputParsed.contractTitle);
vars['contractSubject'].setValue(outputParsed.description);
vars['supplier'].setValue(outputParsed.partyBName);
vars['supplierRepresentativeContact'].setValue(outputParsed.partyBRepresentative);
vars['totalWoVat'].setValue(outputParsed.amount);

// 5) Static defaults
vars['contractCategory'].setValue('financialPerformanceWithPO');
vars['paymentFrequency'].setValue('Monthly');
Don't forget to map the calculation scripts

Contract management summary (task "Technical task - general and approval matrix")

  1. Add a calculation to a task with an AI call
 const response = callAzureAI({
mode: 'raw',
enteredText: managerialContractSummaryPrompt(),
selectedFiles: vars['contractCleanCopy'].getValue(), // array of files
config
});

// The assistant reply = response.reply
vars['aiSummary'].setValue(
markdownToHtml(response.reply)
);
Don't forget to map the calculation scripts

Anna Gernát Updated by Anna Gernát

Contact

Syca (opens in a new tab)

Powered by HelpDocs (opens in a new tab)