chain-rdeveloper portal
build

Database Models

Auto-generated from source on 2026-10-30 15:00 UTC. Do not edit manually — run make spec to regenerate.

SQLAlchemy ORM models — modules/svc-ai/app/db/postgres/models.py.


Provider

A registered LLM provider (e.g. OpenAI, Anthropic). Stores connectivity config and enabled/disabled state.

  • Table: providers

  • Mixins: DateMixin.Updated

Columns

ColumnTypeNullablePKNotes
nameEnumNo
display_nameStringNo
is_defaultBooleanNo
base_urlStringYes
is_enabledBooleanNo
configJSONYes

Relationships

  • models → LLMModel


LLMModel

A specific model offered by a provider. Stores capability flags, token limits, pricing, and default config.

  • Table: llm_models

  • Mixins: FKMixin.Provider.Child, DateMixin.Updated

Columns

ColumnTypeNullablePKNotes
model_nameStringNo
display_nameStringYes
descriptionTextYes
is_defaultBooleanNo
is_recommendedBooleanNo
is_chatBooleanNo
is_embeddingBooleanNo
is_visionBooleanNo
is_availableBooleanNo
context_windowIntegerYes
max_output_tokensIntegerYes
input_cost_per_tokenNumericYes
output_cost_per_tokenNumericYes
cache_read_cost_per_tokenNumericYes
cache_write_cost_per_tokenNumericYes
cache_write_1h_cost_per_tokenNumericYes
long_context_thresholdIntegerYes
long_context_input_multiplierNumericYes
long_context_output_multiplierNumericYes
data_regionEnumYes
effortEnumYes
latencyEnumYes
knowledge_cutoffDateYes
configJSONYes
archived_atDateTimeYes

Relationships

  • provider → Provider

  • conversations → Conversation

  • invocations → LLMInvocation


Conversation

A multi-turn LLM conversation session.

userid is the requesting user from svc-core — stored as plain text, no FK constraint. externalagent_id optionally links to a svc-core Agent; again no FK constraint.

  • Table: conversations

  • Mixins: FKMixin.LLMModel.NullableChild, DateMixin.Updated

Columns

ColumnTypeNullablePKNotes
user_idTextNo
external_agent_idUUIDYes
titleStringYes
total_input_tokensIntegerNo
total_output_tokensIntegerNo
total_tokensIntegerNo

Relationships

  • model → LLMModel

  • messages → ChatMessage


ChatMessage

A single message within a Conversation. token_count is stored per-message for accurate billing and context management.

  • Table: chat_messages

  • Mixins: FKMixin.Conversation.Child, DateMixin.Sent

Columns

ColumnTypeNullablePKNotes
roleEnumNo
contentTextNo
token_countIntegerNo

Relationships

  • conversation → Conversation


LLMInvocation

One traced invocation — an execution, a resumed segment of one, or a platform flow — and the model calls it made. Tracks token usage, latency, cost, and outcome for observability and billing. conversation_id is a soft cross-service reference to svc-core's conversations.id (no FK constraint).

`provider / model_name name the model the request asked for (an agent's or a prompt's configured model, a generation flow's model), or the one model every call used when the request named none. They are stored as text so the row says which model it was even when the catalogue does not list it, or no longer does; model_id is the catalogue link when there is one. Null only when the calls used several models and the request named none — calls` says exactly which did what, one row per model call.

  • Table: llm_invocations

  • Mixins: FKMixin.LLMModel.NullableChild, DateMixin.Created

Columns

ColumnTypeNullablePKNotes
conversation_idUUIDYes
user_idUUIDYes
workspaceStringYes
core_invocation_idUUIDYes
purposeStringYes
output_previewTextYes
prompt_tokensIntegerNo
completion_tokensIntegerNo
total_tokensIntegerNo
latency_msIntegerYes
statusEnumNo
error_detailTextYes
request_configJSONYes
estimated_cost_usdNumericYes
providerStringYes
model_nameStringYes

Relationships

  • model → LLMModel

  • calls → LLMInvocationCall


LLMInvocationCall

One model call within a traced invocation, as the usage meter saw it.

Recorded where the call happened, against the model that was actually built for it — so a graph run whose system nodes run on one model and whose skill nodes pin others says which node called which model, and a retry or a runtime fallback shows the attempt that failed as well as the one that answered. `provider / model_name are required — every call site names the model it built, and the meter logs one that does not; model_id` is the catalogue link when the model is listed.

`estimated_cost_usd` is None when the call could not be priced (or failed), never zero for "unknown".

  • Table: llm_invocation_calls

  • Mixins: FKMixin.LLMModel.NullableChild, DateMixin.Created

Columns

ColumnTypeNullablePKNotes
invocation_idUUIDNo
sequenceIntegerNo
providerStringNo
model_nameStringNo
kindStringNo
nodeStringYes
stepStringYes
pass_indexSmallIntegerYes
prompt_tokensIntegerNo
completion_tokensIntegerNo
cache_read_tokensIntegerNo
cache_write_tokensIntegerNo
reasoning_tokensIntegerNo
latency_msIntegerYes
statusEnumNo
error_detailTextYes
estimated_cost_usdNumericYes
pricingJSONYes

Relationships

  • invocation → LLMInvocation


ToolInvocation

A single tool call made during an agent execution.

Records the tool name, input arguments, raw output, execution outcome, and latency — the primary data source for tool observability and debugging.

conversation_id is a soft cross-service reference to svc-core's conversations.id (no FK constraint).

executioncontext captures free-form metadata about the execution that produced this call (e.g. skillid, graph node name, agent name) so invocations can be grouped or filtered by workflow.

  • Table: tool_invocations

  • Mixins: DateMixin.Created

Columns

ColumnTypeNullablePKNotes
conversation_idUUIDYes
user_idUUIDYes
workspaceStringYes
core_invocation_idUUIDYes
tool_nameStringNo
input_argsJSONYes
raw_outputTextYes
latency_msIntegerYes
statusEnumNo
error_detailTextYes
execution_contextJSONYes
reportJSONYes

Relationships

  • citations → ToolCitation


ToolCitation

A single source citation extracted from a ToolInvocation's output.

Each citation captures the tool that produced it, the raw source reference (URL or document name), a human-readable title, and an ordinal index that preserves the order in which sources appeared in the tool response.

source_type distinguishes URLs (clickable links) from knowledge-base documents (filename references) and other custom citation kinds, allowing the frontend to render each type appropriately.

collection is only populated for queryknowledgebase invocations and records which RAG collection the document was retrieved from.

  • Table: tool_citations

  • Mixins: FKMixin.ToolInvocation.Child

Columns

ColumnTypeNullablePKNotes
indexIntegerNo
source_typeEnumNo
sourceTextNo
titleTextNo
collectionStringYes
relevance_scoreFloatYes

Relationships

  • invocation → ToolInvocation


WorkerAgentDefinition

A reusable worker agent definition — the building block for skill graphs.

Definitions describe an agent's role, system prompt, default model, and default tools. They are referenced by name in skill graphdefinitions so that graphs stay lightweight (no embedded configs) while remaining fully customisable via configoverrides at the node level.

is_builtin=True entries are seeded on startup and should not be deleted by regular users.

  • Table: worker_agent_definitions

  • Mixins: DateMixin.Created

Columns

ColumnTypeNullablePKNotes
nameStringNo
display_nameStringNo
descriptionTextNo
roleEnumNo
system_promptTextNo
default_model_configJSONNo
tools_enabledBooleanNo
mcp_serversJSONNo
default_toolsJSONNo
input_schemaJSONNo
output_schemaJSONNo
tagsJSONNo
is_builtinBooleanNo

AgentMemory

What an agent keeps of one person between conversations — written by memorywrite, recalled by memoryread (`app/memory`).

externalagentid and userid are soft cross-service references to svc-core — no FK constraints so svc-ai remains independently deployable. conversationid links the memory to the conversation that produced it.

`kind is an episode (one turn) or a curated memory (fact, preference, goal) written only from the person's quoted words, kept in evidence`. A corrected memory is superseded rather than deleted, so its history stays readable; recall leaves out superseded and expired rows.

  • Table: agent_memories

  • Mixins: DateMixin.Created

Columns

ColumnTypeNullablePKNotes
external_agent_idUUIDYes
user_idTextNo
conversation_idUUIDYes
memory_keyStringNo
contentTextNo
created_atDateTimeNo
kindStringNo
evidenceTextYes
workspaceStringYes
embeddingARRAYYes
embedding_keyStringYes
expires_atDateTimeYes
superseded_atDateTimeYes
superseded_byUUIDYes
confirmed_atDateTimeYes
recall_countIntegerNo
last_recalled_atDateTimeYes

SpendCounter

Model spend in one period — a UTC day or calendar month — kept for the deployment's spending ceiling (`app.services.spend_guard`).

One row per period, `day:2026-10-08 or month:2026-10`, incremented by every metered call. The guard keeps the running total in memory and writes here so that a restart does not forget what the day has spent.

  • Table: spend_counters

Columns

ColumnTypeNullablePKNotes
cost_usdNumericNo
updated_atDateTimeNo