Loading

Agentforce: LWC Intermittently Fails to Load After an Agent Action

Date de publication: Nov 27, 2025
Description

When an Agent Action returns an LWC (Lightning Web Components), the component sometimes displays correctly, and other times the response contains no component output. Instead, the agent replies with text only.

For example:

  • LWC intermittently does not appear after the action runs

  • The agent occasionally asks for additional information even when enough details were already provided

  • The agent may delay executing the action or take multiple reasoning steps

  • The action runs but the final response does not include the expected component

Cause:

This behavior typically occurs when:

  1. The agent is not instructed to always include the component

  2. Required fields are missing or inconsistently extracted, causing the action to return an empty output

  3. Topic instructions are overly long or contain multiple conditional branches

  4. Phrasing is ambiguous, such as “should,” “try,” “if possible,” leading to inconsistent execution

  5. Optional flows run too early, blocking or delaying the component response

Example Scenario

A user requests:

“Create a lead for John Doe at john@test.com.”

Expected behavior:
→ Agent executes the action and returns the LWC lead form.

Intermittent failure:
→ The action runs but produces an empty response, causing no LWC to load.

Why this happens:

  • Required inputs were not fully validated

  • Instructions were long and ambiguous

  • The agent was not explicitly told to always include the component

  • Optional questions were asked before the action finished

 

Résolution

To ensure the LWC always loads consistently, apply the following best practices.

1. Use Clear, Structured, Step-Based Topic Instructions

Use a short, simple sequence to guide the planner.

For Example:

STEP 1 — EXTRACT INFORMATION

  • Extract full name → split into firstName and lastName

  • Extract email if present

  • Extract phone if present

STEP 2 — VALIDATE INPUTS
Run the action only if:

  • firstName is present

  • lastName is present

  • email OR phone is provided

If any required field is missing:

  • Ask only for the missing field

  • Do not re-ask for information already provided

STEP 3 — EXECUTE ACTION
If validation passes, immediately run the action without additional questions.

STEP 4 — DISPLAY THE COMPONENT
After the action runs:

  • ALWAYS include the returned LWC component

  • Respond with: “The record is being created. Let me know if you need anything else!”

  • Do not state that the record is already created

STEP 5 — OPTIONAL FOLLOW-UP
After showing the component, you may ask if the user wants to provide additional details.

2. Update Action Output Instructions to Require Component Display

Add this to any action that returns an LWC.

For Example:

When this action runs, you MUST:

  1. ALWAYS include the returned LWC component in your response.

  2. Say: “The record is being created. Let me know if you need anything else!”

  3. Never state that the record is fully created.

  4. Include the component even if some fields are still being processed.

This ensures the assistant never omits the component, even when the action provides partial information.

3. Validate Inputs Before Execution

Define which fields are mandatory for the action to run.

For Example:

Before executing:

  • firstName must not be empty

  • lastName must not be empty

  • email OR phone must be available

If something is missing, the assistant must ask only for the missing field.

This prevents the action from producing an empty response.

4. Avoid Ambiguous or Overly Complex Instructions

Instructions should not include:

  • Long descriptions

  • Multiple nested conditions

  • References to backend logic

Use precise terms such as:

  • MUST

  • ALWAYS

  • NEVER

  • ONLY IF

This ensures consistent and predictable planner behavior.

5. Place Optional Steps After the Component Has Been Returned

Optional flows should not be placed before the LWC is shown.

Example:

  • First: show the Lead Form component

  • Then: optionally ask if the user wants to provide additional details

This ensures the required component is displayed every time.

Numéro d’article de la base de connaissances

005232509

 
Chargement
Salesforce Help | Article