chain-rdeveloper portal
build

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:

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 typeDescription
organisationA group of users with shared resources
projectA 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.

FieldDescription
system_promptThe agent's fixed instruction set
model_idReference to a registered LLM model (svc-ai UUID)
configRuntime 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 WorkerAgentDefinition registered in svc-ai

  • Edges 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_typeBackendDescription
graphNeo4jEntity/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)

EntityDescription

Tasks (migration 24) and pipelines (migration 92) were removed; neither was reachable.

Evaluation (svc-core)

EntityDescription
experiment_variantsNamed configurations within an experiment
experiment_runsIndividual scored execution of one variant
test_suitesNamed dataset of test cases
test_casesSingle test case (input + expected output)
test_suite_runs / test_case_resultsExecution and result records

Simulation (svc-core)

EntityDescription
simulation_scenariosNamed evaluation scenario within a world
simulationsExecution run of agents within a world/scenario

LLM Registry (svc-ai)

svc-ai owns all LLM provider and model metadata in postgres-ai.

EntityDescription
llm_modelsModel registry per provider (capabilities, cost, context window); a removed model is archived (archived_at), never deleted, so old records keep naming it
llm_invocationsOne traced invocation (execution, resumed segment or platform flow) for usage statistics and activity tracking; names its model as text
llm_invocation_callsEvery 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:

BandValuesMeaning
latencyfastest · fast · moderate · slowerComparative 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:

EffortAnthropicOpenAI
balancedClaude Sonnet 5GPT-5.6 Terra
deepClaude Opus 5GPT-5.6 Sol
frontierClaude Fable 5.1GPT-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:

RuleApplies toWhy
Use the Responses APIOpenAI 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_tokensOpenAI reasoning families"max_tokens is not supported with this model"
Forward effortModels 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.