Skip to content

alexandramartinez/mac-project

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MuleSoft AI Chain (MAC) Project testing

This project demonstrates how to integrate the MAC project's modules and connectors for your Mule projects.

In this Project

Agentforce

Connect to your Agentforce Agent via API.

Einstein AI

Use the Einstein AI trust layer to make use of different models from Einstein.

  • Agent
    • Define Prompt Template
  • Chat
    • Answer Prompt
    • Generate From Messages
  • Embeddings
    • Adhoc File Query
    • Generate From File
    • Generate From Text
  • RAG
    • Adhoc Load Document

Tip

Agent, Chat and RAG make use of LLMs to give an answer in natural language, whereas Embeddings will give numeric responses since no LLM is being used.

Tools - Use AI Service operation is not included in this project.

Prerequisites

  • Salesforce org - Create a new dev account here
  • MuleSoft IDE - Anypoint Studio or Anypoint Code Builder

Salesforce Configuration

1. Salesforce Connected App

Note

Based on these instructions.

  1. Open your Salesforce org and to go Setup.
  2. From setup, use Quick Find to search for App Manager.
  3. Click New Connected App and then select Create a Connected App.
  4. Specify a Connected App Name like mac_project.
  5. Add your contact email. Make sure it's a real email, you'll need it later.
  6. Check Enable OAuth Settings
  7. Callback URL: https://login.salesforce.com
  8. Selected OAuth Scopes. Do NOT select more scopes or you'll get a scope error:
    • Access chatbot services (chatbot_api)
    • Access the Salesforce API Platform (sfap_api)
    • Manage user data via APIs (api)
    • Perform requests at any time (refresh_token, offline_access)
  9. Deselect/select the following settings:
    • Require Proof Key for Code Exchange (PKCE) Extension for Supported Authorization Flows ◻️
    • Require Secret for Web Server Flow ◻️
    • Require Secret for Refresh Token Flow ◻️
    • Enable Client Credentials Flow ✅
    • Enable Authorization Code and Credentials Flow ◻️
    • Enable Token Exchange Flow ◻️
    • Enable Refresh Token Rotation ◻️
    • Issue JSON Web Token (JWT)-based access tokens for named users ✅
    • Introspect All Tokens ◻️
  10. Save the app and click Continue.
  11. Once you're in the Manage Connected Apps page, click Manage.
  12. Click Edit Policies.
    • Permitted Users: All users may self-authorize
    • Enable Single Logout ◻️
    • Run As <select your user, in my case, Alex Martinez>
    • Issue JSON Web Token (JWT)-based access tokens ✅
    • Token Timeout: 30 Minutes
  13. Go back to the connected app and click Manage Consumer Details.
  14. Add your verification code from your email.
  15. Click generate and then apply.
  16. Copy the consumer key/secret from the top. You will use these in MuleSoft.

2. Agentforce Setup

  1. In Setup, go to Einstein Setup and turn on Einstein.
  2. Wait a few seconds and refresh the site. You might not see the following options if you don't refresh.
  3. Look for Agentforce Agents and turn on Agentforce.
  4. Enable the Agentforce default Agent.
  5. In Agentforce Agents, click on New Agent.
  6. Create from a Template > Agentforce Service Agent
  7. Remove all the topics to start from scratch
    • (optional) Add the Off Topic topic with the information from off-topic.md
  8. Add the following details:
    • Name: Agentforce MuleSoft Agent
    • API Name: Agentforce_MuleSoft_Agent
    • Description: Use custom topics and actions to connect to your MuleSoft APIs.
    • Role: An AI customer service agent who connects to MuleSoft APIs for custom functionality.
    • Company: This company is used for demo purposes.
  9. Don't add Data Cloud resources for this example.
  10. Once the agent is created and you have it open, click Connections.
  11. Click on Add to add a new connection.
  12. Select API, add an integration name like MAC Project Integration and select the connected app you previously created (mac_project).
  13. Once you add the connection, make sure to click on Activate at the top-right of the screen.

Important

The Mule API cannot call Agents that are deactivated. Make sure that it's Active in Salesforce. BUT anytime that you need to modify the agent, you have to deactivate it first.

Mule Configuration

Copy the dev-properties.yaml file and create a local-properties.yaml file.

Configure your environment and Salesforce credentials:

  domain: YOUR_SALESFORCE_ORG_DOMAIN
  clientId: YOUR_CONNECTED_APP_CLIENT_ID
  clientSecret: YOUR_CONNECTED_APP_CLIENT_SECRET

Your Client ID / Secret is the same from your Connected App's Consumer Key / Secret.

You can obtain your Salesforce Org's domain from Salesforce Setup > My Domain > Current My Domain URL. For example: orgfarm-6acf46e05z-dev-ed.develop.my.salesforce.com

Running the Project

  1. Import the project into Anypoint Studio or Anypoint Code Builder.
  2. Ensure your local-properties.yaml is correctly configured.
  3. Run the Mule application.

You can find the HTTP requests in requests/. I am using the REST Client extension in VS Code to run these from the text editor, but you can use Postman, cURL, or any other REST Client you prefer.

Troubleshooting

  • Authentication errors: Double-check your Client ID, Client Secret, and Connected App settings.
  • Scope errors: Make sure the scopes in your Connected App are set up correctly. If you add more/less scopes than the mentioned in the settings here, you might get scope errors.
  • Network issues: Ensure your Mule server can reach Salesforce.

References

About

This project demonstrates how to integrate the MAC project's modules and connectors for your Mule projects.

Topics

Resources

Stars

Watchers

Forks