A program from one sentence
Sam says one sentence. System Two writes the card's program from it in one call and weighs what it leaves open; System One weighs again only when Sam says more.
In Quick start the card's tone, its possibilities and its question are written by hand. Sam never sees any of that. All Sam says is “A birthday card for Grandma. She’s turning 90.” Here the app starts with a card that knows only who it is for and who it is from, and System Two writes the rest of the program from that sentence.
You will learn
- How one sentence becomes the card's program:
intent.reprogram({ prompt })from a program that knows only its input - How System Two weighs what it leaves open, as the prior in
choices([{ value, weight }]) - How
askWhenToldlets that prior stand until Sam says more, so the program starts with one call - What System Two is told, and what the intent checks in what it writes
The card before anything is said
/** @jsxImportSource @reintent/core */
import { host, type Content } from '@reintent/core';
/** Who the card is for, and from: the root's input. */
export type Person = { to: string; age: number; from: string };
/** The card as it is before anyone asked for anything: who it is for, and who it is from. */
export function Card(p: Person) {
return host('div', {
style: {
padding: 20,
borderRadius: 12,
background: '#f6f1ea',
color: '#3a2a1c',
fontFamily: 'Georgia, serif',
},
children: [
host('h1', { style: { margin: '0 0 12px', fontSize: 26 }, children: `For ${p.to}, ${p.age}` }),
host('p', { style: { margin: 0, textAlign: 'right', fontStyle: 'italic' }, children: `— ${p.from}` }),
],
});
}
/** The program before Sam says anything: the card, and the app's own controls (children) above it. */
export default function App(p: Person & { children?: Content }) {
return host('div', {
style: { display: 'grid', gap: 10 },
children: [p.children, <Card to={p.to} age={p.age} from={p.from} />],
});
}
Starting…
Starting…
Nothing logged.
App.intent.tsx is the card before anyone asked for anything. It reads the root's input, to, age and from, and draws “For Grandma, 90” and “— Sam”. It leaves nothing open.
In App.tsx, Sentence sends Sam's sentence to System Two once, with intent.reprogram({ prompt }), and accepts what comes back at once. Sam asked for this card, so the sentence is Sam's yes. A later change to the program is a proposal that waits for Sam, as in Reprogramming the intent.
One call
Open Words.intent.tsx. System Two wrote it from the sentence, and the sandbox plays its recorded answer. It leaves the tone open, and weighs it from what Sam said:
const tone = useChoose(
choices<Tone>([
{ value: 'warm', weight: 0.6 },
{ value: 'playful', weight: 0.25 },
{ value: 'formal', weight: 0.15 },
]),
{
of: 'card',
name: 'tone',
defaultValue: 'warm',
question: `“A birthday card for Grandma. She’s turning 90.” What tone should the card for ${p.to}'s ${p.age}th birthday have: warm, playful, or formal?`,
ask: ['model'],
askWhenTold: true,
},
);The weights are the program's prior: System Two read the sentence when it wrote them. The question carries Sam's words, for System One to read later. The words on the card are a useGenerate with uses: { tone }, so each tone gets its own message.
In the timeline, the card starts with two requests, both to System Two: the program, and the message for warm. System One is not asked.
System One waits for Sam
askWhenTold: true says the prior already answers the question while nobody has told the intent anything. Until then, System One is not asked, and the tone reads its prior: warm, from Code, the program's own layer.
Click She loves jokes. It goes into the intent's facts, the judgment's stamp changes, and System One weighs the tone: playful .55. System Two writes the playful message. Click It’s for a formal event. instead: formal .60, and a formal message. Click it again to take it back. The facts are empty again, the prior stands again, and nothing is asked.
Without askWhenTold, the same program asks System One as soon as it is shown: the question System Two has just answered, on the same inputs.
What System Two is told
model.reprogram gets the request with Sam's sentence in prompt. The model is given the program now, a short account of the API, and what this program is for:
This program is written from nothing but what the person said, in one call. Leave open what the person did not say, as choices; weigh each yourself from what they said, as the prior in choices([{ value, weight }]). Give each a question that carries the person's words, with ask: ['model'] and askWhenTold: true, so System One weighs it again only once they say more. Write what nobody can list (the words of the message) with useGenerate.
The model.reprogram that recorded this card, and the one in live:card below, type-check what the model writes and run it once on the root's input before answering with it. The errors go back to the model, and it writes again, as an agent works with a compiler. choices refuses a weighted possibility with anything more than value and weight, such as a question put there by mistake: without that, the whole object would become a value, and its weight would be lost.
With a model of your own
pnpm --filter reintent-site live:card runs this card against a live model instead of the recordings: any OpenAI-compatible server, such as llama.cpp's llama-server (--url http://localhost:8080/v1), or --claude for the models the recordings use. It prints the tone, who wrote it, and the card, after the sentence and after each thing Sam says, with how many times each model was called.
Recap
- One sentence is a reprogram of a program that knows only its input. Sam asked for it, so the app accepts the first program at once.
- System Two leaves open what Sam did not say, and weighs it as the prior in
choices([{ value, weight }]). askWhenToldlets that prior answer until Sam tells the intent something; then System One weighs, as with any judgment.- The
model.reprogramhere checks what System Two writes before answering with it, and gives the errors back to it.
Last updated on
Edit on GitHub