This post explores an alternative approach to data management in SAS Viya using a custom LangChain agent. This agent enables users to engage in a conversational interface with SAS Viya, bypassing the need for complex programming. By leveraging the power of large language models (LLMs) and SASPY, the agent offers a variety of data management tasks that include fetching table information, retrieving column details, and manipulating tables. What's more, the agent's built-in memory feature allows for the context-aware handling of user queries and the reusability of responses for subsequent questions. This approach opens the doors to an era of enhanced user interaction and automation in data management tasks, making it a valuable tool for data engineers and analysts alike.
Earlier, I explored employing LangChain with structured data:
I was excited by the possibilities. I was equally disappointed that there was no LangChain agent for SAS Viya.
Therefore, I wrote one. The post explains the result.
Watch the following video. The code executed is a Python program that defines a custom agent for interacting with SAS Viya. It leverages the LangChain Python library, Azure OpenAI, and SASPY to interact with SAS libraries and perform various operations such as fetching table information, getting column information, and appending tables.
The custom agent is primarily designed to interact with a Large Language Model (LLM), specifically, the GPT-4 model deployed on Azure OpenAI. It utilizes a set of custom defined tools to retrieve and manipulate data in SAS libraries. These tools use SASPY to connect to a SAS Viya instance, start a session and execute SAS code. It also features a memory component to remember previous interactions, which aids in maintaining context across a series of questions or commands.
The program consists of several key components:
The agent operates by taking a user question or command, applying the prompt template, and executing the LLM with the relevant tools. The output is parsed and returned to the user. The chat history maintains a record of previous interactions, which allows the agent to refer back to earlier responses, ensuring continuity and context across multiple user inputs.
This approach is critical for creating intelligent, interactive agents that can handle complex tasks and maintain context across multiple interactions. By leveraging LLMs, the agent can understand and respond to a wide range of queries or commands. The use of specific tools enables the agent to interact with SAS libraries, making it a useful tool for data engineers and analysts working with SAS.
This program demonstrates how to create a powerful, interactive custom agent for SAS Viya capable of performing complex tasks and maintaining context across multiple interactions. It showcases the potential of LLMs in creating intelligent agents and the use of SASPY in interacting with SAS Viya. SASPY is just an example. The same approach could be employed with SWAT, SASCTL, or plain SAS Viya REST API.
The implementation of the custom SAS Viya agent in LangChain is successful, demonstrating the potential of using LLMs and specific tools to create intelligent, interactive agents. The next steps could involve expanding the range of tools available to the agent and optimizing the agent's memory component to handle more complex interactions.
Personally, I believe this approach represents an exciting advancement in the field of data management. By using AI and natural language processing to make SAS Viya more accessible to non-technical users, making it easier to use, we're opening up new possibilities for data analysis and manipulation. I'm excited to see where this technology takes us in the future.
In a next post, I will describe in more detail the Python program and the different prerequisites.
Want to understand what it takes to build a custom agent? Read the post How to Create Your Custom LangChain Agent for SAS Viya.
Thanks to @AjmalFarzam for teaching me SASPY in 15 minutes with his Submit workloads to SAS Viya from Python.
Thank you for your time reading this post. If you liked the post, give it a thumbs up! Please comment and tell us what you think about having conversations with your data. If you wish to get more information, please write me an email.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning and boost your career prospects.