The teams-ai API matches Semantic Kernel prompt options.
Below is a diagram of the Teams-AI flow. Teams AI SDK hooks into the Teams SDK and Azure OpenAI SDK to provide a seamless experience for developers.
Bot memory and AI memory are separate. Bot memory stores data for the bot to use, while AI memory stores AI data.
$conversation.<prop>
- bot conversation memory$user.<prop>
- bot user memory$temp.<prop>
- bot temp memory (data kept for 1 turn only)$<prop>
may be used as an alias for$temp.<prop>
AI bot memory may store context/information for as little as 1 turn, while bot memory may be used to store information for the lifetime of the conversation.
Unlike bot memory, AI memory consumes tokens and therefore is more expensive, but keeping a shorter
$history
may cause more frequent hallucinations from the AI.
$history
- conversation history tracked by AI (not related to bot's conversation history see Bot memory)$input
- input from the prompt, such asactivity.text
$output
- the last executed function's output. You reference this output in code asstate.temp.value.output
- Hallucinatiion - when the AI creates an independant context/response that does not match the app's use-cases.
- Parent prompt: when executing chaining, the output from the child prompt may be directly passed to the parent prompt:
app.ai.prompts.addFunction("getUserName", async (context, state) => {
return context.activity.from.name;
});
In your prompt(s) text file, reference the above function as {{getUserName}}
app.ai.prompts.addFunction("translateInputToEnglish", app.ai.createSemanticFunction("translationPrompt"));
The child prompt passes its $output
to the parent (translationPrompt
)
const result = await app.ai.completePrompt(context, state, "myPrompt");
If, for example, a user wants to reset the conversation, a command like 'reset' may be created. However, there are any number of ways the user might call reset, as well as ways that the developer does not want to consider valid. The following is a fairly comprehensive RegExp that can cover many scenarios.
RegExp: ` For details and coverage on this regex, visit this regex101 link which covers and tests 'reset' and 'restart' inputs from the user.
const resetRegex = `/^(?:.*\s)?\/(reset|restart)|^(reset|restart)\(?\)?$/i`;
app.message(resetRegex, async (context, state) => {
state.conversation.delete();
await context.sendActivity(`Ok I have deleted the conversation history.`);
});
You may replace reset|restart
with whatever word(s) desired, of course. Usage of regex is not required, but may be helpful in covering many scenarios that result in the same action.