Resolve the customer on your server
Replace the developmentcurrentSession() in openlegion/session.ts with your application’s authentication. Return the signed-in person’s stable user ID and the ID of the customer account they belong to. Return null when the person is signed out. Your server uses the account ID to find the workspace and the user ID to attribute messages and decisions.
Keep OPENLEGION_API_KEY on the server. The browser talks to your kit route. For backend requests on behalf of a user, the API supports a workspace session or an organization key with the act_as scope and an OpenLegion-Subject header. Derive the subject and workspace from the authenticated session.
Give an agent one of your functions
Start withget_account in the scaffold. In openlegion/tools.ts, replace its sample return value with a query scoped to ctx.external_ref, the customer ID in the signed call. When a particular user’s permissions matter, check ctx.subject too. Scheduled work can have a null subject, so define which operations may run without a person.
A tool declaration describes its input, the source of its results (trust) and its effect, such as read or egress. Use web_low for results containing other people’s words, even if those words came from your database. Register the tool in openlegion/template.ts so the agent can call it. The kit verifies the connector signature before invoking the function. Tool declarations and examples
Choose built-in tools for the job
Your own functions go in the template’s top-leveltools map. The built-in tool IDs an agent may use go in its tools list. For a research assistant, choose the tools according to the result you want.
For work that needs code execution,
sandbox.run runs a command in a temporary sandbox. Network destinations are controlled by the template. Interactive browser tools also depend on the deployment’s browser capability and a site grant. Check the capability reported by GET /keys/self before adding browser tools to a template, and handle a refusal if the browser is unavailable at run time. Built-in tool catalog · Template fields and policy
Hold a call for approval
For a function that sends an email, declareeffect: "egress" and requiresApproval: true. Give it an approvalTitle and name the approvalFields the person should review, such as the recipient and message. The effect tells the Platform what the function does. The approval requirement holds each proposed call.
The chat displays the saved action. Workspace owners and admins may decide any held action in their workspace. A member may decide one requested in a thread they started. Approval authorizes the saved input. The actual call and receipt follow in a later run. Use ctx.action as the idempotency key when your function performs the external operation, so a retried call can return the original result. Approvals and workspace roles
Let customers connect their own accounts
For a service such as Google Calendar or Drive, declare the supported app in the template’sapps and register your return origin. The customer completes the hosted connection flow and returns to your UI. The Platform stores the account token and exposes permitted tools to the agent. For a customer-supplied MCP server, every tool call requires approval. The catalog returned for a workspace reflects what its template permits. Connected accounts and the React components