> ## Documentation Index
> Fetch the complete documentation index at: https://docs.openlegion.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Connect your users, tools and approvals

> Map your signed-in user to a workspace, scope tool calls to that customer and hold a sensitive operation for approval.

## Resolve the customer on your server

Replace the development `currentSession()` 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 with `get_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](https://platform.openlegion.ai/docs/guides/tools)

### Choose built-in tools for the job

Your own functions go in the template's top-level `tools` 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.

| Task | Built-in tools |
| - | - |
| Find sources and read a public page | `web.search`, `web.fetch` |
| Read a document the user supplied | `files.read_attachment` |
| Write a brief and return a downloadable file in the chat | `files.write`, `files.deliver` |
| Recall a saved fact or look back over earlier events | `memory.search`, `memory.timeline` |
| Arrange a future run | `agent.schedule` |

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](https://platform.openlegion.ai/docs/platform-tools) · [Template fields and policy](https://platform.openlegion.ai/docs/template-spec)

## Hold a call for approval

For a function that sends an email, declare `effect: "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](https://platform.openlegion.ai/docs/guides/approvals)

## Let customers connect their own accounts

For a service such as Google Calendar or Drive, declare the supported app in the template's `apps` 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](https://platform.openlegion.ai/docs/guides/connections)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.