Skip to content

Structured Memory

Typed records for every org.

Updated

Every org gets Structured Memory: typed records that agents structure and store before the data goes elsewhere. In the code and in agent.yml it is the data store (data:, _schemas/, data.* tools). Agents use it to keep structured state between runs, for example leads seen, invoices filed or tickets scored. Records show in the console Structured Memory screen with provenance per field.

Schemas

A schema is one _schemas/{name}.yml file. _schemas/ inherits like _apis/: an agent sees the schemas of its ancestors, and a child schema with the same name replaces the parent one.

name: lead # singular snake_case. Immutable after the first deploy.
label: Lead
label_field: email
fields:
  email: { type: email, required: true, unique: true }
  company: { type: text }
  score: { type: number }
  stage: { type: select, options: [new, qualified, lost] }
  notes: { type: long_text }
Key Rule
name Matches [a-z][a-z0-9_]{0,62}. Immutable after the first deploy. To rename, create a new schema.
label Display name. Required.
label_field The field that names a record in the console. It cannot be a relation field.
fields.{name}.type text, long_text, number, currency, boolean, date, datetime, email, phone, url, address, select, multi_select, relation.
fields.{name}.required Boolean.
fields.{name}.unique Boolean. data.upsert matches on a unique field. A relation field cannot be unique.
fields.{name}.options select and multi_select only.
fields.{name}.to relation only, and required there. The _schemas table of the same project that the field links to.
fields.{name}.many relation only. Default false: the value is one record id. true: a list of at most 50 ids.
fields.{name}.access relation only. none (default), takes or gives: which way access passes through the link. Read linked records.
fields.{name}.filing.auto_at relation with access: takes only. A number from 0.5 to 1, default 0.9. Read filing queues.
access Who can open, change and delete the records of the table. Read Who can open records.

A push can add a field. A push that removes or retypes a field fails lint with schema_breaking. A change of to or many on a relation field is breaking too. To change a field type, add a new schema.

A relation field links a record to records of another table:

name: lab_result
label: Lab result
label_field: title
fields:
  title: { type: text, required: true }
  intake: { type: relation, to: intake, access: takes } # people who can open the intake can open this result

A live deploy creates or updates each _schemas definition in the org store. A preview does not. If the org already has a definition with the same name that Run did not create (for example a Workspace one), the deploy fails as a whole with “the org has a definition with this name already”.

Access

Schemas and records belong to the org, not to the agent. Two agents on the same schema see the same records. data: in agent.yml sets what each agent can do:

data:
  read: [lead, '*'] # "*" reads every Run schema of the org, not Workspace ones
  write: [lead]
  create_schemas: false

The data grant caps the agent. The access block of each schema sets which records each person can open, change and delete. A turn that a person sends opens only the records that this person can open, also through links. Read Who can open records.

Tools

Tool Needs What it does
data.schemas read Lists the definitions and their JSON Schema, drafts included.
data.query read Filter, sort, limit and offset. A relation field filters on record ids.
data.get read One record by id. A relation value shows as { id, label }.
data.create, data.update, data.delete write A unique-field collision returns data_conflict.
data.upsert write Create or update on a unique field. The common case for enrichment agents.
data.define_schema create_schemas: true Creates a draft schema during the run. See below.
data.file write on a queue table, read on its target table Files a document of a queue table, or asks the queue team. Read filing queues.

Each write emits a data.changed event and carries provenance: run id, agent, deployment SHA and origin: agent.

End users

When the run request carries metadata.end_user, the run stamps it on every record it creates. data.query and data.get then return only records of that end user and org-wide records. An update keeps the owner of the record.

{ "input": "Score this lead", "metadata": { "end_user": "u_42" } }

A record without end_user is org-wide and visible to every run. A query with end_user: null from a run that has an end user answers forbidden.

Schemas during a run

An agent with create_schemas: true can call data.define_schema with the same shape as a _schemas file. The tool is absent when the agent has protection: public, and lint refuses that combination with public_create_schemas. The platform then:

  1. Commits _schemas/{name}.yml on the branch data/{name} and opens the pull request Define schema {name} in the repo.
  2. Creates the schema in the org store.
  3. Marks the schema draft, with an automatic merge 7 days later.

A retry after a failure finds the same pull request, so the schema does not fork.

A draft schema works like a stable one, at once and in later runs. The run that defined it can read and write it. Every agent with the name (or "*") in data.read or data.write can use it.

Status Meaning
draft Usable. The pull request is open.
stable The pull request is merged, by a human or automatically after 7 days without objection.
archived A human closed the pull request. The schema and its records are archived.

data.define_schema on a name that exists answers schema_exists with the current definition. This includes a schema made in Workspace or in another repo of the org.

Merge or close a draft early in the console Structured Memory screen, or on its pull request. A merge runs the same checks as any publication: lint, then a merge at the reviewed SHAs, then a deploy of the merge commit. The schema becomes stable only after that deploy succeeds. A failed automatic merge retries after 24 hours. A pull request that you merge or close directly in git also changes the status, at the next schema list.

The Structured Memory screen lists stable, draft and archived schemas, with the record count of each archived one. You can delete an archived schema and its records permanently. A draft or stable schema cannot be deleted there: close the draft first, or remove a stable schema with a push that deletes its _schemas file.

Type to search…

↑↓ navigate↵ selectEsc close