n8n/docs/generated/sqlite-schema/agent_execution_message_links.md
Jaakko Husso ab3048f48d
feat(core): Link delegated Agents executions and store cache tokens in columns (no-changelog)
Replace the `usageDetails` JSON column with top-level columns on
`agent_execution`:

- `cacheReadTokens` and `cacheWriteTokens` store the prompt-cache tokens
  of the `finish` usage. Both are subsets of `promptTokens`.
- `parentExecutionId` and `rootExecutionId` link a delegated run to the
  execution that delegated it and to the top of its tree. Both reference
  `agent_execution.id` with ON DELETE SET NULL and have an index.

The sub-agent runner sets the links from the parent execution id in the
parent persistence metadata. Background jobs pass it on dispatch. A
resumed child keeps the links of its first execution.

Remove the sub-agent usage roll-up. Each delegated run already records
its own execution, so the system usage route now returns each turn with
its descendants (found through `rootExecutionId`) and their sum.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-09 02:48:36 +03:00

3.8 KiB
Generated

agent_execution_message_links

Description

Table Definition
CREATE TABLE "agent_execution_message_links" ("executionId" varchar(36) NOT NULL, "messageId" varchar(36) NOT NULL, "direction" varchar(6) NOT NULL, "position" integer NOT NULL, "createdAt" datetime(3) NOT NULL DEFAULT (STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW')), CONSTRAINT "CHK_agent_execution_message_links_direction" CHECK ("direction" IN ('input', 'output')), CONSTRAINT "FK_e78f470a036d01f9e395d53bb59" FOREIGN KEY ("executionId") REFERENCES "agent_execution" ("id") ON DELETE CASCADE, CONSTRAINT "FK_be7d0a2fd1360c9fa09baf84f60" FOREIGN KEY ("messageId") REFERENCES "agents_messages" ("id") ON DELETE CASCADE, PRIMARY KEY ("executionId", "messageId"))

Columns

Name Type Default Nullable Children Parents Comment
createdAt datetime(3) STRFTIME('%Y-%m-%d %H:%M:%f', 'NOW') false
direction varchar(6) false
executionId varchar(36) false agent_execution
messageId varchar(36) false agents_messages
position INTEGER false

Constraints

Name Type Definition
- CHECK CHECK ("direction" IN ('input', 'output'))
- (Foreign key ID: 0) FOREIGN KEY FOREIGN KEY (messageId) REFERENCES agents_messages (id) ON UPDATE NO ACTION ON DELETE CASCADE MATCH NONE
- (Foreign key ID: 1) FOREIGN KEY FOREIGN KEY (executionId) REFERENCES agent_execution (id) ON UPDATE NO ACTION ON DELETE CASCADE MATCH NONE
executionId PRIMARY KEY PRIMARY KEY (executionId)
messageId PRIMARY KEY PRIMARY KEY (messageId)
sqlite_autoindex_agent_execution_message_links_1 PRIMARY KEY PRIMARY KEY (executionId, messageId)

Indexes

Name Definition
IDX_10fe500ee8877351841799369b CREATE UNIQUE INDEX "IDX_10fe500ee8877351841799369b" ON "agent_execution_message_links" ("executionId", "direction", "position")
IDX_be7d0a2fd1360c9fa09baf84f6 CREATE INDEX "IDX_be7d0a2fd1360c9fa09baf84f6" ON "agent_execution_message_links" ("messageId")
sqlite_autoindex_agent_execution_message_links_1 PRIMARY KEY (executionId, messageId)

Relations

erDiagram

"agent_execution_message_links" |o--|| "agent_execution" : "FOREIGN KEY (executionId) REFERENCES agent_execution (id) ON UPDATE NO ACTION ON DELETE CASCADE MATCH NONE"
"agent_execution_message_links" |o--|| "agents_messages" : "FOREIGN KEY (messageId) REFERENCES agents_messages (id) ON UPDATE NO ACTION ON DELETE CASCADE MATCH NONE"

"agent_execution_message_links" {
  datetime_3_ createdAt
  varchar_6_ direction
  varchar_36_ executionId PK
  varchar_36_ messageId PK
  INTEGER position
}
"agent_execution" {
  BOOLEAN acceptsSteering
  TEXT attachments
  TEXT author
  INTEGER cacheReadTokens
  INTEGER cacheWriteTokens
  INTEGER completionTokens
  REAL cost
  datetime_3_ createdAt
  INTEGER duration
  TEXT error
  TEXT failureSummary
  varchar_16_ hitlStatus
  varchar_36_ id PK
  varchar_255_ model
  VARCHAR_36_ parentExecutionId FK
  INTEGER promptTokens
  VARCHAR_36_ rootExecutionId FK
  varchar_32_ source
  datetime_3_ startedAt
  varchar_16_ status
  datetime_3_ stoppedAt
  varchar_2_ storedAt
  varchar_128_ threadId FK
  TEXT timeline
  INTEGER totalTokens
  datetime_3_ updatedAt
  TEXT userMessage
}
"agents_messages" {
  TEXT author
  TEXT content
  datetime_3_ createdAt
  varchar_36_ id PK
  TEXT modelContent
  DATETIME modelContextAt
  TEXT origin
  varchar_255_ resourceId
  varchar_36_ role
  varchar_255_ threadId FK
  varchar_36_ type
  datetime_3_ updatedAt
}

Generated by tbls