- favorite - sdk:swml - product:ai - product:voice # Using set_meta_data In this example, we demonstrate how to use set_meta_data to store information to reference later. The AI agent, will store a users name and then look up any additional stored information. The benefit of storing information in meta_data is that the information it can be referenced from any function with the same meta_data_token, while also never being exposing the information to the language model. This allows for the AI agent to store sensitive information without the risk of it being exposed to the AI agent. ## **1. Storing User Information** The store_user function is used to store the users name. The users name and a secret associated with them are stored as meta_data. yaml andJson - function: store_user purpose: Store the user information argument: type: object properties: name: type: string data_map: webhooks: - url: https://example.com/name_bank?name=%{lc:args.name} method: GET output: response: The user information was stored. User information can now be looked up with the get_user_info function. action: - set_meta_data: %{lc:input.args.name}: %{Records[0].secret} - toggle_functions: - active: true function: get_user_info - say: Your info was stored. meta_data_token: example_token This will send a request to data_map.webhooks.url with the users name as a query parameter. In this example, we have our server responding with a Records array in the response. This will contain information on the user. **Server Response**: json { response: The user information was stored., Records: [{ secret: [Info about user here] }] } Once the response has returned from the webhook, the meta_data will be set using set_meta_data in the data_map.webhooks.output.action of the function, the get_user_info function will be toggled on using toggle_functions, and the user will be notified that their information was stored. The meta_data key is set to the users name and the value is set to the first value in the Records array. yaml andJson - set_meta_data: %{lc:input.args.name}: %{Records[0].secret} ## **2. Looking up User Information** After storing the user information in meta_data, we can now look up the user information with the get_user_info function. yaml andJson - function: get_user_info purpose: lookup user information argument: type: object properties: name: type: string data_map: expressions: - string: %{lc:args.name} pattern: /\\w+/i output: response: The meta_data is valid. action: - say: Your info is %{meta_data.%{lc:args.name}} - stop: true - string: .* pattern: .* output: response: The meta_data is invalid. User has not been told their information. active: false meta_data_token: example_token This function will check if the meta_data is valid by checking if the users name is a key in the meta_data object. If the meta_data is valid, the user will be told their information. If the meta_data is invalid, the user will be told that their information has not been stored. ## **Full Example** yaml andJson sections: main: - ai: prompt: text: >- Your name is Mr. Blabbermouth. You help the user. ## Handling The User - You are asked to store a users information. - You ask for their name. - You use the store_user function to store the users name. ### Looking up user information - You can only look up a users information after storing it. post_prompt: text: Summarize the call in JSON format. temperature: 0.1 top_p: 0.1 post_prompt_url: https://example.com/post_prompt_url params: swaig_allow_swml: true SWAIG: functions: - function: store_user purpose: Store the user information argument: type: object properties: name: type: string data_map: webhooks: - url: https://example/name_bank?name=%{lc:args.name} method: GET output: response: The user information was stored. User information can now be looked up with the get_user_info function. action: - set_meta_data: %{lc:input.args.name}: %{Records[0].secret} - toggle_functions: - active: true function: get_user_info - say: Your info was stored. meta_data_token: example_token - function: get_user_info purpose: lookup user information argument: type: object properties: name: type: string data_map: expressions: - string: %{lc:args.name} pattern: /\w+/i output: response: The meta_data is valid. User has already been told their information. Do no repeat it. action: - say: Your info is %{meta_data.%{lc:args.name}} - stop: true - string: /.*/ pattern: /.*/ output: response: The meta_data is invalid. User has not been told their information. active: false meta_data_token: example_token