Skip to main content
Formation agents do not have to live only in Slack or Teams. The same agent can sit inside your own product: a chat panel in your web dashboard, an assistant screen in your mobile app, a support widget on your site. The agent keeps its identity, memory and tools, and your product decides who the user is and what they are looking at. This page walks through the whole pattern, using one worked example throughout. Each step links to the reference page that owns the contract. For every way an agent can connect to your systems, including REST APIs, account linking and self-hosted models, see Connect agents to your systems.

The worked example

An operations company runs a web dashboard and a companion iOS app for its customers. It wants one assistant in both:
  • A signed-in user opens the assistant from any screen and asks questions in plain language.
  • The answer streams in as it is written, with live activity (“Looking up devices”, “Reading the report”) while the agent works.
  • The agent knows which organization and workspace the user is in and what screen they asked from.
  • The agent can look things up and take actions in the company’s own system, limited to what that user is allowed to see.
  • Conversations survive closing the app: the user can come back to the list of their past conversations and pick one up.
  • The company’s engineers can see exactly what the agent did on a given turn.
The same agent also has a Slack connection for the company’s own staff. Nothing below changes that.

Architecture

The key design rule: your clients never talk to Formation directly. A small server-side gateway in your backend holds the connection credentials and speaks to Formation for both the web app and the mobile app. The browser and the iOS app only talk to your gateway, with your own session or token. The gateway:
  1. Authenticates the user with your existing auth.
  2. Decides the user’s actor_id and current scopes from your own records.
  3. Signs requests to Formation with the connection’s secret.
  4. Relays snapshots and the event stream back to the client.
The secret never ships in a bundle or binary, and a client can never claim to be a different user, because the client never chooses the actor_id.

Step 1: Create a webhook connection

On the agent’s Connections page, add a Webhooks connection (the generic connector). Formation shows an install id, a signing secret and the events URL once. Store them as server-side secrets for your gateway. You can leave the delivery URL empty. An application that reads replies through snapshots and streaming, as in this example, does not need Formation to POST replies back. Set a delivery URL only if you also want push delivery. Turn on Stream answers for the connection so answers arrive incrementally. Reference: Webhooks, Application streaming.

Step 2: Send messages as the signed-in user

When the user sends a message, the client calls your gateway. The gateway posts a signed message to POST /generic/events:
Choices that matter:
  • actor_id comes from your auth, never from the client. If one person can use several workspaces, give them a distinct actor id per workspace, as above, and check membership before each request. That keeps what the agent learned in one workspace out of another.
  • message_id is stable. Generate it once on the client or gateway and reuse it on retries. Formation de-duplicates on it.
  • session_scopes tells the agent where the user is. Up to four scopes, such as organization, workspace, project or site. They are context the agent sees for this message, not permissions.
  • topology: "direct" makes this a private conversation between the user and the agent, which is what lets the user read it back through the stream.
A 200 means the message is stored durably and the run will happen, even if Formation restarts. The reply arrives through the stream. Reference: Sending a message.

Step 3: Stream the answer

To show the conversation, the gateway first asks for a snapshot, then subscribes from that point:
  1. POST /generic/conversations/snapshot returns the full conversation state: messages, runs, activity, pending inputs, and a sequence number.
  2. POST /generic/conversations/stream with after_sequence set to that number returns a server-sent event stream: message.upsert, text.delta, activity and input events, each with the next sequence.
The gateway relays the stream to the browser as server-sent events and to the iOS app over its own streaming request. If the connection drops, reconnect with the last sequence you applied. If Formation reports a gap or asks for a fresh snapshot, reload the snapshot and subscribe again. The agent keeps working in Temporal while no one is connected, so closing the app never stops a run. Short answers can arrive as one complete message instead of a stream of deltas, and incremental text depends on the model provider supporting streaming. Your client should handle both. Disable response buffering in any proxy between Formation and the client, or the stream will arrive in one lump at the end. Reference: Snapshot, Subscription and replay, Activity.

Step 4: Show past conversations

The gateway can list the user’s own private conversations with POST /generic/conversations/list, and search them with POST /generic/conversations/search. Each entry returns a conversationKey to open with the snapshot and stream calls, and whether it still has unfinished work. A user only ever sees conversations recorded under their own actor_id on that connection. Reference: Conversation history.

Step 5: Give the agent your app’s tools

The webhook connection carries conversation only. To let the agent act inside your system, expose your API as a remote MCP server and connect it on the agent’s Tools page, with OAuth or a dedicated bearer token for the agent. Formation discovers the tools, honors their read-only and destructive annotations, and gates, budgets and audits every call. In the example, the MCP server offers tools such as “search sites”, “get device history” and “open a work order”. Tools can also supply short public activity labels, which is where the “Looking up devices” lines in the app come from. Reference: Remote MCP, Pair it with tools.

Acting as the user

An agent’s MCP connection authenticates the agent, not your user. If each user should only see their own data through the agent, the MCP server has to restrict each call to what the asking user can access. Formation can attach execution context to read-only tool calls that originate from a private webhook conversation: which agent, connection, actor, conversation and run the call belongs to. Your MCP server uses that context to look up a short-lived grant your own system issued for that user, and refuses the call without one. Formation never forwards a user’s credential, and the context alone is not authorization. Tools opt in by declaring the extension; read Delegated MCP queries for the contract your server must implement.

Step 6: Let the user answer the agent

Sometimes the agent needs a decision, such as whether to keep going on a long task. These arrive in the snapshot and stream as inputs with a title and a pending status. Render them as a prompt in your UI, and send the user’s answer back through POST /generic/events as a signed message with an input_response naming the input and whether it was approved. Only one answer wins, retries with the same message_id are safe, and the receipt appears in the stream once it is recorded. The agent can also collect things that do not belong in chat: Both links point at Formation’s PUBLIC_URL, so the user must be able to open it. See Configuration. Reference: Application input decisions.

Step 7: Inspect what happened

For your engineers, two read paths are available:
  • Run diagnostics from your servers. A server-side tool holding an operator API token can read the recorded evidence for a run: the model input, the tools offered and called, and timings. See Application diagnostics.
  • An inspector in your own app. Create a read-only diagnostic key for the agent on its Diagnostic keys page and paste it into your inspector. The key reads diagnostics directly from Formation and cannot send messages, run tools or change configuration. See Inspector access.
The chat connection’s signing secret never grants diagnostics, and a diagnostic key never grants chat. Never put an operator API token in a browser or mobile app.

Checklist

  • A webhook connection with Stream answers on, credentials stored only in your backend.
  • A gateway that derives actor_id and session_scopes from your own auth and signs every request.
  • Snapshot, then stream from its sequence; reload the snapshot on a gap.
  • A remote MCP server for your tools, connected to the agent.
  • An HTTPS PUBLIC_URL that your servers and your users can reach.
  • A test: send a message from the app, close it mid-answer, reopen it, and check the full answer and the conversation list.