Skip to main content

From a Flow

How to call an agent from a Salesforce Flow with the Invoke Agent (Daemon) action.

Overview​

The Agent Platform's Salesforce package adds a Flow action that makes a Daemon call for you, with no code. The agent receives a message, reasons over it with its deployed version, and the Flow gets its answer back.

Everything about the call itself, meaning the stateless and stateful modes, which memory it uses, partial replies and how long it can take, is the same as over HTTP and is covered on the Daemon page. This page covers the action's inputs and outputs and what is particular to calling from a Flow.

Note: A Salesforce Flow stops waiting after 120 seconds, which is as long as Salesforce lets any callout wait, while an agent's turn can run to 240 seconds by default. Keep work called from a Flow well inside two minutes. See When a Flow call fails.


Adding the action​

In Flow Builder, add an Action element and search for:

Invoke Agent (Daemon)

It appears under the Flourish Agent Platform category.

Inputs​

InputRequiredDescription
Agent External Id✅The Agent ID of the agent to invoke. Copy it with the Copy Agent ID button in the Agent Builder.
Message✅The message to send to the agent: the equivalent of what a user would type in chat.
Stateful-Set to true to start or continue a persistent conversation. Defaults to false.
Conversation Id-Required when resuming a stateful conversation. Pass the Conversation ID returned by a previous Daemon call. Leave blank to start a new conversation.
Host Context JSON-An optional JSON string of additional context passed to the agent at runtime. See Host Context in a Flow.
Group Key-Names which memory the agent uses for this call. See Choosing which memory to use. Agents set to No memory ignore it.
Idempotency Key-Stops a duplicate call starting a second turn while the first is still running. See Group Key and Idempotency Key.
Additional Instructions-Extra instructions for this one call, applied on top of the agent's profile. Use it for something specific to this Flow that does not belong in the agent itself, such as an output format.

The inputs map onto the HTTP request's fields, which is worth knowing if you move an automation from Flow to code:

Flow inputJSON field
Agent External Idin the URL, as {agent_id}
Messagemessage
Statefulstateful
Conversation Idconversation_id
Host Context JSONhost_context
Group Keygroup_key
Additional Instructionsadditional_instructions
Idempotency Keythe Idempotency-Key header

The HTTP call's other options are not in the action, such as calling as a person or as your system. A Flow call always acts as your organization and sends an ordinary message.

Outputs​

OutputDescription
ResponseThe agent's text response.
Conversation IdThe conversation ID for stateful calls. Store this in a Flow variable if you need to resume the conversation later.
Is Completefalse when the agent stopped early or its reply was blocked. Check this before treating Response as a finished answer.
Stopped BecauseBlank on a normal reply. Otherwise one of the reasons listed under When a reply is partial.
Blockedtrue when the output safety policy blocked the reply. Response holds a placeholder rather than an answer.

Check Is Complete before using the Response. A turn that stopped early still returns whatever partial answer it had composed, and it reads like a complete one. A Flow that writes it to a field or emails it to a customer has no other way to tell the difference.

The list of reasons grows, so branch on Is Complete rather than on the reasons you know about. A reason you have never seen still means the reply is partial.

One case reads as complete when it is not. When the agent did its work but its reply could not be written, Is Complete is still true, and Response holds the agent's own summary of what it did, or a short notice that the work happened, instead of an answer. No output tells the two apart, so keep it in mind before a Flow sends Response to a customer. Don't call again because of it: the work is done, and a second call does it again.


Group Key and Idempotency Key​

Both take a value from your own data, so a merge field is usually the right thing to pass.

Group Key chooses which memory the agent draws on, for an agent set to Shared across everyone. The same name always reaches the same memory:

Group Key = {!$Record.AccountId}
Group Key = {!$Record.CaseNumber}

Idempotency Key stops a Flow that retries on a fault, a screen someone double-clicks, or a scheduled path overlapping its previous run from starting a second turn while the first is still working:

Idempotency Key = {!$Record.Id}
Idempotency Key = {!$Record.CaseNumber}

Use the record id, not a formula that changes between attempts. A key that is unique per attempt is the same as no key at all.


When a Flow call fails​

The Daemon raises a Flow fault on any error, and the message always starts with the HTTP status, so a fault path can branch on it with CONTAINS.

Three of them mean do not retry, because retrying makes each one worse:

In the messageWhat happenedWhat to do
402A monthly spend limit has been reached, either the org's or this agent's own.Nothing clears until the limit resets at the start of the next month, UTC. Raise the agent's own limit in its Cost settings, or wait. A retry loop just burns Flow interviews.
504The agent ran out of time on this turn.Split the work into smaller calls. A turn heavy enough to time out will time out again.
409A call with this Idempotency Key is already running.Nothing. Wait for the first call and use its result.

A fault reading Read timed out, with no status in front, means Salesforce stopped waiting at 120 seconds. The agent did not: it keeps working to the end of its own limit, and the call is charged, but no answer reaches the Flow. Retrying starts the whole turn again, so set an Idempotency Key on any Flow that retries after a fault, and treat a timeout as a sign to split the work. See How long a call can take.

401 or 403 means the org credentials are being refused, and 404 means no agent with that External Id is visible to this org. Both are configuration rather than something a retry fixes.

400 with requires an authenticated user principal in the message means the agent is set to Per person memory. The action always calls as your organization, so such an agent cannot be called from a Flow.

429 is the one refusal that is worth retrying. It means a conversation has passed 200 calls in 2 minutes, so pause and the same call goes through. Only stateful Flows reusing one Conversation Id can reach it; a stateless call gets a fresh conversation every time and is never rate limited.


Host Context in a Flow​

Host Context JSON takes a JSON string. Build it with a Text Template or an Assignment element that concatenates field values into a JSON structure, for example the record's id, its name and its owner. What the agent does with it is on the Daemon page, under Passing Host Context.


Example Flow Patterns​

Summarize a Case on Close​

Trigger a Flow when a Case is closed. Pass the case description and comments to the agent, then write the summary back to a custom field.

  1. Trigger: Case status changes to Closed.
  2. Get Records: Retrieve the case details.
  3. Invoke Agent (Daemon) action: Send the case description and comments as the message.
  4. Update Records: Write the agent's response to a custom AI_Summary__c field on the Case.

Multi-Turn Lead Qualification​

Use a stateful conversation to ask a prospect a series of questions over time, maintaining context across each step.

  1. Trigger: Lead is created.
  2. Invoke Agent (Daemon) action: Stateful, no Conversation ID (starts a new conversation).
  3. Update Records: Store the returned Conversation ID on the Lead record.
  4. Later trigger: Lead stage is updated.
  5. Invoke Agent (Daemon) action: Stateful, passing the stored Conversation ID. The agent continues the thread with full prior context.

Classify Incoming Emails​

Trigger on new Email Message records. The agent classifies the intent and urgency, and the Flow routes accordingly.

  1. Trigger: Email Message is created.
  2. Invoke Agent (Daemon) action: Send the email body as the message.
  3. Decision: Parse the agent's response (e.g. "urgent", "billing", "general").
  4. Branch: Route to the appropriate queue or create a high-priority Case.

Tips​

Store Conversation IDs on records. For long-running stateful workflows, persist the Conversation ID on a Salesforce field so it survives across separate Flow executions, batch jobs, or time-triggered automations.

Watch the timeout. From a Flow, anything near the 120-second wait is a reason to split the work across separate invocations or narrow the agent's task.