Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion agent-claude-sdk/tests/fixtures/server-instructions.json

Large diffs are not rendered by default.

7 changes: 6 additions & 1 deletion app/src/lib/copilot/a2ui-guidance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@ import { GENERATIVE_UI_DESIGN_SKILL } from "./generative-ui";
* interface delegated it, drew an HTML iframe, or followed the iframe's grey chart rules on native
* charts. Builds on #1764, which gave it to the starter Personal Assistant alone.
*
* WHEN IS THE STANDING RULE'S, NOT A LIST. Its first line used to name cases (alternatives, a plan,
* adjusting assumptions; a quick answer, a fact, a confirmation). It now says only the principle the
* answer-format rule says (`COMPONENT_GUIDANCE` in `shared/bot-prompt.ts`): draw an interface when
* it makes the answer clearer or more useful. The rest is how to make one worth using.
*
* EVERY BOT, OVER AG-UI. It travels as an ordinary entry of the run's AG-UI `context`, beside the
* `render_ui` guide it qualifies, so a built-in Bot and any Bot a person connects are told the same
* thing the same way. Nothing here asks which Bot the run belongs to, and nothing may: a built-in Bot
Expand All @@ -19,7 +24,7 @@ import { GENERATIVE_UI_DESIGN_SKILL } from "./generative-ui";
*
* This is a prompt, written for a model, not copy a person reads.
*/
export const NATIVE_UI_GUIDANCE = `Choose the presentation that makes the answer easier to understand or use, without waiting for the person to ask for particular components. Use an interface when exploring alternatives, following a plan or adjusting assumptions benefits from it. Keep a quick answer, a single fact or a confirmation in ordinary prose. Do not ask permission just to choose the format.
export const NATIVE_UI_GUIDANCE = `Choose the presentation that makes the answer clearer or more useful, without waiting for the person to ask for particular components, and do not ask permission just to choose the format.

When an interface is useful, draw native A2UI in this conversation with render_ui and target chat. Use only the components, functions and schemas in the supplied catalog. An interactive answer should use the native controls and bindings, rather than an HTML or HtmlView substitute or a static gallery chart. Purpose-built tools still handle the real records and actions they are granted for. Render the requested interface here; research with your tools when needed rather than delegating its presentation to another Bot.

Expand Down
6 changes: 3 additions & 3 deletions app/tests/checklist-card.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ test("the model is told a checklist is for work to tick off, not for presenting
const description = checklist?.description.toLowerCase() ?? "";
expect(description).toContain("tasks");
expect(description).toMatch(/not .*(information|findings|recommendations)/);
// The guidance every Bot reads no longer sends "a list" to a checklist.
// The guidance every Bot reads sends no kind of answer to a checklist: what a checklist is for is
// said on the checklist's own tool, above, and the guidance says only when a component helps.
const guidance = COMPONENT_GUIDANCE.replace(/\s+/g, " ");
expect(guidance).not.toMatch(/a list or a plan: a checklist/i);
expect(guidance).toMatch(/recommendations[^.]*never a checklist/i);
expect(guidance).not.toMatch(/checklist/i);
});
9 changes: 7 additions & 2 deletions mobile/src/shared-copy/tool-name.js
Original file line number Diff line number Diff line change
Expand Up @@ -5148,7 +5148,7 @@ var FOLLOW_UP_TOOL = "follow_up";
var STOP_TOOL = "stop";
var DELEGATING_GUIDANCE = [
"You are the person's point of contact, and the work they ask for runs in task threads of your own, so this conversation stays short. Each turn, answer the person in words, in exactly one of these two ways, never both:",
"- Answer directly only a short ask: a question you can answer in a few sentences from what you know or from this conversation, without a tool of an app, a computer or a search. A greeting, a thank-you or an 'ok' is a short ask too: answer it in a few words of your own, never with only an emoji. A question about whether you can do something is a short ask: answer yes or no from the tools you hold and offer to do it, and until the person says to, start no task and read none of their data. What the person asks for about this conversation itself is yours to do in this reply too, never a task's: a routine, a follow-up or a reminder, or a goal is set up here with the tool for it, so it belongs to this conversation and what it produces arrives here. Draw a component when that answer has structure, as you always do, and say in a sentence or two what it shows and what stands out: a component goes with the answer's words, never in place of them, and the words never repeat what it shows.",
"- Answer directly only a short ask: a question you can answer in a few sentences from what you know or from this conversation, without a tool of an app, a computer or a search. A greeting, a thank-you or an 'ok' is a short ask too: answer it in a few words of your own, never with only an emoji. A question about whether you can do something is a short ask: answer yes or no from the tools you hold and offer to do it, and until the person says to, start no task and read none of their data. What the person asks for about this conversation itself is yours to do in this reply too, never a task's: a routine, a follow-up or a reminder, or a goal is set up here with the tool for it, so it belongs to this conversation and what it produces arrives here. Draw a component when it makes that answer clearer or more useful, as you always do, and say in a sentence or two what it shows and what stands out: a component goes with the answer's words, never in place of them, and the words never repeat what it shows.",
`- Hand the other work the person asked for to a task with ${DELEGATE_TOOL}, without waiting to be asked to hand it off: making something (a chart, a table, a sheet, a report, a plan, a document), even from figures they gave you and even when you could make it in one step, working through figures, research, reading or browsing, a comparison, anything in an app or on a website, and every action such as an order, a purchase, a booking or a message. The test is what the work takes: a request that needs an app's tool, a computer, a search, or something made for the person is a task's, however small it looks; you do not do it here. Only what they asked for: never start a task for work nobody asked for, such as the job a question was about. First write one short line saying what you will do ("On it, I'll chart those figures and sum them up."), then call ${DELEGATE_TOOL} in the same reply with a brief that stands on its own: every figure, name, link and constraint from this conversation the work needs. Brief all of what they asked for, never narrowed to what you guess can be reached, such as only what is public: the task asks the person for an app it needs. Give a time window as the person did, counted back from now: "the last day" is the last 24 hours, never "since" yesterday's date, which a search reads as whole calendar days and so takes in older items. Do not do the work yourself as well, and do not wait for it. When it finishes, its result, with every chart, table or card it drew, is posted in this conversation; if it needs the person, this conversation says so with a link to the thread where it waits. Once ${DELEGATE_TOOL} has answered, your reply is finished: the task's card already shows it and the way into its thread, so write nothing more and call nothing else.`,
`When the person adds to or changes work a task of this conversation already has, or answers what it reported ("tell it to also check the parking", "it should use last year's figures", "ask it to add a chart", "it's private"), pass it on with ${FOLLOW_UP_TOOL}, naming that task by the taskId its ${DELEGATE_TOOL} answer gave: that is the whole of your reply's work, so never start a new task for it and never do it yourself, even when the task has finished. A new piece of work is a new task, even when they ask for it with "also" or "too" while another task runs ("Also write a guide for US customers", "and one for the UK too"): another thing to make or do on its own (another guide, report, chart, search, booking or message) goes to its own task with ${DELEGATE_TOOL}, so they can follow it and stop it on its own, never into a task that is making something else. ${FOLLOW_UP_TOOL} is only for changing or adding to the work a task is already doing. When they ask you to stop one ("stop the Figma one", "never mind the venue", "cancel that"), call ${STOP_TOOL} for it, and only for the task they mean: when the work they name is not one of this conversation's tasks (you did it yourself, or it was never started), stop nothing, never a different task in its place, and tell them so. Either way, first write one short line saying what you did ("I've told it to check the parking too."), then call the tool in the same reply, and once it has answered your reply is finished.`,
`Only when the person asks for the link to a task's thread, call ${LINK_TOOL} and give them the link as a Markdown link, exactly as it comes back.`
Expand All @@ -5157,7 +5157,7 @@ var DELEGATING_GUIDANCE = [
`);
var BRIEF_FRAME = [
"This is a task from your conversation with the person, handed into a thread of its own so that conversation stays short. Do the work here with your tools, as you would there, and finish it.",
"When the answer has structure (figures, a comparison, a list of items, a plan, a record), draw it with a component, as you always do: call the component in a step of its own, once the results it shows have come back and before you write your answer. Never write out what a component already shows: no Markdown table or list of the same rows beside it, and never a component's data as text.",
"When a component makes the answer clearer or more useful, draw it, as you always do: call the component in a step of its own, once the results it shows have come back and before you write your answer. Never write out what a component already shows: no Markdown table or list of the same rows beside it, and never a component's data as text.",
"Your last message is your report. It alone is posted back in that conversation, with the components you drew; everything you say before it stays in this thread, where the person can open it. The person reads that conversation, not this thread, so the report must stand on its own: give the answer itself in words, with the facts, figures, dates and quotes they asked for, never only that you found them. A component goes with those words, never in place of them: when you drew one, say in a sentence or two what it shows and what stands out. Size it to the question: what you found, or what you did and its link, in a sentence or two when the ask was simple, then anything you could not confirm, a sentence each. Leave out how you got there: no account of what you searched, read, checked, resolved or chose, no list of steps, and no offer of more work.",
"Write it to the person: never mention this brief, and never say where a component sits, such as 'the chart above'. Name people and channels the way the person would, never by an app's id or its markup for one.",
"The task:"
Expand All @@ -5171,6 +5171,11 @@ var WHOLE_ANSWER_FRAME = [
var POSTED_BACK = "Lead with the result and say plainly anything you could not confirm. Your answer and any components you draw are posted back in that conversation as they are; what you say while you work stays in this thread.";
var BRIEF_PREFIXES = [
BRIEF_FRAME,
[
BRIEF_FRAME[0],
"When the answer has structure (figures, a comparison, a list of items, a plan, a record), draw it with a component, as you always do: call the component in a step of its own, once the results it shows have come back and before you write your answer. Never write out what a component already shows: no Markdown table or list of the same rows beside it, and never a component's data as text.",
...BRIEF_FRAME.slice(2)
],
WHOLE_ANSWER_FRAME,
[
WHOLE_ANSWER_FRAME[0],
Expand Down
74 changes: 74 additions & 0 deletions shared/bot-prompt.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,80 @@ const WITHOUT_SEARCH = computerGuidance({ search: false });
/** One sentence can span a source line break, which is not a fact about what the Bot is told. */
const flat = (text: string) => text.toLowerCase().replace(/\s+/g, " ");

/**
* When a Bot draws a component: the principle, once, for every Bot, and no list of cases.
*
* It first listed a case per kind of answer and ordinary answers became cards; then it said
* Markdown by default, and the default model wrote a comparison of three options out in text in two
* runs of three. What a component is for is said on its own tool; the rule says only when to draw.
*/
describe("when a Bot draws a component", () => {
const builtIn = workingGuidance({ untrusted: "Untrusted." }).join("\n\n");
// A connected Bot's standing role: one text for every run, so no tools are known.
const standingRole = workingGuidance({
brought: true,
untrusted: "Untrusted.",
}).join("\n\n");

test.each([
["a built-in Bot", builtIn],
["a connected Bot's standing role", standingRole],
])(
"%s is told it once, straight after the sources rule it defers to",
(_, prompt) => {
expect(prompt.split(COMPONENT_GUIDANCE)).toHaveLength(2);
expect(prompt).toContain(
`</sources>\n\n<answer_format>\n${COMPONENT_GUIDANCE}\n</answer_format>`,
);
// No other section says when to draw by kind of answer.
expect(flat(prompt)).not.toContain("has structure");
},
);

test("says the principle: draw when it makes the answer clearer or more useful, text otherwise", () => {
const [principle] = COMPONENT_GUIDANCE.split("\n\n");
expect(flat(principle ?? "")).toContain(
"would make the answer clearer or more useful than text, draw it, without waiting to be asked; otherwise answer in text.",
);
// Neither of the defaults it has swung between.
for (const swing of [
"by default",
"materially",
"explicitly asks",
"when in doubt",
"whenever an answer has structure",
])
expect(flat(COMPONENT_GUIDANCE)).not.toContain(swing);
});

test("lists no cases: no kind of answer, no component, no example", () => {
const said = flat(COMPONENT_GUIDANCE);
for (const kind of [
"chart",
"table",
"checklist",
"record card",
"notice",
"choice",
"comparison",
"a plan",
"a list",
"trend",
"email",
"explanation",
"such as",
"for example",
"e.g.",
])
expect(said).not.toContain(kind);
// Tool names are camelCase or snake_case; the tools on a turn vary per Bot and grant.
expect(COMPONENT_GUIDANCE).not.toMatch(/\b[a-z]+[A-Z]\w*\b|\b\w+_\w+\b/);
// A principle in a sentence or two, and the rule about drawing once: two short paragraphs.
expect(COMPONENT_GUIDANCE.split("\n\n")).toHaveLength(2);
expect(COMPONENT_GUIDANCE.length).toBeLessThan(600);
});
});

describe("computerGuidance", () => {
test.each([
["with a search tool", WITH_SEARCH],
Expand Down
Loading
Loading