Cortex · Prompt and contextContext producers (
Context producers (context)
context is a list of producers: a string, an array of strings, a Message[], or a function (sync or async) of deps, input and the agent that returns one of those. Each string becomes a system message, in the list’s order, after the finish protocol; a function runs once, when the run starts.
type Deps = { programme: { night: string; title: string }[] };
const desk = defineAgent<undefined, Deps>({
id: 'desk',
instructions: 'Answer the member in one sentence.',
context: [
'Doors open thirty minutes before the show.',
({ deps }) => deps.programme.map((show) => `${show.night}: ${show.title}`),
],
});
const preview = await desk.preview('What plays on Sunday?', { llm, deps: { programme } });system Doors open thirty minutes before the show. system 2026-10-23: The Tempest system 2026-10-24: The Tempest system 2026-10-25: Twelfth Night user What plays on Sunday?
[ 'system Doors open thirty minutes before the show.', 'system 2026-10-23: The Tempest', 'system 2026-10-24: The Tempest', 'system 2026-10-25: Twelfth Night', 'user What plays on Sunday?', ]
Runs in this page on the installed package. The input and the expected output are defined by the example.