Subject Rights

A person's records spread over every store an agent writes: sessions and their user: tier, memory, artifacts, the audit log, and the stores a deployment adds. adk_core::subject gives a deployment the mechanisms to know whom it holds data about, record what they consented to, and export, erase, or link their data across stores in one operation.

Note: these are mechanisms. Whether a deployment's use of them meets an obligation it has is for the deployment to assess.

Overview

TypeRole
SubjectKind::VisitorA person the deployment knows only by an id it issued, such as a website visitor who has not signed in
VisitorIdThe random id: v: and 64 hex characters, never derived from an address, user agent, or fingerprint
ConsentStoreConsent records per subject and purpose; gates read it before a lasting write
SubjectRegistryEach subject's pseudonym, links, and erasure state — never its data
SubjectDataStoreOne store family's adapter: export and erase a subject's data
SubjectRightsFans export, erase, and link out over the registry, the consent store, and every adapter

The registry holds no index of a subject's records. Stores keyed by (app, user) find a subject by its id, so no second copy of a person's data can drift from the stores that hold it.

Visitors

A visitor is pseudonymous, not anonymous: the id names one person, so the data held under it is that person's. A visitor's run is never authenticated:

CheckA visitor
ReadonlyContext::is_authenticated()false, even when the run carries a RequestContext
Standing approvals and requested callsNever apply, since both need an authenticated user
ApprovalService::decideRefused with approval.visitor_not_allowed

Set ActingConfig::subject_kind (or RunConfigBuilder::subject_kind) to SubjectKind::Visitor for a visitor's run.

use adk_core::subject::VisitorId;
use adk_core::{RunConfig, SubjectKind};

let visitor = VisitorId::generate();
let config = RunConfig::builder().subject_kind(SubjectKind::Visitor).build();
assert_eq!(config.acting.subject_kind, SubjectKind::Visitor);
assert!(visitor.as_str().starts_with("v:"));

ConsentPurpose names what a lasting write is for. The names match AWP's consent scopes one to one, so a signed AWP receipt is the evidence of the record with the same purpose.

PurposeLasting writes it allows
SessionContinuityA conversation kept beyond the visit
PersistentProfileThe user: state tier and long-term memory
AnalyticsUser attributes on telemetry; visit counting
ProactiveOutreachMessages the site starts
PaymentDataStored payment preferences
NewsletterThe site's newsletter
Custom(name)A purpose the deployment defines

A ConsentRecord is live from granted_at until it expires or is revoked. Revoking stops later writes and erases nothing, unless SubjectRights::with_erase_on_revoke names the purpose.

use std::sync::Arc;

use adk_core::subject::{
    ConsentEvidence, ConsentPurpose, ConsentRecord, ConsentStore, InMemoryConsentStore,
    InMemorySubjectRegistry, SubjectRights, VisitorId,
};

# async fn demo() -> adk_core::Result<()> {
let rights = SubjectRights::new(
    Arc::new(InMemorySubjectRegistry::new()),
    Arc::new(InMemoryConsentStore::new()),
)
.with_app("shop")
.with_erase_on_revoke(ConsentPurpose::PersistentProfile);

let visitor = VisitorId::generate().subject();
rights
    .grant(
        ConsentRecord::new(visitor.clone(), ConsentPurpose::PersistentProfile, "2026-10")
            .with_evidence(ConsentEvidence::new("awp.receipt", "6f1c…")),
    )
    .await?;

// Revoking this purpose erases the visitor's data as well.
let revocation = rights.revoke(&visitor, Some(&ConsentPurpose::PersistentProfile)).await?;
assert!(revocation.erasure.is_some());
# Ok(())
# }

ConsentGate decides whether a subject may have something lasting written for a purpose. It gates visitors by default — a user id that parses as a VisitorId — and every human and service after for_every_subject(); agents are never gated. With a registry (with_registry), every writer below also refuses a subject that is being erased.

WriterPurposeWithout consent
adk_session::ConsentGatedSessionServiceSessionContinuityNew sessions live in process memory (or the store given to with_ephemeral); appending to a durable session fails with consent.required
adk_session::ConsentGatedSessionServicePersistentProfileuser: keys are dropped from created state and event deltas
adk_memory::ConsentGatedMemoryServicePersistentProfileAdds are skipped; search returns nothing
authorize_tool_call, through RunConfig::consent_gateThe tool's purpose, from ConsentGate::with_toolThe call is refused with consent.required, audited with policy_ref consent
The runner, through RunConfig::consent_gateAnalyticsThe run's agent.execute span carries no adk.user_id
The runner, through RunConfig::consent_gate—A subject being erased gets no run (subject.erasing)

Revoking consent stops later writes and erases nothing; reads and deletes reach both the durable and the in-memory store, so erasure finds a conversation wherever it lives.

use std::sync::Arc;

use adk_core::RunConfig;
use adk_core::subject::{ConsentGate, ConsentPurpose, InMemoryConsentStore, InMemorySubjectRegistry};
use adk_memory::{ConsentGatedMemoryService, InMemoryMemoryService};
use adk_session::{ConsentGatedSessionService, InMemorySessionService};

let gate = ConsentGate::new(Arc::new(InMemoryConsentStore::new()))
    .with_registry(Arc::new(InMemorySubjectRegistry::new()))
    .with_tool("subscribe_newsletter", ConsentPurpose::Newsletter);

let sessions = ConsentGatedSessionService::new(Arc::new(InMemorySessionService::new()), gate.clone());
let memory = ConsentGatedMemoryService::new(Arc::new(InMemoryMemoryService::new()), gate.clone());
let run_config = RunConfig::builder().consent_gate(gate).build();

Erasure

SubjectRights::erase works in this order, and can be repeated until it completes:

  1. Mark. The subject and every visitor id linked to it move to SubjectState::Erasing; consent gates refuse writes for a subject in that state with subject.erasing.
  2. Revoke. Every live consent record is revoked.
  3. Erase. Each SubjectDataStore erases the subject's data by its StoreSupport.
  4. Consent. The consent records are erased.
  5. Audit. An erasure audit record names the subject's pseudonym and each store's outcome, never the subject's id.
  6. Forget. When no store failed, the registry forgets the subject, its pseudonym, and its links. A failed store leaves the subject Erasing, so a repeat finishes the job.
StoreSupporteraseReport line
HardDeletes before returningerased with counts
Eventual { within }Starts an asynchronous deletescheduled with completesBy
UnsupportedNot called; the data remainsunsupported
UnreachableNot called; the data is held outside the deployment, such as by a model providerunreachable
any, when the call fails—failed with the error code

The report's status is completed when every store erased or scheduled its deletion, and partial otherwise. A store that cannot erase is reported, never skipped. The report names no subject, so it may be kept or logged.

use std::sync::Arc;

use adk_core::subject::{
    ErasureStatus, InMemoryConsentStore, InMemorySubjectRegistry, StoreErasure, StoreSupport,
    SubjectDataStore, SubjectRights, SubjectScope, VisitorId,
};
use adk_core::{Result, async_trait};
use serde_json::{Value, json};

/// The data a provider keeps, which the deployment cannot delete itself.
struct ProviderResponses;

#[async_trait]
impl SubjectDataStore for ProviderResponses {
    fn name(&self) -> &str {
        "provider.responses"
    }

    fn support(&self) -> StoreSupport {
        StoreSupport::Unreachable
    }

    async fn export(&self, _scope: &SubjectScope) -> Result<Value> {
        Ok(json!(null))
    }

    async fn erase(&self, _scope: &SubjectScope) -> Result<StoreErasure> {
        Ok(StoreErasure::default())
    }
}

# async fn demo() -> adk_core::Result<()> {
let rights = SubjectRights::new(
    Arc::new(InMemorySubjectRegistry::new()),
    Arc::new(InMemoryConsentStore::new()),
)
.with_app("shop")
.with_store(Arc::new(ProviderResponses));

let report = rights.erase(&VisitorId::generate().subject()).await?;
assert_eq!(report.status, ErasureStatus::Partial);
assert!(!report.failed(), "nothing to retry: the provider is reported, not retried");
# Ok(())
# }

Export

SubjectRights::export returns the registry records, every consent record, and one entry per store for the subject and its linked visitor ids. A store that cannot list by subject returns subject.unsupported and appears as unsupported; SubjectExport::is_complete says whether every store returned its data.

Linking a visitor to an account

SubjectRights::link(visitor, identified) records that a visitor id belongs to an identified subject. From then on, export and erasure of the identified subject cover the visitor id. Data stays where it is; moving it under the account is a separate, later step.

RuleEnforced by
A visitor id links to one subject, oncesubject.link.consumed from the registry
Only a visitor links, and only to a subject that is not a visitorsubject.link.invalid
Neither subject is being erasedsubject.erasing
The caller proved the visitor's token and a fresh authentication of the identified subject in the same requestThe server, before it calls link

The link is audited under both subjects' pseudonyms.

Backends

The registry and the consent store run on every session backend (adk-session):

BackendFeatureSubject registryConsent store
In-memory (adk-core)—InMemorySubjectRegistryInMemoryConsentStore
SQLitesqliteSqliteSubjectRegistrySqliteConsentStore
PostgreSQLpostgresPostgresSubjectRegistryPostgresConsentStore
RedisredisRedisSubjectRegistryRedisConsentStore
MongoDBmongodbMongoSubjectRegistryMongoConsentStore
Neo4jneo4jNeo4jSubjectRegistryNeo4jConsentStore
FirestorefirestoreFirestoreSubjectRegistryFirestoreConsentStore
Store familyAdapterCrateErases
SessionsSessionSubjectDataadk-sessionEvery session, its events, and the user: tier through delete_all_sessions, on any SessionService

SessionSubjectData::with_support(StoreSupport::Eventual { within }) declares a session service whose deletes complete asynchronously, such as Vertex AI's.

Memory and artifacts

Store familyAdapterCrateExports throughErases through
MemoryMemorySubjectDataadk-memoryMemoryService::export_userMemoryService::delete_user
ArtifactsArtifactSubjectDataadk-artifactArtifactService::list_user (names, versions, MIME types, sizes)ArtifactService::delete_user

Both take with_support for a managed service whose deletes complete asynchronously, such as Vertex AI Memory Bank or a GCS bucket with object versioning or soft delete.

Audit log

PieceCrateDoes
PseudonymousRecorderadk-coreNames covered subjects in new audit records by registry pseudonym
AuditLogSubjectDataadk-coreAdapter over any AuditLogStore: exports the records that name the subject's id and erases them with AuditLogStore::redact, keeping every leaf hash
PseudonymousAuditSinkadk-authPseudonymises AuditEvent::user and on_behalf_of, and drops ip_address

Audit leaves are never removed; a redacted log still verifies. See Audit Log.

RAG

adk_rag::RagSubjectData reaches a subject's chunks in the listed collections of any VectorStore:

SubjectPartitionFinds the subject's chunksErases them with
Tagged { scopes }adk_subject metadata (SUBJECT_METADATA_KEY) equal to one of the subject's user ids, in each listed scopeVectorStore::delete_where
ScopePerUserThe scope Scope::from_parts([app, user]) of each application and user idVectorStore::purge_scope

Declare adk_subject filterable on the collection and set it on every document ingested about a person. The export names each collection and scope with the number of the subject's chunks, since the vector store trait lists no chunk text. A backend whose deletes complete later, or keep earlier table versions until they are cleaned up, declares StoreSupport::Eventual with with_support.

HTTP routes

SurfaceRoutesAuthenticates
AWP edge (adk_server::awp)GET /awp/v2/consent/export, POST /awp/v2/consent/eraseThe visitor's token
adk_server::subject_rights (feature awp)GET /subject/export, POST /subject/erase, POST /subject/linkThe server's RequestContextExtractor

subject_rights_router(SubjectRightsEndpoints::new(rights, tokens)) mounts with ServerBuilder::add_api_routes, so the routes sit under /api. A signed-in caller exports or erases its own data and its linked visitor ids. POST /subject/link needs the visitor's token (AWP-Subject or the __Host-adk_visitor cookie) and a fresh sign-in: the request context's auth_time metadata no older than ten minutes (with_max_sign_in_age). It answers 409 for a visitor id already linked, and clears the visitor cookie.

adk_auth::VisitorTokens signs tokens as v1.{visitor id}.{expiry}.{HMAC-SHA256} with the first of its keys and verifies with all of them, so keys rotate without dropping visitors.

Writing an adapter

A store family implements SubjectDataStore once and proves it with the shared suite:

CaseContract
export_returns_only_the_subjectA seeded subject's export holds data; that of a subject never seeded is empty
erase_removes_only_the_subjectNo read path returns the subject's data afterwards; another subject's data is intact
erase_is_idempotentA repeat succeeds and deletes nothing
erase_covers_linked_idsThe data of linked visitor ids goes too
erase_stays_in_its_applicationsData in an application outside the scope stays
use std::sync::Arc;

use adk_core::async_trait;
use adk_core::conformance::SubjectDataStoreHarness;
use adk_core::subject::SubjectDataStore;

struct Harness;

#[async_trait]
impl SubjectDataStoreHarness for Harness {
    async fn open(&self) -> Arc<dyn SubjectDataStore> {
        todo!("the adapter under test")
    }

    async fn seed(&self, app_name: &str, user_id: &str) {
        todo!("write data for the user through the store's own API")
    }

    async fn visible(&self, app_name: &str, user_id: &str) -> usize {
        todo!("count what every read path returns for the user")
    }
}

adk_core::subject_data_store_conformance_tests!(harness = Harness);

subject_registry_conformance_tests! and consent_store_conformance_tests! prove registry and consent store backends the same way. All three need the conformance feature of adk-core.

Error codes

CodeCategoryMeaning
subject.erasingConflictThe subject is being erased; nothing is written for it
subject.link.consumedConflictThe visitor id is already linked
subject.link.invalidInvalidInputA link names subjects of the wrong kinds
subject.unsupportedUnsupportedA store cannot export or erase by subject
consent.conflictConflictA consent record with the id exists
approval.visitor_not_allowedForbiddenA visitor tried to decide an approval request
consent.requiredForbiddenA write or tool call needs consent the subject has not given
  • Agent Identity — subject kinds and authenticated identity
  • Audit Log — the signed log erasure records are written to
  • AWP Edge — consent receipts at the website edge