agent-swarm.devagent-swarm.dev
Guides

Asset Namespaces

Group tasks, workflows, schedules, pages, apps, scripts, and provider-backed files under canonical shared or personal namespace keys

Asset namespace keys provide one directory-like grouping contract across the swarm's primary assets. A key is metadata, not identity: many assets can use the same key, while each asset keeps its existing ID. A task's contextKey also remains a separate routing and conversation-context field.

Key format

Every task, workflow, schedule, page, app, and script has a non-null canonical key. Existing rows and writes that omit the field use shared/.

  • shared/ and descendants such as shared/releases/
  • personal/<user-id>/ and descendants such as personal/<user-id>/drafts/
  • lowercase, relative paths using forward slashes and a trailing slash
  • a maximum of 255 characters after Unicode NFKC normalization

Empty segments, . or .. traversal segments, backslashes, absolute paths, NUL bytes, and unknown roots are rejected. Repeated keys are expected and valid; database indexes on key are deliberately non-unique.

When a workflow creates a task, the task inherits the workflow key unless the task node supplies one. Scheduler-created tasks inherit the schedule key. New standalone resources receive deterministic shared keys such as shared/task:<id>/, shared/workflow:<id>/, shared/schedule:<id>/, shared/page:<id>/, shared/app:<id>/, shared/script:<id>/, and shared/fs:agent-fs:<id>/. Older clients that omit the column at the SQL boundary still fall back safely to shared/.

personal/<user-id>/ is a namespace and write-ownership convention. It is not a privacy boundary or a read-visibility guarantee. Existing read permissions still govern every entity. Do not store sensitive content based only on a personal/ key.

Writes to a personal/<user-id>/ destination require the trusted user resolved from the authenticated request or task context to match the user ID in the key. A caller-supplied user ID is not sufficient. Shared namespaces retain each entity's existing mutation rules.

Source keys

A session that comes in from Slack, Telegram, or Discord gets a source key under shared/<source>/. The server sets it on the first task of the session when the caller gives no key. The later tasks of the session inherit it, as with any key.

SessionKey
Slack threadshared/slack/<channel>/thread:<ts>/
Slack DM through Chat SDK, with no thread tsshared/slack/<channel>/task:<id>/
Telegram topicshared/telegram/<chatId>/thread:<topicId>/
Telegram chat with no topicshared/telegram/<chatId>/task:<id>/
Discord threadshared/discord/<channelId>/thread:<threadId>/
Discord channel or DM with no threadshared/discord/<channelId>/task:<id>/
  • <id> is the id of the first task of the session. Keys are lowercase, so the Slack channel C0AR967K0KZ becomes c0ar967k0kz.
  • A Slack key goes to every first task with Slack thread fields, whatever its source. So an agent session that the lead starts in a Slack thread gets the key of that thread.
  • Teams and the other Chat SDK adapters keep the default key. So does an id that holds a /.
  • A key that the caller gives wins. The server does not check keys under a source prefix at task creation.

The group of a session is its key without the last segment, so each channel, DM, or chat is one group (shared/slack/<channel>/). The dashboard shows these groups in their own read-only source sections.

Effective source

The Sessions view filter (showSource, and the older hideSource) reads an effective source: the source of the key prefix when the key is under shared/slack/, shared/telegram/, or shared/discord/, else the task source. So an agent session (mcp) in a Slack thread counts as slack. The generic source filter still reads the task source.

Moves into source groups

Source groups are read-only for moves. A move of a session into a key under a source prefix is refused with "Source groups are read-only." PATCH /api/assets/task/{id}/key returns 400. POST /api/session-moves returns 200 and lists the session in skipped with that reason. The one exception is the session's own source key (the key that its Slack fields or chat thread give), so Undo after a move out works. A session that an agent created with some other explicit shared/slack/... key cannot move back after a move out. A move out of a source group works. POST /api/session-moves/prefix (rename and delete of a group) refuses a source prefix as the old or the new key.

One-time backfill

Sessions from before source keys sit under shared/ or shared/task:<id>/. After the first boot of the version that adds source keys, a background job moves them to their source keys:

  • It moves a session only when its key is still the default (shared/ or shared/task:<id of the first task>/). A session that someone moved to a group stays there.
  • It moves each session on its own: the whole chain of tasks and their attachment files, with a row in the key history.
  • It keeps the read state, Done, Later, and the latest activity time of each session.
  • When it finishes, it writes the done marker session-source-keys-v1 in seed_state, so it never runs again. A session that fails stays on its old key, the run writes no done marker, and the next boot tries again. A boot that stops halfway goes on from the last batch that had no failure.
  • While the key audit blocks moves, the job waits for the next boot.

Cross-entity API

GET /api/assets returns lightweight summaries across tasks, workflows, schedules, pages, apps, scripts, and mapped files. It accepts keyPrefix, comma-separated types, and limit filters. Summaries contain labels and provider references but never task briefs, page bodies, workflow definitions, script source, secrets, or file bytes.

PATCH /api/assets/{entityType}/{id}/key moves an asset to another logical namespace. App moves require app.manage; an agent-scoped script may be moved by its owning agent or an operator, while global scripts require lead/global write access. Moving an external provider mapping requires operator authentication and changes only local namespace metadata; its provider ID, organization, drive, and provider key remain unchanged, and the server does not call the remote provider. A task attachment mapping moves with its parent task and cannot be detached through the file endpoint.

Operator-only POST /api/assets/mappings idempotently associates a provider tuple with a logical key. The tuple is unique, while the namespace key is not. Agent-fs task attachments receive mappings automatically and inherit their parent task's namespace.

SwarmSDK access

HTML pages and JSON-page actions can use the domain-grouped asset methods instead of constructing REST requests directly:

const grouped = await window.swarmSdk.assets.list({
  keyPrefix: "shared/releases/",
  types: "task,workflow,schedule,page,app,script,file",
  limit: 100,
});

await window.swarmSdk.assets.move("page", pageId, "shared/releases/");

The full domain also exposes assets.audit() and assets.registerMapping(body). Those operations remain operator-only; the SDK does not weaken endpoint authentication or personal-namespace write checks.

Audit and rollout

Operator-only GET /api/assets/key-audit checks all primary assets and mappings, including apps and scripts. Missing or noncanonical keys are structural failures. Unknown personal users, missing attachment mappings, and provider mapping drift are repairable warnings. Namespace moves are blocked while audit issues exist so operators can repair mapping state before introducing more drift.

The same audit runs after migrations during server startup. Structural failures stop startup by default. ASSET_KEY_AUDIT_DISABLE_STARTUP_HARD_FAIL=true is a temporary recovery switch that reports the failure without aborting; repair the database and remove the switch before normal operation.

Existing apps and scripts are backfilled to shared/; new rows receive their deterministic resource keys. Migration rollback is application-first: deploy the previous application version while leaving the additive columns, indexes, triggers, mapping table, and history table in place. Old code ignores them safely. Do not remove or rewrite the applied migration. If a later cleanup migration is required, take and verify a database backup first and ship it as a new forward-only migration.

On this page