Data Models
Overview
CHAIN-R uses two PostgreSQL databases (one per service), each managed by Alembic and accessed only by its owning service. All inter-service data sharing happens via API calls.
The authoritative, auto-generated model reference is in:
spec/models/database.md — svc-core (postgres-core)
spec/models/database-ai.md — svc-ai (postgres-ai)
This document describes the conceptual domain model.
Domain Entities
Identity & Ownership
All platform resources (agents, knowledge bases, skills, etc.) are owned by one of three resource owner types:
| Owner type | Description |
|---|---|
organisation | A group of users with shared resources |
project | A workspace scoped to a user or organisation |
The User model stores a mirror of the Auth0 identity keyed on auth0_id. Auth0 is the authoritative source for authentication; the local record exists solely for relational ownership of platform resources.
AI Primitives (svc-core)
Agent
A custom AI agent with a fixed identity and behaviour.
| Field | Description |
|---|---|
system_prompt | The agent's fixed instruction set |
model_id | Reference to a registered LLM model (svc-ai UUID) |
config | Runtime overrides (temperature, output format, etc.) |
Agents can be assigned specialist tools, knowledge repositories, and skills via join tables (agent_tools, agent_repositories, agent_skills). Agents only ever integrate whole knowledge repositories — never an individual knowledge base directly — so retrieval context stays grouped, deduplicated, and reusable across agents; see knowledge_repositories and repository_knowledge below. At runtime, svc-ai also injects a set of general tools (web search, URL fetch, calculator, current time) into every agent automatically.
Conversation / Chat Message
conversations links to either an agent or a raw model and stores the full message history. chat_messages stores individual turns with role, content, token count, and an optional execution trace. chat_message_segments stores per-worker output segments for multi-agent skill responses, allowing the UI to display which worker produced which part of the reply.
Skill
A skill is a DAG of worker agents implemented as a LangGraph graph. The graph_definition field stores node ↔ worker mappings and edge connections. Skills are assigned to agents and executed by svc-ai when the agent is prompted.
Key characteristics:
Each node maps to a
WorkerAgentDefinitionregistered in svc-aiEdges define sequential or conditional flow between workers
Built-in skill templates are discoverable via
GET /skills/available
Custom Worker
A customisation of a built-in svc-ai WorkerAgentDefinition. Stores a base_worker slug, an optional system_prompt override, and can have specialist tools assigned via worker_tools. At execution time, svc-ai merges the custom overrides on top of the base definition.
Tool
A named tool with a JSON schema and an implementation reference. Tools are either:
General — auto-injected into every agent at runtime by svc-ai (calculate, websearch, urlfetch, current_time)
Specialist — explicitly assigned to specific agents or workers
Custom tool records in svc-core store the schema and implementation reference. Built-in tools are registered in svc-ai's BUILTIN_TOOLS registry.
Knowledge (svc-core)
A knowledge record defines a knowledge base. The source_type field distinguishes the storage backend:
source_type | Backend | Description |
|---|---|---|
graph | Neo4j | Entity/relationship graph; editable via the graph canvas UI |
knowledge_documents tracks document metadata; actual file content lives in MinIO. After upload, svc-core triggers indexing in Qdrant via svc-ai for semantic search.
A knowledge_repository is a named collection grouping one or more knowledge bases (via the repository_knowledge junction) into a single unit. Repositories — not individual knowledge bases — are what gets granted to an agent (agent_repositories), so a themed group of sources can be attached in one step and reused consistently across multiple agents.
knowledge_citations is the record of use (migration 110): one row per knowledge source (and document) an answer a person received cited, written when the answer is stored from exactly the sources it stores, and stamped with the conversation's workspace as the usage ledger is. A grant is reach; this is what answers actually drew on. Not a user-creatable resource, so no edit history. See the knowledge guide.
Execution (svc-core)
| Entity | Description |
|---|
Tasks (migration 24) and pipelines (migration 92) were removed; neither was reachable.
Evaluation (svc-core)
| Entity | Description |
|---|---|
experiment_variants | Named configurations within an experiment |
experiment_runs | Individual scored execution of one variant |
test_suites | Named dataset of test cases |
test_cases | Single test case (input + expected output) |
test_suite_runs / test_case_results | Execution and result records |
Simulation (svc-core)
| Entity | Description |
|---|---|
simulation_scenarios | Named evaluation scenario within a world |
simulations | Execution run of agents within a world/scenario |
LLM Registry (svc-ai)
svc-ai owns all LLM provider and model metadata in postgres-ai.
| Entity | Description |
|---|---|
llm_models | Model registry per provider (capabilities, cost, context window); a removed model is archived (archived_at), never deleted, so old records keep naming it |
llm_invocations | One traced invocation (execution, resumed segment or platform flow) for usage statistics and activity tracking; names its model as text |
llm_invocation_calls | Every model call within an invocation — provider, exact model, graph node, tokens, latency, outcome, cost |
svc-core references models by the svc-ai UUID (model_id) without cross-database foreign keys. Metadata is resolved at runtime via GET /models/lookup.
Seeded catalogue
Built-in providers and models are plain data in app/db/postgres/providers/registry.py, upserted by the lifespan seeder on every startup. Pricing, limits and the bands below are therefore kept current by editing the registry, not by writing a migration — a migration is only needed to add a column or to delete a row the seeder no longer writes.
Only OpenAI and Anthropic are seeded. They are the two providers supported end to end (API key, LiteLLM route, a lineup somebody has checked); every other provider is registered but disabled and carries no models. The three Groq models migration 2 seeded were never routable and are deleted by migration 17.
Effort and latency bands
llm_models records two comparative bands alongside the hard figures:
| Band | Values | Meaning |
|---|---|---|
latency | fastest · fast · moderate · slower | Comparative speed within this catalogue |
effort is what makes two providers' catalogues comparable, and is the axis the models page filters on. The tiers pair across providers:
| Effort | Anthropic | OpenAI |
|---|---|---|
balanced | Claude Sonnet 5 | GPT-5.6 Terra |
deep | Claude Opus 5 | GPT-5.6 Sol |
frontier | Claude Fable 5.1 | GPT-6 Astra |
That pairing is pinned by tests/db/test_provider_registry.py, which also refuses a band only one provider fills — a tier served by a single provider is a provider filter under another name.
latency is Anthropic's published comparative band; OpenAI publishes no equivalent, so an OpenAI model takes the band of the tier it shares. It is a position in this catalogue, not a measurement — observed per-model latency would need a latency_ms figure on governance_usage, which is the open half of latency-based routing (see docs/guides/governance.md).
knowledge_cutoff is the provider's reliable knowledge cutoff rather than the broader training-data cutoff, stored as a date so it sorts. Providers publish it to the month, so the day is the 1st unless a provider states one.
Per-model request shape
A model's API contract is not fixed across generations, and the penalty for sending a parameter a model has dropped is a 400 rather than a warning — the invocation fails outright. svc-ai/app/services/model_capabilities.py holds those differences as one table consulted by every call path (LiteLLM and LangChain alike), so a model generation is one rule rather than a branch in each caller:
| Rule | Applies to | Why |
|---|---|---|
| Use the Responses API | OpenAI gpt-5*, gpt-6*, o* | Function tools are refused on /v1/chat/completions unless reasoning is off — an agent with tools fails every turn |
Send max_completion_tokens | OpenAI reasoning families | "max_tokens is not supported with this model" |
Forward effort | Models that take one (see the module) | The control that replaced temperature |
An unrecognised provider or model gets the permissive default, so this never turns an unknown model into a broken one. ModelConfig.effort carries the level (low … max), forwarded by svc-core when the model's stored config sets one and dropped by svc-ai for models that take no effort level.
Values come from the providers' own model pages (Anthropic, OpenAI) and should be re-checked against them on a lineup change.
MCP Servers (svc-core)
mcp_servers stores user-configured Model Context Protocol server connections. Each record references a template key (from svc-ai's built-in MCP template registry) and a connection config (credentials, endpoints). Servers can be scoped to a user, organisation, or project.
MCP servers and toolkits are withdrawn for the MVP: the tables are kept, so existing rows stay readable and deletable, but nothing new can be written and no row is forwarded to svc-ai. See API security.