> ## 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.

# How the Platform runs an agent

> Trace a customer's message from your app through a workspace, an agent, a run and a recorded action.

Suppose you run a support product. You write one template for a support assistant. Each customer gets a workspace made from that template. When someone opens chat to ask about an order, your server identifies both the customer who owns the order and the person asking. The Platform runs the agent and calls your order lookup with that customer's identity.

| Resource | What it means in this example |
| - | - |
| Organization | Your business's templates, API keys, connectors, webhook endpoints and credit pool. Test and live resources are separate. |
| Template version | A published set of agent instructions, tools, policies, limits and customer-editable settings. |
| Workspace | One customer's agents, conversations, connections, memory and limits. Your own customer ID is its `external_ref`. |
| Agent and thread | The agent persists across tasks. A thread holds one conversation with that agent. |
| Run | One execution started by a message, schedule, API call or other trigger. Runs on the same agent take turns. |
| Action and receipt | The requested tool and its input, the policy decision and the recorded outcome of execution. |

## Create the workspace once per customer

Call `workspaces.create` on your server with the template and a stable `external_ref`. Repeating the call with that reference retrieves the customer's workspace. Keep its ID alongside your customer record. Pass their IANA `time_zone` when creating it so schedules such as “Monday at 9” run on their clock. The default is UTC.

For example, this server-side call uses the template created by the quickstart in a project named `my-app`. Substitute a customer ID from your authenticated session and your promoted template slug.

```ts theme={null}
import { OpenLegion } from "@openlegion/platform";

const ol = new OpenLegion();
const workspace = await ol.workspaces.create({
  external_ref: "customer_42",
  name: "Example customer",
  template: "my-app",
  time_zone: "Europe/London",
});
```

Use `workspace.id` when making subsequent API calls for this customer.

## Roll out a template change

Pushing a template creates an immutable version. A workspace that tracks the template slug takes the promoted version on its next run. A workspace created with a version such as `support@3` stays on that version. For tracking workspaces, promoting an earlier version rolls the change back.

## Follow a run

A message starts work on the server. Closing the chat leaves the run active, and the chat can reattach when the person returns. A proposed action goes through policy before execution. If it needs approval, the Platform saves the action and ends the run. A later run can execute the approved input. Read the action's receipt when you need to know what happened.

The hosted engine keeps agent state in Postgres and holds a lease while a run is executing. A waiting approval or an idle agent can therefore persist across requests and deployments. Your application remains responsible for sign-in, permissions on its own records and how results reach its customers. [Platform architecture](https://platform.openlegion.ai/docs/how-it-works) · [Template specification](https://platform.openlegion.ai/docs/template-spec)


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