Forum Discussion

Janhvi's avatar
Janhvi
Copper Contributor
May 08, 2024

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:
I want to find the intent from the user query and based on that intent further call the respective function/tool to perform respective action. How can I achieve this using Teams AI Library?
I went through the samples mentioned here:
https://github.com/microsoft/teams-ai/blob/main/js/samples/04.ai-apps/
but couldn't find anything similar.

    • Janhvi's avatar
      Janhvi
      Copper 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's avatar
        Vaibhav-MSFT
        Icon for Microsoft rankMicrosoft

        Hello 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`;
        }
        });
        });

         

         

Resources