Search overlay panel for performing site-wide searches

Boost Performance & Scale with Postgres Advanced. Join Pilot Now!

How to Create an AI Agent With Heroku and Agentforce

Heroku is a powerful general-purpose PaaS offering, but when combined with the broader Salesforce portfolio, it excels in unlocking and unifying customer data, regardless of its age, location, size, or structure. Salesforce customers turn to Heroku when they need to leverage high data volumes from sources such as consumer web or mobile apps or when they need scalable compute resources to access and analyze complex data in real time. In this blog, we’ll explore how to create an AI agent with Agentforce, taking advantage of the Heroku platform to transform data from diverse sources to provide comprehensive, real-time information that keeps employees in the flow of work

Supercharge Agentforce with Heroku

What is an AI agent?

An AI agent is an autonomous digital assistant that uses artificial intelligence to understand requests, reason through complex tasks, and take action across connected business systems. Unlike AI chatbots, AI agents can perform multi-step tasks and make decisions using enterprise context. Given access to the right information, they are a powerful new way to automate tasks and give workers low-friction access to your business’s data.

What is Agentforce?

Salesforce recently launched a new AI-driven technology, Agentforce, along with an array of prebuilt agents tailored to each role within Customer 360, from service to sales and various industries. Salesforce Agentforce is a “digital labor” platform that gives businesses the tools they need to build and deploy autonomous AI agents. The platform includes Agent Builder, a low-code environment for defining and testing AI agents; the Atlas Reasoning Engine, which orchestrates AI workloads like data retrieval and solution planning; and AgentExchange, a marketplace of pre-built skills that can extend agentic capabilities.

Agentforce relies on discrete actions described to the AI engine, allowing it to interpret user questions and execute one or more actions (effectively coded functions) to deliver an answer.

However, some use cases require actions that are more customized to a specific business or workflow. In these situations, custom actions can be built using both code and low-code solutions, enabling developers to extend the range of actions available to Agentforce. Developers can use the  Apex programming language or the Flow low-code environment to build actions. If the necessary data resides within Salesforce, and the complexity and computational needs are minimal, both options are worth exploring first. However, if this is not the case, a Heroku custom action written in languages other than Apex can be added to Agentforce agents, as will be demonstrated in this blog post.

Introducing UltraConstruction, an Agentforce user

Let’s take a look at a use case first. UltraConstruction, a 60-year-old company, uses Salesforce Sales and Service Cloud agents to handle customer inquiries. However, their older, unstructured invoices are stored in cloud archives, creating access challenges for their AI agents and leading to delays and customer frustration.

Agentforce chat interface showing a failed invoice query, illustrating data access challenges.

UltraConstruction’s Agentforce builders and developers have discovered that older invoice information is stored in cloud file archives in various unstructured formats, such as Microsoft Word, PDFs, and images. UltraConstruction does not need this information imported, but requires it to be accessible by their AI agents.

archived invoices

UltraConstruction’s developers know that Java has a rich ecosystem of libraries to handle such formats, and that Heroku offers the vertical scalability needed to process and analyze the extracted data in real time. With the additional help of AI, they can make the action more flexible in terms of the queries it can handle—so they get coding! The custom Agentforce action they develop on Heroku accesses information without moving that data, and answers not only the above query but practically any other query that sales or service employees might encounter.

Agentforce AI agent responding to invoice queries with full access to unstructured historical data.

An Agentforce and Heroku integration blueprint

UltraConstruction’s use case can occur regardless of the type, age, location, size, or structure of the data. Even for data already residing in Salesforce, more intensive computational tasks such as analytics, transformations, or ad-hoc queries are possible using Heroku and its array of languages and elastic compute managed services. Before we dive into the UltraConstruction Agentforce action, let’s review the overall approach to using Heroku with Agentforce.

Agentforce and Heroku integration schematic illustrating the data flow between Agentforce, large language models, and Heroku compute services.
* Heroku Integration is currently available only in pilot mode and is not intended for production use. For more information, including alternative steps for deploying in production, please refer to this tutorial.
On the far right of the diagram above, we can see customer data depicted in various shapes, sizes, and locations, all of which can be accessed by Heroku-managed code on behalf of the AI agent. In the top half of the diagram, Agentforce manages which actions to use. Heroku-powered actions are exposed via External Services and later imported as an Agent Action via Agent Builder.

In the bottom half of the diagram, since External Services are used, the only requirement for the Heroku app is to support the OpenAPI standard to describe the app’s API inputs and outputs, specifically the request and response of the action. Finally, keep in mind that Heroku applications can call out to other services, leverage Heroku add-ons, and utilize many industry programming languages with libraries that significantly speed up the development process.

A sample Agentforce Heroku action

Now that you know the use case and the general approach, let’s look at an example AI agent. In the following video and GitHub repository README file, you will be able to try this out for yourself! The action has been built to simulate the scenario that UltraConstruction found themselves in, with some aspects simplified to make the sample easier to understand and deploy. The following diagram highlights how the above blueprint was taken and expanded upon to build the required action.

Agentforce and Heroku integration diagram showing data access process for archived invoices using Heroku Compute Services and OpenAPI.
* Heroku Integration is currently available only in pilot mode and is not intended for production use. For more information, including alternative steps for deploying in production, please refer to this tutorial.
The primary changes to note are:

  • Java, along with Spring Boot
    The Spring framework offers a wide range of tools that make managing data, security, and calling AI LLMs (Large Language Models) very simple with minimal code. It supports both web and API-based applications.
  • H2 is a highly optimized in-memory database
    Stores data from processed invoice documents in a relational form, ready for querying.
  • springdoc.org is used to generate an OpenAPI schema
    Java is a strongly typed language, making it an excellent choice for building and defining APIs. This library requires minimal configuration for compliant OpenAPI APIs, which are required by External Services.
  • Spring AI has been used to simplify access to industry LLMs
    Spring AI is easy to configure and often requires minimal coding—sometimes just one line of code—to tap into powerful LLMs, such as those provided by OpenAI and others. In this case, it is responsible for taking the natural language query entered into the Agentforce agent and converting it into SQL, which is run against the H2 database. The result of this query is then returned to Agentforce and integrated into a natural language response for the user.

If you’re interested in viewing the code and a demonstration, you can watch the video below. When you’re ready to deploy the example AI agent yourself, review the deployment steps in the README.

Conclusion

Code is a powerful tool for integration, but keep in mind that Heroku also provides out-of-the-box integrations that bring Salesforce data closer to your application through Heroku Postgres and our Heroku Connect product. We also support integrations with Data Cloud. Heroku also offers pgvector as an extension to its managed Postgres offering, providing a world class vector database to support your retrieval augmented generation and semantic search needs. You can see it in action here. While this blog’s customer scenario didn’t require these capabilities, other agent use cases may well benefit from these features, further boosting your agent actions! Last but not least, we at Heroku consider feedback a gift, so if you have broader ideas or feedback, please connect with us via the Heroku GitHub roadmap.

Updates

Since publishing this blog, we have released additional content we wanted to share.

  • Introduction to the Heroku Integration Pilot for Developers. This video helps developers discover our new Heroku Integration feature, which brings Heroku applications directly into Salesforce orgs to extend Apex, Flow, Agentforce, and many other experiences with Heroku’s elastic compute services. It also provides a new SDK experience for developers to access Salesforce data. This feature is currently in pilot and isn’t generally available at this time; developers can request access through the signup forms included in the video description.
  • This step by step tutorial, available in Java and Python, will guide you through configuring an Agentforce Action deployed on Heroku within your Salesforce org. By the end, you will be able to ask Agentforce to generate your own badge, as shown below!
    Heroku Agentforce Tutorial
  • An additional demonstration video and sample code, diving deeper into how Heroku enhances Agentforce agents’ capabilities. In this expanded version of the popular Coral Cloud Resort demo, vacationing guests can use Agentforce to browse and book unique experiences. With Heroku, the agent can even generate personalized adventure collages for each guest, showcasing how custom code on Heroku enables dynamic digital media creation directly within the Agentforce platform.
    Coral Cloud Resorts

Ready to Get Started?

Stay focused on building great data-driven applications and let Heroku tackle the rest.

Sign Up Now  Talk to A Heroku Rep