Developers are constantly looking for new ways to increase productivity. Generative AI is a tool that is profoundly changing the way code is written and optimized, and it provides the foundation to generate code suggestions using natural language instructions.
We recently announced the general availability of Anypoint Code Builder for Desktop, an IDE built on Visual Studio Code that can be used to visually design, build, test, and deploy enterprise integrations. Given that MuleSoft developers have the challenging task of designing, building and deploying integrations we set ourselves a goal of rolling out new AI-based developer tooling.
We will explore a new AI feature that will be piloting within Anypoint Code Builder called Generative Flows. Generative Flows leverage the generative power of Einstein for Anypoint Code Builder to help MuleSoft developers be more productive.
What are Generative Flows?
Einstein for Anypoint Code Builder increases productivity and provides helpful assistance for complex integration tasks. Generative Flows make it easy to create a draft integration simply by describing the business logic. With boilerplate integration code generation as its foundation it also makes it easier for new developers to get acquainted with Anypoint Code Builder.
How do Generative Flows work?
We utilize Open AI’s GPT models and have added several layers to tailor the responses to the Mule domain-specific language. This includes leveraging Mule proprietary data for prompt engineering and adding validation to the outputs before they are surfaced in Anypoint Code Builder.
By using this internal data in tandem with various machine learning techniques, the MuleSoft engineering team improved the quality of responses beyond what is generated by hitting these models directly. As a result we are able to generate valid flows for MuleSoft pre-bundled connectors (Salesforce, Database, HTTP, Email) with high accuracy. Even more, our AI trust layer within Einstein ensures that data exchanged with Open AI is never stored at rest and is not used to train models keeping your enterprise data and code private to your organization.
Draft an integration using natural language
Einstein for Anypoint Code Builder is front and center as soon as you develop an integration. Instead of starting your integration from scratch you now have the ability to describe your end-to-end business logic.
When a developer selects Start with AI, a new panel opens that allows them to use natural language to describe the integration. The dialog has two examples of the types of integrations developers can create.
For example, let’s ask Einstein to create an integration that helps us connect Salesforce with a Postgres database. Suppose we have the following challenge to solve for: Create an API that can take a variable corresponding to opportunity amount then use that information to query for Salesforce opportunities in Sales Cloud. If the opportunity amount exceeds $100,000, the opportunity information should be replicated to a Postgres database. If the amount is less, create a CSV file.
Let’s see what happens when we take this requirement into Einstein using natural language. In our prompt we’ll specify values that help with column names, table names, and key fields we need.
“create a flow that creates an api endpoint that takes an amount as a query parameter then queries for Salesforce opportunities that have a status of closed won. If the Amount in the query parameter is greater than $100,000, then insert into a postgres database table called bigwins. If the amount is less then create a csv file”
Here we’ve written a well grounded prompt with enough context and data for Einstein to be able to provide a useful and accurate response.
Here, Einstein has produced a suggested integration flow. It not only gives the required XML, but also describes the output in natural language allowing the developer to quickly check for accuracy. The key to an accurate and useful response was the data we supplied in our prompt. Let’s break down the prompt to see how it can help provide a response that saves development effort.
“create a flow that creates an api endpoint that takes an amount as a query parameter..”
- The flow starts with an HTTP listener that listens for GET requests on the “/opportunity” path.
- The “amount” query parameter is extracted and stored in a variable using the component.
“..then queries for Salesforce opportunities that have a status of closed won..”
- The salesforce:query component is used to query Salesforce opportunities with a status of “Closed Won”.
- Einstein has suggested a SOQL query to extract the values needed (SELECT Id, Name, Amount, StageName FROM Opportunity WHERE StageName = ‘Closed Won’)
“..If the Amount in the query parameter is greater than $100,000, then insert into a postgres database table called bigwins..”
- The Choice router is used to check the value of the “amount” variable set in the query parameter
- If the amount is greater than $100,000, a db:insert component is used to insert the opportunity details into a PostgreSQL database table called “bigwins”.
- Einstein has drafted a SQL insert statement (INSERT INTO bigwins (opportunity_id, opportunity_name, amount) VALUES (#[payload.Id], #[payload.Name], #[payload.Amount]))
“..If the amount is less, then create a csv file.”
- If the amount is less than or equal to $100,000, an ee:transform component is used to transform the payload into CSV format. Einstein has drafted the DataWeave needed (%dw 2.0 output application/csv — payload)
- Then a file:write component is used to save the CSV file with the name “output.csv”. Since we didn’t specify the filename Einstein has suggested one.
Putting the generated integration into action
As soon as the Einstein prompt has provided a draft output, a developer can use the suggested integration by inserting it into their active project using a simple button click. The graphical editor shows the output of the XML visually.
In fewer than 60 seconds, we’ve completed the following tasks that would have otherwise been manual:
- Included dependencies needed for Salesforce, HTTP and Database connectors
- Created an HTTP listener and associated query parameter
- Drafted a SOQL query using the Salesforce connector to retrieve closed won opportunities from Salesforce
- Included a choice router to branch logic based on opportunity amount
- Included a Database insert statement when opportunity amount > $100,000
- Created DataWeave to convert opportunities < $100,000 to a CSV file
This allows developers to spend more time on more complex tasks, testing, and error handling.
Generative AI: changing code as we know it
Generative AI is one tool that is profoundly changing the way code is written and optimized and provides the foundation to generate code suggestions using natural language instructions. Generative Flows, powered by Einstein for Anypoint Code Builder, enable developers to build integrations faster than before.
Generative Flows can download dependencies, draft DataWeave scripts, create SQL statements, and include flow control operations, which allows integration developers to build a minimal viable integration faster, freeing up their time for more complex tasks. Want to learn more? To participate in the pilot for Generative Flows, reach out to your account team or customer support manager. And don’t forget to discover how to get started with Anypoint Code Builder.