Personalizing Salesforce Agentforce Responses with User & Contact Profile Context

Personalizing Salesforce Agentforce Responses with User & Contact Profile Context

This Blog Post is Technical Guide reference for Developers & Architects. You can discover how to configure and leverage Agentforce User Profile Information in Salesforce to automate contextual personalization across User and Contact records. Use this Blog Post as reference for mastering Agentforce User Profile Context.

Salesforce Agentforce: How to Leverage Agent User Profile Information for Personalized AI Interactions

In conversational AI, eliminating friction is key to delivering seamless user experiences. Forcing users to state their name, email, time zone, or location during an ongoing interaction leads to unnecessary back-and-forth and reduced user engagement.

Salesforce Agentforce Agent User Profile Information solves this problem by automatically capturing critical user metadata and injecting it directly into the agent’s execution context. This allows developers, admins, and architects to build highly personalized, context-aware AI interactions without requiring manual data entry from the end user.

What is Agentforce User Profile Information?

Agentforce User Profile Information provides ambient contextual data about the interacting entity. When an interaction starts, the Agentforce execution runtime automatically pulls pre-existing attributes—such as identity, geographic locale, and regional settings—into the session context.

This user profile context enables your agents to:

  • Tailor language, greetings, and formatting to the user’s localized time zone and language settings.
  • Identify the user’s corporate or contact details dynamically.
  • Pass identity parameters to backend logic and prompt execution flows.

User Profile Context Availability: Employee vs. Service Agents

The specific profile attributes available to Agentforce depend on two key factors: the agent type (Employee vs. Service) and the underlying Salesforce record type associated with the session.

Agent TypeAssociated RecordAvailable User Profile Context Fields
Employee AgentsUser RecordName, Email, Company, Locale, Time Zone
Service AgentsUser RecordName, Email, Company, Locale, Time Zone
Service AgentsContact RecordName, Email, Country

Key Nuances

  • Employee Agents: Always bind to an active Salesforce User record, providing full corporate identity context including company and time zone.
  • Service Agents: Can bind to either a User record (for internal portal users or authenticated community members) or a Contact record (for external customers). When bound to a Contactrecord, the context shifts to customer-facing details (Country replaces Company and Locale/Time Zone).

How to Apply User Profile Fields Across Agentforce

Once user profile information is accessible within the agent runtime, you can leverage it across multiple functional layers:

  1. Agent Instructions: Refer directly to profile fields inside core instructions to dictate tone, greeting styles, or regional phrasing without asking the user for their information.
  2. Prompt Templates: Inject user profile fields into grounding prompts to customize LLM outputs based on user identity or regional context.
  3. Agent Script: Reference profile fields directly as context variables to evaluate conditional branching, route tasks, or dictate logical workflows.

Configuration Code Snippet

To activate user profile context within your agent’s context declaration, enable the user_profile block as shown below:

context:
    user_profile:
        enabled: True

Best Practices & Key Recommendations

When enabling and configuring the user_profile context in Agentforce, consider the following technical and architectural guidelines:

  • Explicit Schema Validation: Always verify whether your target session runtime binds to a Useror a Contact record before referencing context variables. Referencing a User-only field (e.g., time_zone or company) during a Contact-bound Service Agent interaction will evaluate to null.
  • Fallback Logic in Agent Scripts: When referencing profile variables in conditional logic, implement fallback branches to handle scenarios where optional profile fields (such as countryon a Contact record) are blank.
  • Instruction Grounding: Explicitly instruct the agent in system prompts on how to use locale and time zone attributes (e.g., “Format all dates and times according to the user’s localized time zone context”).
  • Minimalist YAML Configuration: Maintain clean configuration files by explicitly specifying enabled: True under user_profile within the top-level context key block to ensure profile runtime data is loaded at session initialization.

Sample Agent Script Code for Reference

system:
    instructions: |
        You are an AI Agent.
    messages:
        welcome: |
            Hi, I'm Agentforce! I use AI to search trusted sources, and more. Ask me "What else can you do?" to see how I can simplify your workday. How can I help?
        error: "Something went wrong. Try again."

config:
    agent_label: "Agentforce Employee Agent"
    agent_template: "EmployeeCopilot__AgentforceEmployeeAgent"
    developer_name: "Agentforce_Employee_Agent"
    agent_type: "AgentforceEmployeeAgent"
    description: "Automate common business tasks and assist users in their flow of work. Agentforce Employee Agent can search knowledge articles and other data sources. Customize it further to meet your employees' business needs."

context:
    user_profile:
        enabled: True

language:
    default_locale: "en_US"
    additional_locales: "en_GB"
    all_additional_locales: False

variables:
    emailAddress: mutable string
        description: "Email Address to search Cases"
        visibility: "External"

start_agent agent_router:
    label: "Agent Router"
    description: "Welcome the user and determine the appropriate subagent based on user input"
    reasoning:
        instructions: ->
            | Select the best tool to call based on conversation history and user's intent.
        actions:
            go_to_Case_Management: @utils.transition to @subagent.Case_Management

subagent Case_Management:
    label: "Case Management"
    description: |
        Manage Support Cases
    reasoning:
        instructions: ->
            if @variables.emailAddress is None:
                | The user's email address is available in the user_profile context. 
                | Extract the email value from user_profile and call {!@actions.setEmailAddress} to store it. 
                | Do not ask the user for their email address. 
                
            | Run {!@actions.Fetch_Cases_by_Email} to get the Cases related to the Email.
            | Run {!@actions.Fetch_Cases_by_Email} to update the case with the Comments shared.
        actions:
            setEmailAddress: @utils.setVariables
                with emailAddress = ...
                description: "Set the email address variable"
            Fetch_Cases_by_Email: @actions.Fetch_Cases_by_Email
                with caseEmail = @variables.emailAddress
                available when @variables.emailAddress is not None
            Update_Case: @actions.Update_Case
                with caseId = ...
                with caseComment = ...

    actions:
        Fetch_Cases_by_Email:
            label: "Fetch Cases by Email"
            description: |                  
                Fetch Cases by Email
            target: "flow://AF_Fetch_Cases_by_Email"
            inputs:
                caseEmail: string
                    label: "caseEmail"
                    description: "Stores the Case Email Address"
                    is_required: False
            outputs:
                listCases: list[object]
                    label: "listCases"
                    description: "Stores the Cases related to the Email Address"
                    complex_data_type_name: "lightning__recordInfoType"
                    is_displayable: False
                    filter_from_agent: False
                message: string
                    label: "message"
                    description: "Stores the Success or Error Message"
                    is_displayable: False
                    filter_from_agent: False
                success: boolean
                    label: "success"
                    description: "Stores whether the execution succeeded or not"
                    is_displayable: False
                    filter_from_agent: False
        Update_Case:
            label: "Update Case"
            description: |
                Update Case
            target: "flow://AF_Update_Case"
            inputs:
                caseComment: string
                    label: "caseComment"
                    description: "Stores the Case Comments"
                    is_required: False
                caseId: string
                    label: "caseId"
                    description: "Stores Case record ID"
                    is_required: False
            outputs:
                caseRecord: object
                    label: "caseRecord"
                    description: "Stores the Case record"
                    complex_data_type_name: "lightning__recordInfoType"
                    is_displayable: False
                    filter_from_agent: False
                message: string
                    label: "message"
                    description: "Stores the Success or Error Message for Case Update operation"
                    is_displayable: False
                    filter_from_agent: False
                success: boolean
                    label: "success"
                    description: "Stores whether the Case update succeeded or not"
                    is_displayable: False
                    filter_from_agent: False

Leave a Reply