Reintent

Asking System One

What a judgment asks, what its answer is kept for, and what the card shows while a new answer is on its way.

System One's tone for Grandma's card is an answer about Grandma, turning 90. Sam's manager gets a birthday card too, and the same question about her needs another answer. Asking again on every evaluation, though, would keep the card waiting on a model for nothing. The intent needs to know what each answer was given for.

You will learn

  • What a question on a choice sends to the model, and what the model answers
  • How uses names what a judgment reads
  • How what a person says becomes part of the inputs
  • What the card shows between a change and the new answer

The question and the answer

In Quick start a recorded model answers. Here System One is written in place, so you can see what it is asked:

/** @jsxImportSource @reintent/core */
import { choices, host, useChoose, 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 default function App() {
  // A question for System One, and what it reads.
  const tone = useChoose(choices<Tone>(...TONES), {
    ...TONE,
    defaultValue: 'warm',
    question: 'Which tone suits this birthday card?',
    ask: ['model'],
    uses: { to: 'Grandma', age: 90 },
  });
  return <Card tone={tone} />;
}
ChoicesC

Starting…

Realizationλ

Starting…

What happened

Nothing logged.

A choice with a question and ask: ['model'], and uses for what System One reads, is a question for System One, and useChoose reads it like any other choice. When the card is shown, the intent sends the question to the judge of the model given to createIntent({ model }). The request is a ModelRequest: the prompt, the possibilities as kinds, the uses, and the sentences said (facts). The answer is a weight for each possibility, System One's belief, kept in its own layer (Who answers a choice).

The judge line is logged once. The second evaluation reads the same inputs, so the intent uses the answer it has. Change the weights in index.intent.tsx, and the card follows.

uses: what a judgment reads

Two cards, one question, one component:

/** @jsxImportSource @reintent/core */
import { choices, host, useChoose } from '@reintent/core';

export type Person = { to: string; age: number; from: string; relation: string };
export const TONES = ['warm', 'funny', 'formal'] as const;
export type Tone = (typeof TONES)[number];

export const GRANDMA: Person = { to: 'Grandma', age: 90, from: 'Sam', relation: 'Sam’s grandmother' };
export const LEE: Person = { to: 'Ms. Lee', age: 50, from: 'Sam', relation: 'Sam’s manager at work' };

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(p: Person, tone: Tone) {
  if (tone === 'formal') return `Many happy returns, ${p.to}.`;
  if (tone === 'warm') return `Happy ${p.age}th birthday, ${p.to}!`;
  return `${p.age} laps around the sun, ${p.to}!`;
}

/** One question for every card; what it reads (uses) is this card's person. */
export function useTone(p: Person) {
  return useChoose(choices<Tone>(...TONES), {
    of: `card-${p.to}`,
    name: 'tone',
    defaultValue: 'warm',
    question: 'Which tone suits this birthday card?',
    ask: ['model'],
    uses: { to: p.to, age: p.age, relation: p.relation },
  });
}

export function Card(p: Person) {
  const tone = useTone(p);
  return host('div', {
    style: { padding: 16, borderRadius: 12, background: LOOK[tone].background, color: '#3a2a1c' },
    children: [host('h2', { style: { color: LOOK[tone].accent, margin: 0 }, children: title(p, tone) })],
  });
}

export default function App() {
  return host('div', {
    style: { display: 'grid', gap: 8 },
    children: [<Card {...GRANDMA} />, <Card {...LEE} />],
  });
}
ChoicesC

Starting…

Realizationλ

Starting…

What happened

Nothing logged.

uses names the inputs of the judgment, here who the card is for, their age, and how they know Sam. The request carries them to System One, and the answer is kept for exactly those inputs. Grandma's card gets warm, 0.62 to 0.30; Ms. Lee's, formal, 0.70 to 0.25. What happened shows both requests, each with its uses.

Put in uses everything the answer depends on

An answer is kept for its inputs. When Card gets other props but uses leaves out the one that matters, the inputs look the same, and the old answer is used where it no longer fits.

What was said

Say “It is for a formal family dinner.” in the sandbox above. A sentence said to the intent (intent.tell) is about the whole program, so it is part of every judgment's inputs. Both cards are asked again, and both turn formal.

Take the sentence back. The inputs are what they were, and so are the answers: both cards return to the earlier ones, with no new judge line in What happened.

While the new answer is on its way

A real model takes a moment. Here System One answers after 0.8 seconds:

/** @jsxImportSource @reintent/core */
import { choices, host, useChoiceStatus, 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 default function App() {
  // The tone, and whether System One's answer was given for what was said before.
  const { value: tone, stale } = useChoiceStatus(choices<Tone>(...TONES), {
    ...TONE,
    defaultValue: 'warm',
    question: 'Which tone suits a birthday card for Grandma, turning 90?',
    ask: ['model'],
  });
  return host('div', {
    style: {
      maxWidth: 380,
      padding: 24,
      borderRadius: 12,
      background: LOOK[tone].background,
      color: '#3a2a1c',
      opacity: stale ? 0.6 : 1,
    },
    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' }),
      stale && host('small', { children: 'Thinking the tone over again…' }),
    ],
  });
}
ChoicesC

Starting…

Realizationλ

Starting…

What happened

Nothing logged.

Until the first answer arrives, the card uses its default, and then it turns warm. Now say “It is for a formal family dinner.” in the panel. The sentence changes the inputs, so System One is asked again, and meanwhile the card keeps the newest earlier answer, warm, marked stale. useChoiceStatus gives the same stale, so the card dims and says it is thinking the tone over. When the new answer arrives, the card turns formal. Take the sentence back, and the earlier answer is used again at once. Say it again, and the formal answer is already there.

Only an answer for the same uses stands in

An earlier answer stands in when it was given for the same uses, under other sentences or another program. A card for someone else waits for its own answer, on the layers below.

Recap

  • question with ask: ['model'] asks System One, reading uses; the model's judge answers with weights.
  • uses names the inputs of a judgment; the answer is kept for exactly those.
  • What a person says to the intent is part of every judgment's inputs.
  • Inputs that change ask again; inputs that come back reuse the earlier answer.
  • Between a change and the new answer, the earlier answer for the same uses stands in, marked stale.

Last updated on

Edit on GitHub