ctx.systemOne asks a System One model typed questions about a state. A System One model, such as TypeSafe’s Jev, reads the state once and answers each question with a typed answer and its probabilities. It writes no text, so its answer is always one your code can read. Use it for a judgement that code can’t make, such as which trade owns an RFI or whether a submittal matches its spec section, and keep the rules that act on the answer in code.
The sandbox holds no key. Each request goes to Forge, which asks TypeSafe under Forge’s own key. TypeSafe sees the state and questions you send. A local development stage (bun run dev) points at the TypeSafe emulator on its port block unless TYPESAFE_API_URL is set, so run bun run dev:emulators beside it (without the emulator running, requests fail with SystemOneUnavailable); the emulator’s answers follow from the request rather than a model.
ctx.systemOne is available in two places:
- A tool’s
ctx.systemOne. - A workflow step’s
s.systemOne, insidestep.do(name, async (s) => ...).
Asking questions
ctx.systemOne takes a state, named questions, and optionally a model. Make each question with noul, choice, or score from @buildr/sdk:
| Question | Asks | Answer |
|---|---|---|
noul(instructions, { true?, false? }) |
Yes or no. The optional criteria say what counts as yes and as no | { type: "noul", noul }, the probability of yes, from 0 to 1 |
choice(instructions, options) |
Which of 1 to 255 options applies. Each key names an option, and its value says when the option applies, or is null for one its name explains |
{ type: "choice", choice, confidence, probabilities }, with a probability for each option |
score(instructions, levels) |
Where the state falls on 2 to 10 ordered levels, lowest first | { type: "score", score, confidence, probabilities }. score is the levels’ places, from 0, weighted by their probabilities, so it can fall between two levels |
The state and each question’s wording can be text, or JSON whose structure the model reads too. A request asks 1 to 64 questions, and the model reads the state once for all of them, so ask related questions in one request rather than one request each.
import { choice, defineExtension, noul, object, string, tool } from "@buildr/sdk";
const triage = tool(
{
description: "Routes an RFI to the trade that owns it",
input: object({ body: string(), specSection: string() }),
},
async (ctx, { body, specSection }) => {
const { answers, model } = await ctx.systemOne({
state: { rfi: body, specSection },
questions: {
trade: choice("Which trade owns the RFI?", {
structural: null,
mep: "Mechanical, electrical, and plumbing",
civil: "Site work and utilities",
}),
blocking: noul("Does the RFI block work in the field?"),
},
});
const confident = answers.trade.confidence > 0.8;
return {
trade: confident ? answers.trade.choice : "needs review",
urgent: answers.blocking.noul > 0.9,
model,
};
},
);
export default defineExtension({}, { tools: { triage } });The result has answers, by question name, model, the versioned model that answered, and usage.inputTokens, the tokens the model read. In TypeScript, each answer’s type follows its question’s, so answers.trade.choice is "structural" | "mep" | "civil".
Models
model is jev-latest by default, TypeSafe’s newest stable Jev. An alias moves when TypeSafe ships a new Jev, so its answers can change with no change to your code. To keep thresholds that you tuned against one version, name that version, such as jev-1.14.0. TypeSafe lists its models at docs.typesafe.ai/models.
Workflows
A workflow step’s recorded result keeps the answers its work read, so a replay doesn’t ask again.
Limits
| Limit | Value | What happens past it |
|---|---|---|
| Questions | 1 to 64 per request | The request rejects with a TypeError |
| Requests per call | 50 per tool call, and 50 per workflow step | Further requests reject with a TypeError |
| Requests per org | About 600 a minute across the org’s extensions and CI checks | The request rejects with SystemOneRateLimited |
| State length | Jev reads 32,000 tokens of state and one question | The request rejects with SystemOneRefused |
Errors
A request that Forge or TypeSafe refuses rejects with a ForgeError, as a ctx.forge call does:
| Error | Status | Meaning |
|---|---|---|
SystemOneRefused |
400 | The model won’t answer the request as it stands: the model doesn’t exist, a question is malformed, or the state is too long |
AiBrowserLimitReached |
402 | The org has spent all of the AI and browser allowance its plan includes this month |
SystemOneRateLimited |
429 | The org’s extensions asked too often this minute, or TypeSafe is answering more slowly; a later try may succeed |
SystemOneUnavailable |
503 | No answer came back: the stage has no System One model, or TypeSafe is down, overloaded, or didn’t answer in time |