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.
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:- Authenticates the user with your existing auth.
- Decides the user’s
actor_idand current scopes from your own records. - Signs requests to Formation with the connection’s secret.
- Relays snapshots and the event stream back to the client.
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 toPOST /generic/events:
actor_idcomes 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_idis stable. Generate it once on the client or gateway and reuse it on retries. Formation de-duplicates on it.session_scopestells 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.
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:POST /generic/conversations/snapshotreturns the full conversation state: messages, runs, activity, pending inputs, and asequencenumber.POST /generic/conversations/streamwithafter_sequenceset to that number returns a server-sent event stream:message.upsert,text.delta, activity and input events, each with the next sequence.
Step 4: Show past conversations
The gateway can list the user’s own private conversations withPOST /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 throughPOST /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:
- Secrets through a one-time vault link.
- Drawings through a sketch canvas link.
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.
Checklist
- A webhook connection with Stream answers on, credentials stored only in your backend.
- A gateway that derives
actor_idandsession_scopesfrom 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_URLthat 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.