How to Call an AI Agent from Salesforce Flow? (Step-by-Step)
Healthcare providers struggle to give immediate medical advice outside office hours. This Salesforce Flow + AI Agent integration delivers automated treatment suggestions to patients while they wait for appointments. Learn how to combine these powerful tools with proper response formatting.
Healthcare Use Case
Imagine a patient books a doctor's appointment for tomorrow but needs immediate medical advice tonight. Without AI automation, they'd either wait anxiously or seek unreliable online sources. This Salesforce solution provides trustworthy interim guidance automatically.
Our hospital use case involves patients booking appointments through Salesforce. When they select a date and time, the system captures their diagnosis. If the diagnosis field contains data (like "fever"), the flow triggers an AI Agent to generate appropriate treatment suggestions.
Key benefit: Patients receive vetted medical advice within minutes of booking, improving care quality and reducing unnecessary emergency visits. The AI Agent provides suggestions aligned with the practice's medical standards.
Flow Structure Overview
The record-triggered flow activates when a new Visit record is created with a diagnosis. It has two critical paths that work together:
- Immediate path: Checks if diagnosis exists and gathers initial patient data
- Asynchronous path: Handles the AI Agent call and response processing
This separation is crucial because AI Agent responses aren't instantaneous. The immediate path ensures quick record creation, while the asynchronous path manages the slower AI processing behind the scenes.
Asynchronous Response Handling
AI Agents in Salesforce behave like API calls - they need time to generate responses. Trying to call them synchronously would create timeout errors and poor user experiences.
The asynchronous path solves this by:
- Queuing the AI Agent call to run after the initial record save
- Allowing sufficient time for the AI to process the request
- Updating the record later with the generated suggestions
Pro tip: Always test your asynchronous flows with realistic wait times. AI responses in healthcare should typically appear within 2-5 minutes to maintain patient trust.
Creating the Agent Input
The agent input combines structured data with natural language instructions. For our healthcare example, it includes:
- Patient diagnosis ("fever")
- Contact information
- Clear request for treatment suggestions
A well-structured input might say: "Please provide treatment details for a patient diagnosed with fever. Their email is [email protected] and appointment is tomorrow." This gives the AI Agent both medical context and communication parameters.
Response Processing Challenge
Initial testing revealed a critical issue - raw AI Agent responses come in JSON format. While perfect for systems integration, JSON is terrible for patient communication.
Our first implementation displayed unformatted JSON containing medical advice. Patients saw technical syntax instead of clear instructions. This created confusion rather than providing helpful guidance.
Lesson learned: Never expose raw AI output to end users. Always transform technical responses into human-readable formats appropriate for your audience.
Using Prompt Templates
The solution involves prompt templates that:
- Extract the message content from JSON responses
- Reformat it into clear paragraphs
- Remove all technical syntax
The template instructs Salesforce to "take the message from the agent response and present it in readable paragraph format." This transforms dense AI output into patient-friendly medical advice.
Testing the Flow
After implementing prompt templates, we retested the solution:
- Created a new Visit record with diagnosis "fever"
- Saved the record (triggering the flow)
- Refreshed after 2 minutes
The results were transformative. Instead of JSON, patients now see properly formatted paragraphs with clear medical advice like: "For fever, we recommend rest, hydration, and over-the-counter fever reducers. Contact us immediately if symptoms worsen."
Watch the Full Tutorial
See this integration in action at the 2:30 mark where we demonstrate the JSON-to-paragraph transformation. The video walks through each configuration step with real-time results.
Key Takeaways
This Salesforce Flow + AI Agent pattern delivers immediate value in healthcare and beyond. By combining automation with AI intelligence, you can provide sophisticated responses without manual intervention.
In summary: Use asynchronous flows for AI calls, structure clear agent inputs, and always transform technical responses into user-friendly formats with prompt templates.
Frequently Asked Questions
Common questions about this topic
Calling AI Agents from Flows allows you to combine the decision-making power of AI with Salesforce automation. This is particularly useful for scenarios like healthcare where you need to provide immediate automated responses while waiting for human intervention.
For example, giving patients preliminary medical advice before their appointment creates better patient experiences and reduces unnecessary emergency visits. The AI handles routine cases while flagging urgent matters for human review.
- Combines structured business logic with AI intelligence
- Provides instant responses during off-hours
- Scales personalized communication
Immediate paths execute right away while asynchronous paths run later. Since AI Agent responses take time to generate, they must be handled asynchronously to prevent system timeouts and poor user experiences.
In our healthcare example, the immediate path quickly saves the visit record and checks for a diagnosis. The asynchronous path then handles the slower AI processing and updates the record with suggestions a few minutes later.
- Immediate path: Fast initial record processing
- Asynchronous path: Slower AI response handling
- Combined: Smooth end-to-end experience
AI Agents typically return responses in JSON format which isn't user-friendly. Raw technical output creates confusion rather than providing value to end users like patients or customers.
Prompt templates solve this by extracting the meaningful content and reformatting it appropriately. In our healthcare example, this transforms technical AI output into clear medical advice paragraphs that patients can easily understand and follow.
- Removes technical syntax
- Formats for readability
- Maintains brand voice
Absolutely. This integration pattern works for any scenario needing AI-powered automation in Salesforce. The combination of structured flows with AI intelligence has nearly limitless applications across industries.
Common use cases include personalized customer service responses, product recommendations based on purchase history, or financial advice tailored to individual circumstances. Anywhere you need to combine business rules with adaptive intelligence benefits from this approach.
- Customer service automation
- Personalized recommendations
- Financial guidance
Include all contextual information the AI needs to generate a relevant response. The more specific your input, the more accurate and helpful the output will be for your users.
For healthcare, this means diagnosis details and patient contact info. For other use cases, include relevant record data and clear instructions about what response you want the AI to generate. Well-structured inputs lead to high-quality outputs.
- Relevant record data
- Clear instructions
- Contact/identification info
Response times vary based on complexity but typically take a few seconds. More sophisticated requests or those requiring external data lookups may take slightly longer.
The asynchronous flow design ensures this delay doesn't impact user experience. In our healthcare example, patients see the suggestions appear shortly after record creation - usually within 2-5 minutes depending on system load.
- Simple requests: 2-10 seconds
- Complex requests: 30-60 seconds
- End-user experience: 2-5 minute delay
Yes, through careful prompt engineering and template design. You have full control over how responses appear to end users, allowing you to match your organization's communication style.
You can specify response length, tone, and structure in your agent configuration. The prompt template then ensures final output matches your exact requirements for end-user presentation, whether that's brief bullet points or detailed paragraphs.
- Control length and detail
- Set appropriate tone
- Match brand guidelines
GrowwStacks specializes in Salesforce AI integrations and automation workflows. Our certified experts design, build and deploy custom AI Agent solutions tailored to your specific business needs and use cases.
We offer free 30-minute consultations to discuss your automation goals and demonstrate how AI Agents can transform your operations. Whether you need healthcare solutions like this example or completely different applications, we can help you implement them efficiently.
- Custom AI Agent development
- Salesforce Flow integration
- Free initial consultation
Automate AI-Powered Responses in Your Salesforce Org
Manual responses create delays and inconsistencies. Let GrowwStacks build custom AI Agent flows that deliver instant, accurate responses tailored to your business processes.