Loading component…
Loading component…
An agent stuck on a decision lays out its options as a tree – consequences of each branch, risky ones marked, its pick highlighted – and you choose a path or write your own
To reuse this local React demo, copy all files from the Code tab into the same folder, then import DecisionTree from ./decision-tree.
import { DecisionTree, type Decision } from "@/components/ui/decision-tree";
const decisions: Decision[] = [
{
id: "dupes",
question: "3 customers have two active subscriptions – how should I proceed?",
context: "All three signed up twice during the checkout outage.",
agent: "Billing agent", model: "Sonnet 5.5", risk: "high",
options: [
{ label: "Cancel the newer ones", pick: true, effects: ["Cancels 3 subscriptions · reversible", "Sends 3 emails"] },
// A flagged part: marked in the leaf, its note shows on hover or with F
{ label: "Refund the newer ones", effects: [["Refunds ", { text: "$147 · not reversible", note: "One charge is two cycles old." }]] },
{ label: "Ask the customers", effects: ["Sends 3 emails · waits for answers"] },
],
},
];
export function Decisions() {
return (
<DecisionTree
decisions={decisions}
onChoose={async (decision, choice) => {
if ("other" in choice) return await agent.instruct(decision.id, choice.other); // its answer shows under your branch
await agent.resume(decision.id, choice.option.label);
}}
/>
);
}| Name | Type | Default | Description |
|---|---|---|---|
| decisions | Decision[] | { id, question, context?, agent, model?, icon?, risk?, options } – everything waiting for a call; decided ones leave, new ids join at the end | |
| options | DecisionOption[] | Per decision, two to four – { label, effects?, pick? }; effects are what the branch leads to, one line each; pick marks the agent's own preference | |
| effects | DecisionText[] | Per option – a string, or an array of strings and { text, note, source? } flags; flags are marked and explain themselves on hover, focus or F | |
| risk | "high" \| "medium" \| "low" | Per decision – high and medium show as a small tag next to the agent | |
| onChoose | (decision, choice) => string \| void \| Promise<string \| void> | A branch was picked ({ index, option }) or an instruction written ({ other }) – for an instruction, return the agent's short answer | |
| allowOther | boolean | true | Shows the "Other…" branch for your own instruction |
| ref | Ref<DecisionTreeHandle> | hover, choose, setOther, send, next, previous, peek | |
| title | string | "Decisions" | Heading of the bar |
| className | string | Extra class on the root |
Built on a container query: wide, the tree runs left to right – question, branches, consequences
Under 640px it runs top to bottom – the branches hang off a rail under the question, each with its consequences below it; nothing scrolls sideways
Dark mode built in: switches when an ancestor (usually <html>) has the class dark or data-theme="dark"