Forum Discussion
Janhvi
May 08, 2024Copper Contributor
Tools in Teams AI Library
Hello Team, In LLM we use tools like DynamicTool, DynamicStructuredTool to determine when to call which function and with what parameters. How to do the same using Teams AI Library? My Use Case...
Janhvi
May 10, 2024Copper Contributor
Following the below example, I have replicated tools using actions :
https://github.com/microsoft/teams-ai/blob/main/js/samples/03.ai-concepts/c.actionMapping-lightBot/src/prompts/sequence/actions.json
Now if I want to create hierarchy of this action i.e under one action I want to create a set of other actions. How can we do that?
Use Case: Once it has understood the intent to execute the following action, now I want sub actions to be performed for that particular intent.
For example : Intents are creation, modification, deletion etc
Now when it understood the intent as modification, I further want this action to have sub actions say
1) Time (when was it modified)
2) User Event (who modified it)
3) Modified since (what are the modifications since yesterday) and so on
And these sub actions based on the data source provided so how to add data source as well.
How to achieve this?
Vaibhav-MSFT
Microsoft
May 10, 2024Hello Janhvi,
Can you please try to register subhandlers for actions using the Teams AI Library.
import { Application, ApplicationTurnState, PauseParameters } from 'your-teams-ai-library'; // Import necessary types from the Teams AI Library
// Define the JSON data for actions and subactions
const actionsAndSubactions = [
{
"name": "Pause",
"description": "Delays for a period of time",
"subactions": [
{
"name": "Resume",
"description": "Resumes after pause"
},
{
"name": "Stop",
"description": "Stops the pause"
}
]
}
// Add more actions and subactions as needed
];
// Define the subaction handlers
const subactionHandlers: { [name: string]: (context: any, state: ApplicationTurnState, parameters: any) => Promise<string> } = {
async Resume(context: any, state: ApplicationTurnState, parameters: any) {
// Implement logic for handling the Resume subaction
return "Resume logic executed";
},
async Stop(context: any, state: ApplicationTurnState, parameters: any) {
// Implement logic for handling the Stop subaction
return "Stop logic executed";
}
// Add more subaction handlers as needed
};
// Initialize the application
const app = new Application<ApplicationTurnState>({
storage,
ai: {
planner
}
});
// Register action handlers
actionsAndSubactions.forEach(action => {
app.ai.action(action.name, async (context: any, state: ApplicationTurnState, parameters: PauseParameters) => {
const subactionName = context.activity.value?.subaction;
if (subactionName && subactionHandlers[subactionName]) {
return subactionHandlers[subactionName](context, state, parameters);
} else {
await context.sendActivity(`[pausing for ${parameters.time / 1000} seconds]`);
await new Promise((resolve) => setTimeout(resolve, parameters.time));
return `done pausing`;
}
});
});
- JanhviMay 14, 2024Copper ContributorHello Vaibhav-MSFT
The code line
const subactionName = context.activity.value?.subaction;
that you mentioned in the above code, doesn't work as context.activity.value is undefined
I checked it with the latest version as well.
Also where will I find the above reference code?- Vaibhav-MSFTMay 15, 2024
Microsoft
Hi Janhvi,
The context.activity.value "undefined" indicates that activity received by the bot does not contain a value property.
Can you add a check before for handling this-
// Check if context.activity.value exists and has a subaction propertyif (context.activity.value && context.activity.value.subaction)
{
subactionName = context.activity.value.subaction;
}- JanhviMay 15, 2024Copper ContributorHello Vaibhav-MSFT
context.activity.value does not exist.
Hence it will never be able to perform the function provided for any subaction
- JanhviMay 14, 2024Copper Contributor
Thank you so much Vaibhav-MSFT !
Apart from the below two links, where do I find references or document for all of this?
https://learn.microsoft.com/en-us/microsoftteams/platform/bots/how-to/teams%20conversational%20ai/teams-conversation-ai-overview
https://github.com/microsoft/teams-ai/tree/main/js/samples/
Are there any more documentation links?
Also if I want the actions to be performed on some data that I provide, how to achieve that?