# public.agent_history

## Columns

| Name | Type | Default | Nullable | Children | Parents | Comment |
| ---- | ---- | ------- | -------- | -------- | ------- | ------- |
| versionId | varchar(36) |  | false | [public.agents](public.agents.md) [public.agent_execution_threads](public.agent_execution_threads.md) [public.agent_task_snapshot](public.agent_task_snapshot.md) |  |  |
| agentId | varchar(36) |  | false |  | [public.agents](public.agents.md) |  |
| schema | json |  | true |  |  | Frozen snapshot of the published AgentJsonConfig |
| tools | json |  | true |  |  | Frozen map of `toolId → { code, descriptor }` at publish time |
| skills | json |  | true |  |  | Frozen map of `skillId → AgentSkill` at publish time |
| publishedById | uuid |  | true |  | [public.user](public.user.md) |  |
| author | varchar(255) |  | false |  |  |  |
| createdAt | timestamp(3) with time zone | CURRENT_TIMESTAMP(3) | false |  |  |  |
| updatedAt | timestamp(3) with time zone | CURRENT_TIMESTAMP(3) | false |  |  |  |

## Constraints

| Name | Type | Definition |
| ---- | ---- | ---------- |
| agent_history_agentId_not_null | n | NOT NULL "agentId" |
| agent_history_author_not_null | n | NOT NULL author |
| agent_history_createdAt_not_null | n | NOT NULL "createdAt" |
| agent_history_updatedAt_not_null | n | NOT NULL "updatedAt" |
| agent_history_versionId_not_null | n | NOT NULL "versionId" |
| FK_8771675f44c58fb40e0feb9ee35 | FOREIGN KEY | FOREIGN KEY ("publishedById") REFERENCES "user"(id) ON DELETE SET NULL |
| FK_87cd5a8da20304b089ea2f83fec | FOREIGN KEY | FOREIGN KEY ("agentId") REFERENCES agents(id) ON DELETE CASCADE |
| PK_65ffcfe7a8e112fb826311fb092 | PRIMARY KEY | PRIMARY KEY ("versionId") |

## Indexes

| Name | Definition |
| ---- | ---------- |
| PK_65ffcfe7a8e112fb826311fb092 | CREATE UNIQUE INDEX "PK_65ffcfe7a8e112fb826311fb092" ON public.agent_history USING btree ("versionId") |
| IDX_87cd5a8da20304b089ea2f83fe | CREATE INDEX "IDX_87cd5a8da20304b089ea2f83fe" ON public.agent_history USING btree ("agentId") |

## Relations

```mermaid
erDiagram

"public.agents" }o--o| "public.agent_history" : "FOREIGN KEY (#quot;activeVersionId#quot;) REFERENCES agent_history(#quot;versionId#quot;) ON DELETE SET NULL"
"public.agent_execution_threads" }o--o| "public.agent_history" : "FOREIGN KEY (#quot;taskVersionId#quot;) REFERENCES agent_history(#quot;versionId#quot;) ON DELETE SET NULL"
"public.agent_task_snapshot" }o--|| "public.agent_history" : "FOREIGN KEY (#quot;versionId#quot;) REFERENCES agent_history(#quot;versionId#quot;) ON DELETE CASCADE"
"public.agent_history" }o--|| "public.agents" : "FOREIGN KEY (#quot;agentId#quot;) REFERENCES agents(id) ON DELETE CASCADE"
"public.agent_history" }o--o| "public.user" : "FOREIGN KEY (#quot;publishedById#quot;) REFERENCES #quot;user#quot;(id) ON DELETE SET NULL"

"public.agent_history" {
  varchar_36_ versionId
  varchar_36_ agentId FK
  json schema
  json tools
  json skills
  uuid publishedById FK
  varchar_255_ author
  timestamp_3__with_time_zone createdAt
  timestamp_3__with_time_zone updatedAt
}
"public.agents" {
  varchar_36_ id
  varchar_128_ name
  varchar_512_ description
  varchar_255_ projectId FK
  json integrations
  json schema
  json tools
  json skills
  varchar_36_ versionId
  timestamp_3__with_time_zone createdAt
  timestamp_3__with_time_zone updatedAt
  varchar_36_ activeVersionId FK
}
"public.agent_execution_threads" {
  varchar_128_ id
  varchar_36_ agentId FK
  varchar_255_ agentName
  varchar_255_ projectId FK
  integer sessionNumber
  integer totalPromptTokens
  integer totalCompletionTokens
  double_precision totalCost
  integer totalDuration
  varchar_255_ title
  varchar_8_ emoji
  timestamp_3__with_time_zone createdAt
  timestamp_3__with_time_zone updatedAt
  varchar_32_ taskId
  varchar_36_ taskVersionId FK
  varchar_128_ parentThreadId
  varchar_36_ parentAgentId
}
"public.agent_task_snapshot" {
  varchar_36_ versionId FK
  varchar_32_ taskId
  boolean enabled
  varchar_128_ name
  text objective
  varchar_128_ cronExpression
  timestamp_3__with_time_zone createdAt
  timestamp_3__with_time_zone updatedAt
}
"public.user" {
  uuid id
  varchar_255_ email
  varchar_32_ firstName
  varchar_32_ lastName
  varchar_255_ password
  json personalizationAnswers
  timestamp_3__with_time_zone createdAt
  timestamp_3__with_time_zone updatedAt
  json settings
  boolean disabled
  boolean mfaEnabled
  text mfaSecret
  text mfaRecoveryCodes
  date lastActiveAt
  varchar_128_ roleSlug FK
}
```

---

> Generated by [tbls](https://github.com/k1LoW/tbls)
