How it works
You write a template once. Each of your customers gets a workspace made from it, with its own agent. The agent works through your functions, which OpenLegion calls for the right customer, signed. Everything it does is a run, and everything a run changes is an action you can read.
template ──▶ workspace (one per customer) ──▶ agent ──▶ run ──▶ action ──▶ your tool
Your organization and its keys
Your organization holds your templates, connectors, webhook endpoints and money. Its keys are olp_test_… and olp_live_…, each with scopes, and they stay on your server.
Test and live are two separate worlds inside one organization. A test key never sees a live workspace, and the reverse is true too. Test mode runs real models on a free monthly allowance, and no money moves. It holds at most 100 workspaces, archived ones included: erase the ones your tests made to make room. An organization starts in test mode only: live mode is turned on by OpenLegion.
Templates: your agent, as code
A template is your agent product: its instructions, its model tier, its tools (yours, and OpenLegion's own such as agent.finish), what a run may spend, and the policy that decides which actions need a person's approval. With the kit it is openlegion/template.ts (defineTemplate).
Each push makes a new immutable version. Promoting a version moves every workspace that tracks the template onto it from its next run, and rolling back is promoting an older one. A workspace can also pin one version.
Workspaces: one per customer
POST /workspaces creates a customer's workspace from a template. It is create-or-get on external_ref, your own id for that customer, so it is safe to call again. The workspace holds the customer's agents, conversations, memory and credit limits, and nothing in it is visible from another workspace.
Your users act inside a workspace as members. Your server names the person (OpenLegion-Subject, or a session token from POST /sessions), and their role decides what they may do: an owner or admin may approve every held action and sees every conversation, and a member approves what their own conversation asked for, answers the agent's questions and sees only the threads they started.
Agents, threads and runs
The template's agents are made in each workspace. A thread is a conversation with one agent, and a message in it starts a run: one unit of the agent's work, from start to end.
- Something starts every run, and the run's
triggersays what: a chatmessage, aschedule, one of yourinbound_events, your own call (api), an approval that lets held work carry on (resume), another agent's hand-off, or the agent's own follow-up. - Runs on one agent take turns. A message sent while the agent is busy is saved and answered as soon as the current run ends.
- A run starts only once it can set aside its whole budget (the template's
budget.run_credits) from the workspace. If runs in flight hold what it needs, it waits for them; if it couldn't fit even then, it is refused. Once it starts, the workspace cap never cuts it off. It ends when its work is done, or when its budget is spent. - A run never waits for a person. When an action needs an approval, the run ends, and a later run carries on once someone decides.
- The reply streams as it is written. Closing the stream never stops the run, and a page that reloads picks it back up.
A run's status is queued, running, completed, failed, cancelled or settling (an action is still finishing after the run ended).
Actions: what the agent did
Every side effect the agent asks for is an action, saved before it runs: the tool, its input, the policy's decision, and once it is done a receipt. The model is never the last word on something that can't be undone: the policy decides, and a held action waits for a person's approval, bound to that exact input by its action_hash.
An action's status is requires_approval, approved, executing, completed, failed, rejected or expired. It is what you show your customer ("the agent wants to cancel 2 orders"), and what your support team reads when someone asks why the agent did something.
Your tools
Your functions become the agent's tools through one route in your app (app/api/openlegion/[...route]/route.ts). OpenLegion calls it signed with your connector's secret, and names the customer the call is for (ctx.external_ref). The route answers nothing that isn't signed.
Each tool says how far to trust what it returns (trust), and what it does (effect: read, draft, write or egress). A run that has read untrusted content, such as a web page or another person's words, is tainted, and your tools are told (ctx.tainted), so a tool that sends or changes something can refuse.
Your customers' own accounts
An agent can also work in accounts your customers connect themselves, such as their Google Calendar and Drive. Your template lists which apps they may connect (apps). Your user connects one on a page OpenLegion hosts in your brand, and the connection belongs to their workspace. The agent uses the account only through that app's tools, and never holds its token. More in Your customers' own accounts.
Events and webhooks
What happens in your organization becomes an event (run.completed, action.requires_approval, workspace.suspended, …). Events are kept to read with GET /events, and sent to your webhook endpoints, signed. With the kit, they arrive at your route's /webhooks, each type to its own handler.
Money
A credit is $0.001. Each workspace has its own limits (a period cap and a daily cap) inside your organization's pool. Runs, actions and usage say what they cost in micro-dollars (cost_micro).
What OpenLegion never does
- Need your key in a browser: the API sends no CORS headers, the SDK refuses an org key in a browser page, and your pages talk only to your own routes.
- Let the model decide an irreversible action on its own: the policy and your approvals do.
- Contact your customers: everything they see comes through your product.