# Agents

URL: https://forculuslabs.tech/docs/access/agents/

> Give an agent or a service a name of its own, the apps it needs, and credentials you can revoke.

An agent is a caller that belongs to your workspace rather than to a person. It has a name, it reaches only the apps you grant it, and it calls them with credentials of its own. Every request it makes shows in the audit log under its name.

Use an agent for anything that calls your apps on its own: an AI agent that reads a dashboard, a nightly job, another service. A [bypass token](https://forculuslabs.tech/docs/access/tokens/) opens one app and stops when the person who made it loses access. An agent can hold several apps, outlives the person who made it, and is managed by the workspace. [Agents on Forculus](https://forculuslabs.tech/agents) is the same in one page, to send to whoever decides.

## Make an agent

```sh
forculus agent create acme release-bot
```

```text
Made release-bot (ag_5k2m9q0d8w1x7c4v). It reaches nothing yet. Grant it an app with `forculus agent grant acme/<app> release-bot`, then mint it a credential with `forculus agent token acme release-bot`.
```

Any member of the workspace can make one. A name is 1 to 100 characters, with no control characters or invisible ones like a zero-width space, and spaces at either end are trimmed. It can’t look like an agent’s id (`ag_` and 16 letters and digits). Names are unique among a workspace’s live agents, whatever their case and whether their words are joined by spaces, dashes or underscores: with `release-bot` there, `forculus agent create acme Release-Bot` and `forculus agent create acme 'release bot'` are refused with `This workspace already has an agent called release-bot. Pick another name.` A name with spaces needs quotes in every command after, so a name like `release-bot` is easier. The commands below take the name or the id.

In the dashboard, open **Agents** in the workspace’s menu and select **New agent**.

## Grant it an app

```sh
forculus agent grant acme/payroll release-bot --role viewer
```

The app sees the agent as a `viewer` or an `editor`. It takes effect on the agent’s next request. Only someone who can share the app can grant it: the app’s owners, and the workspace’s owners and admins. In the dashboard, it’s the **Agents** section of the app’s **Sharing** tab.

An agent gets into an app only through a grant. Being in the workspace, or the app being open to the whole workspace, lets people in, never agents.

Granting an app to an agent grants it to whoever manages the agent, since they can mint its credentials: its maker, and the workspace’s owners and admins. The **Sharing** tab shows who made each agent.

So an agent made by a member never reaches further than that member can, by any way they’re let in: shared with them, with a [group](https://forculuslabs.tech/docs/access/share/#share-with-a-group) they’re in, or with [everyone at their domain](https://forculuslabs.tech/docs/access/share/#share-with-everyone-at-your-companys-domain). Take the last of those away, or make them a viewer of the app, and the agents they made lose it, or become viewers of it, at the same time. The same goes when an admin is made a member. Agents made by the workspace’s owners and admins keep their grants, since those people manage every agent anyway.

It holds when you grant one too. Granting a member’s agent an app that member can’t open, or `editor` on an app they can only view, is refused, and nothing changes:

```text
error: An agent reaches no further than the member who made it. Share the app with them first, or grant the agent less.
```

To take the app away:

```sh
forculus agent revoke acme/payroll release-bot
```

Its next request is refused, and an open WebSocket, stream or download closes within 15 seconds.

## Mint a credential

```sh
forculus agent token acme release-bot
```

The secret starts with `fca_` and is shown once. We keep only a hash of it. Give it to the agent in its secret settings, never in code: a deploy that has one in its files is refused.

A credential always ends. From the CLI it lasts up to 30 days (`--days`), and no longer than your CLI session would. Signing out, or revoking that session, doesn’t end it: it’s a credential of its own. Revoke it as below, or every credential and bypass token you made with `forculus logout --everywhere --tokens`. The dashboard’s **New credential** offers 7, 30, 90 or 365 days, and asks you to sign in again if you last did more than 15 minutes ago. The API, `POST /v1/workspaces/<workspace>/agents/<agent>/credentials`, takes `expires_in_days` from 1 to 365, and 90 when it’s left out.

The agent’s maker and the workspace’s owners and admins mint and revoke its credentials, unless the workspace’s [publish policy](https://forculuslabs.tech/docs/access/publish-policy/) keeps minting them to the people its owners name. A maker who is removed from the workspace stops managing their agents, and doesn’t get them back if they’re added again. A credential works only while whoever minted it still could: if they leave the workspace, their address falls outside its allowed domains, they lose the role that let them, or their account ends, it stops working and is revoked for good.

To revoke one, by its id from `forculus agent list`:

```sh
forculus agent token acme release-bot --revoke ac_9d2k4m1q8x0w3c7v
```

It stops working on the next request.

## Call an app

The agent sends its credential to the apps domain, with the workspace and the app as the first two parts of the path, as a bypass token does:

```sh
curl -H "Authorization: Bearer $FORCULUS_AGENT_CREDENTIAL" https://forculuslabs-apps.tech/acme/payroll/
```

The app’s own address, `https://payroll--acme.forculuslabs-apps.tech`, takes only a browser sign-in and refuses a credential, and so does any [custom domain](https://forculuslabs.tech/docs/apps/custom-domains/) the app has. Our edge checks the credential with the control plane on every request and caches nothing.

## What your app sees

Each request carries a fresh identity token in `X-Forculus-Identity`. For an agent, `kind` is `service`, the subject is `agent:` followed by the agent’s id, and `agent_name` holds its name as it is now. There’s no email. `role` is the agent’s role on this app. Every SDK takes it as a service, so an app that already handles bypass tokens handles agents too. From version 0.2.0 each SDK also gives you the name, and says whether an agent called: `user.agentName` and `isAgent(user)` in Node.js, `user.agent_name` and `user.is_agent` in Python, `user.AgentName` and `user.IsAgent()` in Go, `user.agent_name` and `user.is_agent()` in Rust. Without those, check whether `sub` starts with `agent:`. See [What you get back](https://forculuslabs.tech/docs/sdks/#what-you-get-back).

Decide what an agent may do by `sub`, never by `agent_name`. A name can be changed by whoever manages the agent, and once an agent ends its name is free for a new one. The name is there to show.

## List agents

```sh
forculus agent list acme
forculus agent list acme --all
```

It lists the live agents. Add `--all` for the ended ones too, after them. Each agent comes with the apps granted to it that you can see, its credentials and when each last opened something. One whose maker has deleted their account says it was made by a deleted account. `--json` gives the same as data, with the maker’s address in `created_by` and `maker_deleted` set. The **Agents** page in the dashboard hides ended agents the same way, until you choose **Show ended agents**.

In the audit log, the requests an agent was let in on name the agent, by the name it had when it made them, and the credential it used, so you can tell its credentials’ use apart and revoke one alone. A refused request names the agent when it’s one of this workspace’s.

## Rename an agent

```sh
forculus agent rename acme release-bot ship-bot
```

Its id, its credentials and the apps granted to it stay as they are. Your app sees the new name in `agent_name` from the agent’s next request.

## End an agent

```sh
forculus agent end acme release-bot
```

Ending is for good. Its credentials stop working on their next request, its apps are taken away, and its name is free for a new agent. It leaves the list, and `forculus agent list acme --all` still shows it. The log keeps what it did. Since it can’t be undone, it asks first. In a script, or anywhere else with no terminal to ask at, add `--yes`.

## Limits

Agents are on every plan. A workspace can have 3 agents at once on Free, 25 on Team and 100 on Business, and each agent 10 live credentials. A credential lasts at most 365 days. A workspace can make 200 agents, and mint 200 credentials, in any 24 hours. Past a limit you’re told which one, for example:

```text
error: This workspace has 3 agents, the most the Free plan allows at once. End one you no longer use first. Or upgrade: Team allows 25 agents.
```

Agents that only call apps are free. The workspace’s first agent granted an app as an editor, so it can deploy or change it, is free too, and every other one uses a member place, like a person. When none is left, granting another agent the editor role is refused with `403` `plan_limit`, and so is inviting someone. See [Billing](https://forculuslabs.tech/docs/billing/#agents).

## For AI agents using the MCP server

[`forculus mcp`](https://forculuslabs.tech/docs/agents/) has `list_agents`, `create_agent`, `set_agent_access`, `rename_agent` and `end_agent`. `list_agents` lists the live agents, and the ended ones too with `all`. It has no tool that mints a credential, so a secret never passes through an agent’s conversation. Mint it yourself with `forculus agent token` or in the dashboard.
