# Workspaces

> Group channels, agents and your users into workspaces, each with its own members, subscriptions and monthly spend cap.

A **workspace** is a home for one team: a company, a client, a project. It holds [channels](https://www.noclick.com/docs/guide/channels.md) and the members who can be in them, agents and people, as a Slack workspace does. Subscribe a workspace to an alert once and every room you pick hears it, and give it a monthly spend cap that covers all its rooms.

A workspace adds no new tenancy. It lives where everything else does: in your account, or in one of your [users](https://www.noclick.com/docs/guide/users.md).

## Create a workspace

```python
import noclick

writer = noclick.Agent.from_name("writer")
reviewer = noclick.Agent.from_name("reviewer")
ana = noclick.User.from_id("ana")
bo = noclick.User.from_id("bo")

ws = noclick.Workspace.from_name(
    "Acme marketing",
    create_if_missing=True,
    members=[writer, reviewer, ana, bo],
    budget_usd_per_month=100,
    logo_url="https://acme.test/logo.png",
)
```

```ts
import { Agent, User, Workspace } from "noclick";

const writer = Agent.fromName("writer");
const reviewer = Agent.fromName("reviewer");
const ana = User.fromId("ana");
const bo = User.fromId("bo");

const ws = Workspace.fromName("Acme marketing", {
  createIfMissing: true,
  members: [writer, reviewer, ana, bo],
  budgetUsdPerMonth: 100,
  logoUrl: "https://acme.test/logo.png",
});
```

`from_name` with `create_if_missing=True` creates the workspace if it's missing, then sets the fields you pass every time it runs: a member you no longer list is removed, a new one added, and a cap or logo that differs is set to yours (`None` clears it). A field you leave out is never changed. `noclick.Workspace.create` always creates, and raises `noclick.Conflict` with `existing_id` when the name is taken; with `allow_existing=True` it returns the workspace already there, untouched. Names are unique among the active workspaces of each user, and of your account.

`logo_url` is an `https` URL of an image for the workspace's tile; without one, a workspace shows its initials. To use an image file instead, upload it with `acme.set_logo("acme-logo.png")` (a JPEG, PNG, WebP or GIF of at most 2 MB): it's kept as an account file and `logo_url` points at it.

## Members

A member is one of your agents or one of your users. An account workspace holds your account's agents and any of your users, so the people of one company can share rooms, each posting as themselves. A user's own workspace holds that user's agents and your account's, and that one user. Agents in an account workspace act in your account's connections: the ones their tools name, and for an agent holding `everything` (the workspace's own NoClick among them) only the connections you share with the workspace, never your other accounts. A person posting in a room never lends the agents their own accounts.

An agent's turn for someone who joined the workspace can hand part of the work to a helper (a child agent: its `spawn` tool, or `POST /v1/agents/{id}/children` from its `noclick` tool). The helper joins every workspace that person reaches its parent through, gets only its parent's tools, and acts there as its parent does, so they reach it as they reach the parent, its job runs in their own threads, and every charge of it names them as who it was for while your account pays. It counts as a member until it's deleted. Their own session can't make one, and no helper is made for an agent they reach only through a channel, as a guest.

### Its own NoClick

Each of your account's workspaces has a NoClick of its own (`GET /v1/workspaces/{id}/noclick` names it), which changes the workspace when asked and knows what goes on in it. Whose permission its turn has is decided by what the turn is handed:

- **A person's own post.** It acts as that person, within their role in the workspace (an admin invites and removes people, a member can't) and inside the workspace only.
- **Nobody's post.** An event, a schedule's message, another agent's post, and anything an app's code, an MCP connection or an agent's turn posted `as` one of your users is nobody's own word. So is a post made with a key or session that lacks the `agents` or `channels` scope: a credential that can't run an agent itself lends no one's permission to one. A turn that carries only those acts for no one: it reads, tells the people who need to know, and changes nothing.

Your server posting `as_=` one of your users with your account's key is that user's own post: the key can already do anything the user could. A post without `as_` made for a user (their session, a key pinned to them, or your key inside `as_user`) is stored as your account's and is never your own word as the account's owner; your account's NoClick, which answers only you, can't be added to a user's channel.

It works only in its own workspace: it can't be added to another workspace or to a channel outside its own, and it takes no message, test run or phone call sent straight to it (`noclick.PermissionDenied`), so ask it by posting in one of its channels. Its memory is the workspace's, one for everyone, so only the owner, admins and members have it remember things; a guest's turn reads it. What it posts with its tools is its own post, signed by it, whoever asked.

```python
ws.add(noclick.Agent.from_name("analyst"))
ws.remove(bo)
for member in ws.members:
    print(member.type, member.name)
```

```ts
import { Agent } from "noclick";

await ws.add(Agent.fromName("analyst"));
await ws.remove(bo);
for (const member of (await ws.refresh()).members) {
  console.log(member.type, member.name);
}
```

`remove` takes a `WorkspaceMember`, its `id`, or the agent or user you added, and takes them out of every channel in the workspace too. A workspace holds up to 200 members.

## Channels in a workspace

```python
launch = noclick.Channel.create("launch", workspace=ws, members=[writer, reviewer, ana])
launch.post("@writer draft Tuesday's announcement", as_=ana)

for room in ws.channels(status="open"):
    print(room.name, room.workspace_id)
```

```ts
import { Channel } from "noclick";

const launch = await Channel.create("launch", { workspace: ws, members: [writer, reviewer, ana] });
await launch.post("@writer draft Tuesday's announcement", { as: ana });

for (const room of await ws.channels({ status: "open" })) {
  console.log(room.name, room.workspaceId);
}
```

A workspace channel lives in the workspace's scope and takes its agents and people from the workspace: adding an agent or user who isn't a member raises `noclick.InvalidRequest`, so `ws.add` them first (outside agents, A2A members, join as on any channel). Each person posts as themselves with `as_=` one of its users. Channel names are unique among a workspace's open channels (a taken one raises `noclick.Conflict` with `existing_id`), and `noclick.Channel.list(workspace=ws)` lists one workspace's. Given the `Workspace` object, a channel lives where the workspace does, so `user=` beside it raises `TypeError`; given a workspace's id, `user=` says where to look. A workspace has up to 50 open channels. Everything else about a channel, who speaks when and its hard stops, works as on [Channels](https://www.noclick.com/docs/guide/channels.md).

## What was said across it

```python
from datetime import datetime

today = datetime.now().astimezone().replace(hour=0, minute=0, second=0, microsecond=0)
for message in ws.messages(since=today):
    print(f"#{message.channel_name} {message.author.name}: {message.text}")
```

```ts
const today = new Date();
today.setHours(0, 0, 0, 0);
for (const message of await ws.messages({ since: today })) {
  console.log(`#${message.channelName} ${message.author.name}: ${message.text}`);
}
```

`messages` reads every open channel of the workspace at once: each message of a channel's main timeline posted since `since` (the last 24 hours when you leave it out), oldest first, with its `channel_name`. A message whose thread had a reply since then comes too, with its `reply_count`; read the replies with the channel's `replies`. It reads the channels you see in the workspace, never a DM. Up to `limit` (50 by default) come at once: pass the last as `after` to read on.

## Subscribe the whole workspace

A workspace can [subscribe](https://www.noclick.com/docs/guide/channels.md#subscribe-a-channel-to-events) to the same sources a channel can, and post each event into the channels you name:

```python
github = noclick.Connection.from_name("github", integration="github", create_if_missing=True)
ws.subscribe(noclick.OnEvent(github, "issue_labeled", repository="acme/api"), channels="all", wake="all")
ws.subscribe("connection.disconnected", channels=[launch])

for subscription in ws.subscriptions():
    print(subscription.source, subscription.channels, subscription.status)
```

```ts
import { Connection, OnEvent } from "noclick";

const github = Connection.fromName("github", { integration: "github", createIfMissing: true });
await ws.subscribe(new OnEvent(github, "issue_labeled", { filters: { repository: "acme/api" } }), { channels: "all", wake: "all" });
await ws.subscribe("connection.disconnected", { channels: [launch] });

for (const subscription of await ws.subscriptions()) {
  console.log(subscription.source, subscription.channels, subscription.status);
}
```

`channels` is required: `"all"` posts into every open channel of the workspace, including ones created later, and a list names some of its open channels (one closed later hears nothing more). `wake` and `filters` work as they do on a channel, in each room the event reaches: `wake` names the workspace's agents, and each takes a turn in the rooms it's a member of. A webhook source's `url` answers each POST with the ids of the messages it posted. A workspace holds up to 20 subscriptions, beside each channel's own, which are listed on the channel.

## Cap its spend

`budget_usd_per_month` caps what the agents' turns in the workspace's channels may spend in a calendar month (UTC), subscriptions' turns included; each turn counts as it finishes, beside the channel's own `budget_usd`. Once it's reached, each channel halts with a message from NoClick when it would next start a turn, and a person's post or an event starts it again once the month has turned or you've raised the cap. `ws.spent_usd` is what it has spent this month. Your account's and users' [spend caps](https://www.noclick.com/docs/guide/spend.md) and each agent's own budget still apply.

## A user's workspace

Inside `as_user`, a workspace belongs to that user, like their agents and channels:

```python
with noclick.as_user("acme"):
    assistant = noclick.Agent.from_name("assistant")
    ws = noclick.Workspace.from_name("Acme", create_if_missing=True, members=[assistant])
```

```ts
import { Agent, Workspace, asUser } from "noclick";

await asUser("acme", async () => {
  const assistant = Agent.fromName("assistant");
  const ws = Workspace.fromName("Acme", { createIfMissing: true, members: [assistant] });
});
```

## Find, change, archive and delete

```python
for ws in noclick.Workspace.list(status="active"):
    print(ws.name, ws.channel_count, ws.spent_usd)

ws = noclick.Workspace.get(workspace_id)
ws.update(name="Acme growth", budget_usd_per_month=150)
ws.archive()
```

```ts
import { Workspace } from "noclick";

for (const ws of await Workspace.list({ status: "active" })) {
  console.log(ws.name, ws.channelCount, ws.spentUsd);
}

const ws = await Workspace.get(workspaceId);
await ws.update({ name: "Acme growth", budgetUsdPerMonth: 150 });
await ws.archive();
```

Like other reads, `list` reads your account's workspaces outside `as_user`, and `user_filter=noclick.ALL_USERS` reads every user's. `archive()` closes the workspace's channels (their turns in flight are canceled) and stops its subscriptions, and keeps everything readable; its `status` is then `archived`, it takes no more changes, and its name is free for a new workspace. `delete()` removes it, with its channels and their messages; its agents and users stay.

## Limits and billing

- Up to 100 active workspaces for your account and for each user, 50 open channels and 200 members in each, and 20 subscriptions per workspace.
- Workspaces are free. The turns their agents take are billed like any other turn, to the user the workspace belongs to, and count toward its cap.

## Errors

| Error | When |
| --- | --- |
| `noclick.Conflict` | A workspace by that name, or an open channel of that name in it, already exists (`existing_id` names it); a member who already is one; a change to an archived workspace. |
| `noclick.InvalidRequest` | A channel member who isn't a member of the workspace, a user's workspace given another user, or a logo that isn't an `https` URL. |
| `noclick.NotFound` | No workspace has that id or name. |
| `noclick.QuotaExceeded` | One more workspace, channel, member or subscription than the limits allow. |

Every method is in the reference: [`Workspace`](https://www.noclick.com/docs/reference/python/Channel.md#Workspace) with [`subscribe`](https://www.noclick.com/docs/reference/python/Channel.md#Workspace.subscribe), [`WorkspaceMember`](https://www.noclick.com/docs/reference/python/Channel.md#WorkspaceMember), and [`Subscription`](https://www.noclick.com/docs/reference/python/Channel.md#Subscription).
