Files
baserow/docs/decisions/011-agent-applications.md
Davide Silvestri 5169076065 feat: introduce User-backed workspace identities (#6556)
* feat: introduce User-backed workspace identities

Replaces workspace core.Agent subjects with identities stored as Django
Users, so permissions, execution and attribution use the same record.

- User.objects and WorkspaceUser.objects are human-only; permission and
  identity code opts in through objects_and_identities. is_human and
  is_identity classify a user at runtime.
- Login, tokens, seats, notification recipients, personal views and
  last-admin checks stay human-only. Roles, teams and field grants work
  for identities unchanged.
- Agent applications run as an identity, never as a person. Every shared
  tool rechecks the identity's authority on each call, and MCP refuses a
  tool that skips that boundary.
- Migrations add the profile metadata and index, remove the Agent model
  and delete or clear legacy Agent data: trash entries, role assignments,
  team memberships, integration authorizations and run-as bindings.
- Rename the management API, UI, events and feature flag to identity.

Squashed and rebased onto develop; the previous history is kept on
backup/6556-before-develop-rebase.

* refactor: remove generic subject options endpoint

* refactor: simplify identity selection and Agent run-as options

* feat: distinguish identity notification senders

* fix: restrict identity bindings to identity managers

* docs: record users and identities verification

* fix: restore snapshots as the person restoring

A restore checked the snapshot creator's permission and used the creator
to decide whether an Agent keeps its identity binding. It now checks the
person restoring, passed to the import as `restored_by`. `copied_by` stays
unset on restore, so credential checks keyed on it behave as on develop.

Restoring a snapshot whose creator was deleted works again. The copy rule
for identity bindings covers Agent run-as only; a copied Local Baserow
integration keeps its authorized subject.

* fix: leave settings pages the user may not open

A settings route without a permitted tab rendered an empty page, as the
Identities page did with its feature flag off. It now opens the first
page the user may see.

* fix: renumber the legacy Agent cleanup migrations

Develop added agent 0016 and integrations 0043, so the migrations that
clear legacy Agent run-as bindings and integration authorizations move to
agent 0017 and integrations 0044.

* test(agent): run the trigger self-event test as an identity

The test added on develop created a `core.Agent`, which this branch
removes. It now uses an identity user as the Agent's run-as subject.

* perf: load user types once per batched permission check

* refactor: state the stored subjects in each subject type

* fix: give every user a profile

* fix: keep identity attribution on rows copied in their workspace

* refactor: give people and identities their own subject type

UserSubjectType stays the type both are registered and stored under. It forwards what differs to HumanSubjectType and IdentitySubjectType, so get_specific_type is the only place in subject code that inspects the user type. The registry returns the specific type on request and get_by_model keeps returning the stored type, which never reads the profile.

An identity's membership is checked in one query instead of two.

* fix: keep the roles of identities when a database is duplicated

The role import read subjects through the model's default manager, which only returns people, so duplicating or restoring a database failed when an identity held a role on it. It now resolves the subject through the subject registry.

A subject that no longer exists is skipped instead of failing the whole duplicate or restore.

* refactor: look up a subject type from its content type in one place

* fix: reload a cached token whose profile is incomplete

A token cached by the previous release has a profile without the user type, which reads as not a person, so its requests were refused until the entry expired. The token cache now treats it as a miss, with the check the user cache already used.

* refactor: check the user type once where the check was repeated

The MCP endpoint loader, the personal view permission manager and the identity trash type each asked the same question several times. The rule that an identity is never selected by email moves from the team handler to the identity subject type.

* refactor: leave trashed workspaces out of the identity membership manager

WorkspaceUser.objects_and_identities was named after objects but also returned memberships of trashed workspaces, so callers filtered them by hand. It now follows the existing pair: it leaves trashed workspaces out, and objects_and_identities_and_trash includes them, as objects_and_trash does for people.

* test: state the behaviour of every user type

The table fails when a user type is added and says what has to be decided first. An unknown type is checked to be denied.

* refactor: refuse to say whether a stored user subject is interactive

The answer differs between a person and an identity, so reading it from the stored type would be wrong for one of them. It now raises and points to the specific type.

* refactor: lock the person in membership writes instead of checking the type

Leaving a workspace, removing a member and adding a user lock the user through the people manager, which refuses an identity or an unknown type in the same query. Nothing adds an identity through add_user_to_workspace, so its branch for identities goes. The last admin check compares the membership with the people who are admin, which needs no type check.

* test: leave no rows behind in the legacy authorization migration test

The test left an integration that pointed at a user that didn't exist and a workspace, in the database the migration tests share. Tests that ran after it then failed on the foreign key or on the workspace id. It now uses a real user and empties the two tables.

* docs: describe the subject types and compare the Subject table alternative

ADR 013 is shorter and states that people and identities each have a specific subject type under the stored auth.User type. It compares shared User storage with a Subject table that users and identities would both point to.

* chore: run the legacy run-as cleanup after the agent actions migration

Develop added agent migration 0017, so the cleanup becomes 0018 and depends on it.

* test: leave no rows behind in the legacy agent migration tests

Like the legacy authorization test, these left a workspace in the database the migration tests share, which a later test that creates workspaces with fixed ids collides with.

* fix: write and read the workspace role of an identity in one place

The role assignment API wrote the role of an identity through the membership update of people, which told every member of the workspace about it and stored Builder as MEMBER, while the identities API stored BUILDER and returned the stored value. Both now write through the identity handler, which stores the role like the role of a person, and the role is read with the resolver the workspace members use.

* fix: take no row lock in the membership writes of a person

Leaving a workspace locked the user before the membership while removing or updating a member locks the membership first, so the two could deadlock. The user type never changes and these operations refuse an identity, so the lock protected nothing: they now only check that the user is a person. Leaving no longer locks the admin memberships and removing a member no longer checks for the last admin, as before identities.

* fix: find an identity by its name only in the subject options

The search also matched the email and username, which for an identity hold an internal key, so searching a part of that key returned every identity.

* chore: run the identity migrations after the new ones on develop

Develop added core 0138, integrations 0044 and enterprise 0073, so the identity migrations become core 0139 and 0140, integrations 0045 and enterprise 0074 and depend on them.

* fix: keep the identity of a copied integration only for identity managers

A duplicated application or a restored snapshot kept the identity its Local Baserow integration acts as, without checking the person who made the copy. Restoring a snapshot could so bring back a binding an admin had removed. The copy now keeps the identity only when that person may bind identities, as the Agent application already did, and is otherwise authorized as that person.

* docs: follow the renumbered migrations and the copy rule in the test plan

The test plan named the identity migrations and their tests by their old numbers and still said a copied integration keeps its subject.

* test(agent): run the row trigger tests as an identity

The row trigger tests added on develop created a `core.Agent`, which this
branch removes. They now use an identity user as the Agent's run-as
subject, and the e2e fixture creates it through the identities endpoint.
2026-11-18 08:44:31 +00:00

11 KiB

ADR 011: Represent each agent as a workspace application

Status Proposed
Date 2026-10-12
Issue https://github.com/baserow/baserow/issues/6259
Author Davide Silvestri (@silvestrid)
Contributors Bram Wipjes

Summary

Agents need an ownership model that makes them easy to create, configure and manage. We considered an Agent Builder (option 1), which contains many agents, and an agent application (option 2), which is exactly one agent. We choose the agent application to prioritize a simple starting experience and independent management.

Terms

Term Meaning
Agent A reusable, configured AI agent that callers can invoke.
Identity A workspace-owned nonhuman User with user type identity and a workspace role, as proposed in ADR 013. An agent may run as one.
Caller Anything that references an agent to invoke it, such as a conversation or an automatic job.
Agent Builder (option 1) A workspace application containing many agents, as a database contains tables.
Agent application (option 2) A workspace application of type agent that is exactly one agent.
Related agents Agents a team wants to manage together, such as all support agents.
Lifecycle operations Duplicate, export/import, snapshot, trash and restore.
Workspace integration A planned integration owned by the workspace, so several applications can share its secrets.

Context

Baserow organizes related resources within workspace applications: databases contain tables, Application Builders contain pages, and Automations contain workflows. These applications provide a common boundary for navigation, permissions and lifecycle operations.

Agents need a similar management boundary. Each agent has configuration that callers reference, with permissions controlling who can configure or invoke it. The ownership model must support these needs while keeping creation and everyday management understandable.

Both options can reuse Baserow's application infrastructure, permission system, internal tools and supported backend services. Sharing a management boundary does not by itself authorize sharing integrations, determine execution identity or provide orchestration. The identity remains distinct from the configured agent application.

This record decides the ownership model. Execution, orchestration and workspace integrations are outside its scope. The delivery issue defines release scope.

Options considered

1. Agent Builder

An Agent Builder is a workspace application containing a list of independently configured agents, following the database-and-tables model. Users create the Agent Builder and then create agents within it. The Agent Builder provides a common management boundary, while each agent has its own ID, configuration and role assignments.

This fits users who want to manage related agents together. Roles and shared settings can be applied on the Agent Builder, with exceptions for individual agents where needed. The Agent Builder is also a natural unit for lifecycle operations on related agents. These benefits require a parent/child model, operations to manage the agents inside it, permission-filtered navigation and lifecycle handling for the agents it contains.

2. Agent application

Each agent application is one agent and directly owns its configuration. Users create it through the standard application flow, configure it and open it from its sidebar entry. Callers reference its application ID.

This gives each agent independent roles and lifecycle operations through existing application code. Related agents have separate sidebar entries and role assignments; managing them together requires additional support.

Aspect Agent Builder (option 1) Agent application (option 2) Favours
First agent Create the Agent Builder, then the agent Create the agent Agent application
Many agents One sidebar entry One sidebar entry each Agent Builder
Roles for related agents Set once on the Agent Builder Set on each agent, or workspace-wide Agent Builder
Roles for one agent Override per agent, a new scope Existing application roles Agent application
Duplicate, export, snapshot All related agents together; links between them kept One agent; links between agents need remapping Depends
Build effort Nested agent CRUD, scopes, navigation, lifecycle Existing application infrastructure Agent application
Grouping related agents later Already available Migrate application IDs, roles and references Agent Builder

Decision

Represent each agent as an agent application: a workspace application with application type agent. Each agent application directly owns one agent's configuration and uses application roles and lifecycle operations. Callers reference the application ID. Configuration, invocation and private conversation/run visibility remain separate permission concerns.

Per-agent roles need role-based access control (RBAC), available on the Advanced and Enterprise plans. Without it, members get the same access to every agent, based on their workspace role.

We expect users to start by wanting to build a single agent. Making that agent the application gives them one thing to name, configure, open and manage. Independent roles and lifecycle operations also match the agent as the unit that callers select. Existing application operations support this model with less additional ownership and permission machinery.

The Agent Builder is consistent with databases, Application Builders and Automations, and offers useful shared administration and lifecycle operations. However, we do not yet have established requirements for managing related agents together. We prefer the clear benefits of a simple starting point over immediate structural complexity for possible future needs. We accept that introducing an Agent Builder later may require more work.

Consequences

  • Each agent has a direct creation flow and independent roles and lifecycle operations. More agents also mean more sidebar entries, and administering related agents can involve repeated role assignments, resource-access configuration and settings changes.
  • Agents are referenced by application ID. APIs, callers and exported references will depend on application IDs. A future change to the ownership model must preserve those references or provide migration and compatibility handling.
  • Permissions and configuration ownership become established boundaries. Introducing an Agent Builder later would require rules for inherited roles, shared settings and resource access, including how to resolve conflicts while preserving effective access.
  • Lifecycle operations are per agent. Coordinated duplication, installation, release, restoration or deletion of related agents will need dependency handling and additional lifecycle rules. Grouping agents in the sidebar alone would not provide those guarantees.
  • Snapshots are per agent. Rolling back one agent restores only that agent, without touching the others. Rolling back related agents takes one restore each, and links between the restored agents still point to the originals. An Agent Builder would restore them together and keep those links. As with any Baserow application, a restore creates a new application, so callers keep referencing the original until pointed at the new ID. Restoring a database snapshot works the same way: automations keep referencing the original database.
  • Collaboration can be designed through references between independent agent applications. That would still need authorization and policies for missing dependencies, duplication and deletion; this ownership decision does not prescribe an execution model.
  • Workspace integrations may reduce repeated integration setup under either option. Shared agent settings, resource access and governance remain separate needs and are not solved by changing integration ownership alone.

Introducing an Agent Builder would become more costly once application IDs, caller references, role assignments and lifecycle contracts are in use. We accept that potential migration cost in exchange for simplicity now, while the need to manage related agents together is uncertain.

Revisit triggers

  • Users repeatedly configure the same roles, resource access or settings across related agents and need those changes to propagate to all of them.
  • Repeated integration setup remains costly after workspace integrations are available.
  • Customers need clear management and access boundaries for related agents, similar to the boundaries provided by databases/tables, Application Builders/pages or Automations/workflows.
  • Related agents regularly need to be installed, released, restored or deleted together.