Ask a language model the same question twice and you can get two different answers.
That is not a bug. It is how the thing works. Every word it writes is a likely next word, chosen from a spread of possibilities. That is why it can write a sales email, read a contract and argue a point. It is also why it should never be the one deciding who is allowed to send $5,000 from the company account.
Some questions have to be guessed. Some questions have to be worked out.
In ONE we hold to one rule: the language model is the only step that guesses. Everything that must be right every time is worked out by the database, from facts, the same way every time, with a reason you can read.
That second kind of thinking has a name. It is automated reasoning, and TypeDB does it in a language called TypeQL.
What reasoning means
You store facts. The database works out facts you never stored.
Ann owns the company Acme. Acme contains a team called Sales. Nobody wrote down “Ann controls Sales.” Nobody needs to. The database concludes it, because an owner of a group controls everything inside it, at any depth.
Add a new team inside Sales tomorrow and Ann controls that too, the moment it exists. No one updates a permissions table. No one forgets to.
That is the whole idea. Write the rule once. Let the database apply it to every fact, now and later.
The building blocks
TypeQL has three kinds of thing.
Entities are things that exist on their own: a person, a company, a product.
Relations are facts that connect things: an employment, a sale, a membership. Every relation names the roles involved.
Attributes are values: a name, a price, a date.
You describe your business with them once. This is called the schema:
define
entity person, owns name, plays employment:employee;
entity company, owns name, plays employment:employer;
relation employment, relates employer, relates employee;
attribute name, value string;
Read it out loud. A person has a name and can be an employee. A company has a name and can be an employer. An employment has an employer and an employee.
From that moment, the database knows what makes sense. Try to record a company as an employee and it refuses. Ask for something that cannot exist and you get an error with a reason, before anything runs.
Subtypes let one kind of thing be a special case of another:
define
entity contractor sub person;
Now every question about people includes contractors. Reports written last year cover them. Permissions written last year apply to them. You can even ask the database about its own model: match $t sub person; returns every kind of person it knows about.
Relations can have many sides, and their own attributes. A sale can have a buyer, a seller, a product and an agent in one fact. In ONE, a connection between two actors is a relation called path, and it carries a strength and a resistance. Work across the connection that succeeds adds strength. Work that fails adds resistance. The connection itself remembers how well it has worked.
Functions: questions written once
In TypeQL, reasoning lives in functions. A function is a question you write once, store in the database, and call from anywhere.
Here is the simplest kind, a list. “Which connections have failed more than they have worked?”
fun toxic_paths() -> { path }:
match
$p isa path, has strength $s, has resistance $r;
$r > $s; $r >= 10.0;
return { $p };
Every function below is copied from the schema ONE runs in production, with the comments taken out.
A business rule as a decision table
Here is a function that classifies a connection into one of five states. It is a business rule, written as a table the database applies:
fun path_status($p: path) -> string:
match
$p has strength $s, has resistance $r, has traversals $t;
{ $r > $s; $r >= 10.0;
let $status = "toxic"; }
or { $s >= 50.0; not { $r > $s; $r >= 10.0; };
let $status = "highway"; }
or { $s >= 10.0; $s < 50.0; $t < 10; not { $r > $s; $r >= 10.0; };
let $status = "fresh"; }
or { $s > 0.0; $s < 5.0; not { $r > $s; $r >= 10.0; };
let $status = "fading"; }
or { not { $r > $s; $r >= 10.0; };
not { $s >= 50.0; };
not { $s >= 10.0; $s < 50.0; $t < 10; };
not { $s > 0.0; $s < 5.0; };
let $status = "active"; };
return first $status;
In plain words. More failures than successes, and at least ten of them: toxic. Fifty or more successes: a highway. Strong but new: fresh. Almost forgotten: fading. Anything else: active.
Look at the not { ... } blocks. Each state explicitly rules out the ones above it, so exactly one state can ever be true. The answer cannot depend on luck or on the order the database happens to read things. Our router uses these states to decide where work goes, and it gets the same answer for the same connection every time.
Saying what is missing
“Which tasks in this plan can start right now?” means: the outstanding tasks that nothing open is blocking.
fun ready-tasks($plan: thing) -> { thing }:
match
let $t in outstanding-tasks($plan);
not { (blocker: $b, blocked: $t) isa blocks;
$b has task-status $bs;
{ $bs == "open"; } or { $bs == "blocked"; } or { $bs == "picked"; }; };
return { $t };
The not is doing the reasoning. The database checks, for each task, that no unfinished blocker exists. And notice the first line: it calls another function, outstanding-tasks. Functions build on functions.
Following a chain to any depth
“Who can this agent reach, through any number of hops?”
fun reachable($from: actor) -> { actor }:
match
{ (source: $from, target: $to) isa path; $to isa actor; }
or
{ let $mid in reachable($from);
(source: $mid, target: $to) isa path; $to isa actor; };
return { $to };
The function calls itself. Either there is a direct connection, or there is someone already reachable who connects onward. That one rule covers two hops, ten hops, any number. Change one condition, require every hop to be strong, and you have trust that travels only through connections that have actually worked.
Questions like this are hard to write in SQL. You need a special recursive form, and it is easy to get subtly wrong. In TypeQL it is the ordinary way to write a function.
The whole permission system in two functions
This is the part that matters most to anyone running a company.
ONE’s groups nest: a company contains teams, teams contain projects. The rule is that an owner anywhere above you controls you. First, a function that walks up the tree:
fun self-or-ancestors-of($g: group) -> { group }:
match
{ $n isa group, has gid $id; $g has gid $id; }
or
{ let $n in ancestors-of($g); };
return { $n };
Then “does this person control this group?”:
fun controls($a: actor, $g: group) -> boolean:
match
let $node in self-or-ancestors-of($g);
(group: $node, member: $a) isa membership, has member-role "owner";
let $ok = true;
return first $ok;
And “may this person or agent take this action here?”:
fun can($a: actor, $g: group, $action: string) -> boolean:
match
{
let $node in self-or-ancestors-of($g);
(group: $node, member: $a) isa membership, has member-role "owner";
} or {
(grantee: $a, scope: $g) isa delegation, has role-action $da;
$da == $action;
};
let $ok = true;
return first $ok;
Two ways to say yes. You own this group or something above it. Or someone gave you a specific permission, for this exact group only.
That second branch is deliberate. A delegation names one group, scope: $g, and is never walked up or down the tree. Give an agency permission to manage one client and it cannot reach that client’s other teams. The rule is in the function, where anyone can read it, not in a hundred if statements across an app.
Why this matters when agents do the work
An AI agent in ONE can hold a wallet, take a task and act for a person. So the question “may it?” comes up constantly.
The agent never decides. It asks can. The database walks the facts and answers yes or no, the same way for an app, a command line or an agent. We generate our agent tools from the schema, so an agent calling ready-tasks or can is calling the same function our own code calls.
A prompt is text, and text never carries authority. An agent can be tricked by a clever message. A function cannot. It does not read the message. It reads who owns what.
Every answer can also be explained. “Yes, because you are an owner of Acme, which contains this team.” That is an audit trail you get for free, because the reasoning is the data.
What changed in TypeDB 3
Older versions of TypeDB had rules. A rule fired on its own and filled in derived facts in the background, whether or not anyone asked.
TypeDB 3 replaced rules with functions. A function runs when something calls it, against the data as it is at that moment. You lose the automatic part. You gain three things: you can read exactly what runs, functions can call each other and themselves, and an answer is never stale, because nothing was precomputed.
For a business that has to explain its decisions, that trade is worth it.
What it costs
Reasoning happens when you ask. A function that walks a deep tree does real work each time. Our database runs in Virginia, and I am often in Thailand, so we keep a copy of the data in memory near the user and answer the common questions from there. The database stays the source of truth and the judge of every write.
The language has sharp edges. There is no if/then/else. You write every branch out and rule the others out with not, which is why path_status looks the way it does. return first true is rejected; you bind a value first, as controls does. We keep a guide for our agents, and most of it is traps we hit once.
We declared more than we deployed. In September we compared the functions in our files with the functions in the live database. 64 of 152 were missing. That was our process, not TypeDB, and we now check our code against a snapshot of the live schema.
Models know little TypeQL. Without examples, they mostly write it wrong. With a guide, examples and the database’s error messages to learn from, they write it well. The errors are the teacher.
Let the model guess
A good company needs both kinds of thinking. The model reads, writes, drafts and suggests. It is wonderful at that.
The database decides who may act, what can start and which connection to trust. It works those out from facts, the same way every time, and tells you why.
Let the model guess. Let the database decide.
This is the second of two posts. The first: When your AI is wrong, does your database tell you? ONE is at one.ie.