Asking a person
What a program leaves to a person, gathered in one place, only where the answer changes something; and a person's way to say none of it fits.
In Quick start's step 8 the card asks Sam about its tone itself, above its buttons. Sam's app has more to show than one card: a printed copy for the dinner, a copy on Grandma's phone, perhaps other cards later. The app should gather every question in one place, ask only what makes a difference, and let Sam answer that none of the possibilities fits.
You will learn
- How
ask: ['human']leaves a choice to a person - How
intent.questions()gathers what to ask - How to ask only in the contexts where the answer changes something
- How
intent.rejectAllsays that none of the possibilities fits
What to ask
The card takes System One's tone when it leads by 0.5, and leaves it to a person otherwise. Sam's app, above the card, lists the questions:
/** @jsxImportSource @reintent/core */
import { choices, host, useChoose, World, type Id } from '@reintent/core';
export const TONES = ['warm', 'funny', 'formal'] as const;
export type Tone = (typeof TONES)[number];
export const TONE: Id = { of: 'card', name: 'tone' };
export const LOOK: Record<Tone, { background: string; accent: string }> = {
warm: { background: '#fdebd3', accent: '#b5562b' },
funny: { background: '#fff2a8', accent: '#7a4fd6' },
formal: { background: '#f1eee8', accent: '#2b2b2b' },
};
export function title(tone: Tone) {
if (tone === 'formal') return 'Many happy returns, Grandma.';
if (tone === 'warm') return 'Happy 90th birthday, Grandma!';
return '90 laps around the sun, Grandma!';
}
export function Card({ tone }: { tone: Tone }) {
return host('div', {
style: {
maxWidth: 380,
padding: 24,
borderRadius: 12,
background: LOOK[tone].background,
color: '#3a2a1c',
},
children: [
host('h1', { style: { color: LOOK[tone].accent }, children: title(tone) }),
host('p', { children: 'Wishing you a wonderful day.' }),
host('p', { style: { textAlign: 'right', fontStyle: 'italic' }, children: '— Sam' }),
],
});
}
export function Grandma() {
const tone = useChoose(choices<Tone>(...TONES), {
...TONE,
defaultValue: 'warm',
question: 'Which tone suits a birthday card for Grandma, turning 90?',
ask: ['model', 'human'],
});
return <Card tone={tone} />;
}
export default function App() {
// System One's tone when it leads by 0.5; otherwise, a person's to answer.
return (
<World minMargin={0.5}>
<Grandma />
</World>
);
}
Starting…
Starting…
Nothing logged.
At first warm leads by 0.65, and there is nothing to ask. Press It is for a formal family dinner.: formal leads by 0.30, and the app asks which tone. Pick one. The answer is a decision like any other, and the question is gone.
A choice whose ask has 'human' uses its default while it cannot settle, and its read says ask: true. With 'model' before it, the person is asked once System One has answered. intent.questions() evaluates the program and returns a Question for each such choice: its id, name, kinds (the possibilities) and, for a judged choice, dist, what System One thinks. The card only marks the tone as left to a person, and the app chooses how to ask. The app holds the Intent, so it calls intent.questions itself, with { judge: 0 } while React renders, so that drawing the list asks System One nothing; useReintent(intent, questions) works the list out again whenever the Intent changes.
Only where it matters
The printed card can be handwritten or typed, and the phone draws every card in its own font. The app shows both copies, and asks about both:
/** @jsxImportSource @reintent/core */
import { choices, createContext, host, useChoose, useContext, World } from '@reintent/core';
export const TONES = ['warm', 'funny', 'formal'] as const;
export type Tone = (typeof TONES)[number];
export const LETTERINGS = ['handwritten', 'typed'] as const;
export type Lettering = (typeof LETTERINGS)[number];
/** Which copy of the card: the one printed for the dinner, or the one on Grandma's phone. */
export type Copy = 'printed' | 'phone';
export const CopyContext = createContext<Copy>('Copy', { key: (c) => c });
export const LOOK: Record<Tone, { background: string; accent: string }> = {
warm: { background: '#fdebd3', accent: '#b5562b' },
funny: { background: '#fff2a8', accent: '#7a4fd6' },
formal: { background: '#f1eee8', accent: '#2b2b2b' },
};
export function title(tone: Tone) {
if (tone === 'formal') return 'Many happy returns, Grandma.';
if (tone === 'warm') return 'Happy 90th birthday, Grandma!';
return '90 laps around the sun, Grandma!';
}
export function Card() {
const copy = useContext(CopyContext);
const tone = useChoose(choices<Tone>(...TONES), {
of: 'card',
name: 'tone',
defaultValue: 'warm',
question: 'Which tone suits a birthday card for Grandma, turning 90?',
ask: ['model', 'human'],
});
// The phone draws every card in its own font: only the printed copy uses the lettering.
const lettering = useChoose(choices<Lettering>(...LETTERINGS), {
of: 'card',
name: 'lettering',
defaultValue: 'typed',
ask: ['human'],
});
const font = copy === 'printed' && lettering === 'handwritten' ? 'cursive' : 'inherit';
return host('div', {
style: { padding: 16, borderRadius: 12, background: LOOK[tone].background, color: '#3a2a1c' },
children: [
host('small', { children: copy }),
host('h2', { style: { color: LOOK[tone].accent, fontFamily: font }, children: title(tone) }),
host('p', { style: { textAlign: 'right', fontStyle: 'italic', margin: 0 }, children: '— Sam' }),
],
});
}
export default function App() {
return (
<World minMargin={0.5}>
<Card />
</World>
);
}
Starting…
Starting…
Nothing logged.
intent.questions([PRINTED, PHONE]) takes a list of contexts and asks in each. For every choice that would ask, it evaluates the program once per possibility, and keeps the question only where the results differ. Both copies read the lettering, and only the printed one draws it, so the lettering is asked with where: ['printed']. After the sentence, the tone is asked in both, where: ['printed', 'phone'], the keys of the contexts.
Asking can ask System One
In a context nobody has shown yet, whether a judged choice asks depends on System One's answer there. intent.questions(contexts, { judge }) sends at most judge new requests across all the contexts, 4 unless given. { judge: 0 } uses only the answers already in hand, and marks a question partial when one was missing.
None of these
Sam looks at warm, funny and formal and wants none of them. Press It is for a formal family dinner., then None of these:
/** @jsxImportSource @reintent/core */
import { choices, host, useChoose, World, type Id } from '@reintent/core';
export const TONES = ['warm', 'funny', 'formal'] as const;
export type Tone = (typeof TONES)[number];
export const TONE: Id = { of: 'card', name: 'tone' };
export const LOOK: Record<Tone, { background: string; accent: string }> = {
warm: { background: '#fdebd3', accent: '#b5562b' },
funny: { background: '#fff2a8', accent: '#7a4fd6' },
formal: { background: '#f1eee8', accent: '#2b2b2b' },
};
export function title(tone: Tone) {
if (tone === 'formal') return 'Many happy returns, Grandma.';
if (tone === 'warm') return 'Happy 90th birthday, Grandma!';
return '90 laps around the sun, Grandma!';
}
export function Card({ tone }: { tone: Tone }) {
return host('div', {
style: {
maxWidth: 380,
padding: 24,
borderRadius: 12,
background: LOOK[tone].background,
color: '#3a2a1c',
},
children: [
host('h1', { style: { color: LOOK[tone].accent }, children: title(tone) }),
host('p', { children: 'Wishing you a wonderful day.' }),
host('p', { style: { textAlign: 'right', fontStyle: 'italic' }, children: '— Sam' }),
],
});
}
export function Grandma() {
const tone = useChoose(choices<Tone>(...TONES), {
...TONE,
defaultValue: 'warm',
question: 'Which tone suits a birthday card for Grandma, turning 90?',
ask: ['model', 'human'],
});
return <Card tone={tone} />;
}
export default function App() {
// System One's tone when it leads by 0.5; otherwise, a person's to answer.
return (
<World minMargin={0.5}>
<Grandma />
</World>
);
}
Starting…
Starting…
Nothing logged.
intent.rejectAll(id) says that no possibility fits. The choice cannot settle, with reason: 'none', the same as when constraints leave nothing (What a person says). It writes nothing, and the card stays as it is. With no World around it to say otherwise, it goes to whoever listens with intent.onUnresolved, here a line in What happened. With nobody listening, the intent asks the model's reprogram for a new program on its own, and it comes back as a proposal for a person to accept. In Quick start's step 9 Sam asks for the reprogramming by clicking; here nobody has to (When no possibility fits).
Recap
ask: ['human']leaves an unresolved choice to a person; meanwhile it uses its default.intent.questions(contexts?)lists what to ask, only where the possibilities give different results.- Each
Questionhasid,name,kinds,distandwhere;{ judge }caps the System One requests asking makes. intent.rejectAll(id)says none fits: the choice is unresolved withreason: 'none', for whoever can change the possibilities.
Last updated on
Edit on GitHub