affectUI › Components › Agents
Decision Loop
How an AI decision becomes an action – the event, the model's typed choice and score, plain-code rules that tick or cross, then the action or a person, and back to learn.
Part of affectUI Pro. Install: npx shadcn@latest add https://www.affectui.com/r/decision-loop.json · Import from @/components/ui/decision-loop
When to use
- Showing how an AI decision turns into an action – the event, the model's typed choice and score, the rules in between, where it goes
- Products where a model decides and plain code guards it – refunds, routing, approvals, triage – and people want to see that guard
- Explaining human in the loop: what runs on its own, what a person sees first, and how the threshold moves that line
When not to use
- Sending requests to the agents that handle them, with a light to each – use Agent Router
- Deciding by a fixed rule table with no model in it – use Decision Table
- A person approving or rejecting what an agent wants to do – use Approval Gates
Usage
import { DecisionLoop, type LoopEvent, type LoopAction, type LoopRule } from "@/components/ui/decision-loop";
const events: LoopEvent[] = [
{
id: "e1",
source: { name: "Intercom", logo: <IntercomLogo /> },
title: "Charged twice for my plan",
text: "I see two charges of $38 from this morning. Can you refund one?",
fields: [{ label: "Amount", value: "$38" }, { label: "Plan", value: "Pro" }],
decision: { choice: "refund", scores: { refund: 0.94, reply: 0.04, bug: 0.02 } },
outcome: "right",
},
];
const actions: LoopAction[] = [
{ id: "refund", label: "Refund", via: "Stripe", logo: <StripeLogo />, count: 41 },
{ id: "reply", label: "Reply", via: "Help center", logo: <FolderLogo />, count: 128 },
{ id: "bug", label: "Bug report", via: "Linear", logo: <LinearLogo />, count: 17 },
];
const rules: LoopRule[] = [
{ id: "amount", code: "amount <= 50", why: "Bigger refunds go to a person", test: (e) => amountOf(e) <= 50 },
];
export function Triage() {
return (
<DecisionLoop
events={events}
actions={actions}
rules={rules}
model={{ id: "triage", name: "Ticket triage", subtitle: "Claude Haiku 5.5" }}
review={{ label: "Human review", via: "Support team" }}
defaultThreshold={0.85}
/>
);
}Props
| Name | Type | Default | Description |
|---|---|---|---|
events | LoopEvent[] | { id, title, text?, source?, fields?, decision: { choice, scores }, outcome? } – taken one after another | |
actions | LoopAction[] | { id, label, via?, logo?, count? } – where a decision goes when every rule holds; decision.choice names one | |
rules | LoopRule[] | { id, code, why?, test } – after the threshold, checked in order; the first that fails sends the event to a person | |
model | { id, name, subtitle?, details? } | The model card – its pixel mark comes from id; details ({ label, value, icon? }) fill its info card | |
review | { label, via?, count? } | Who looks when a rule fails – "Human review" by default | |
threshold / defaultThreshold | number | How sure the model must be to act alone, 0.5–0.95 – 0.85 by default | |
onThresholdChange | (t) => void | The threshold moved by the arrows | |
autoPlay | boolean | Takes the next event by itself – on by default; reduced motion keeps it still | |
onRoute | (event, to) => void | A decision reached an action – its id, or "review" | |
className | string | An extra class on the root |
Accessibility
- Each event is announced once it has gone somewhere – "Charged twice for my plan: Refund at 0.94 → Refund"
- Every rule says whether it holds, fails or wasn't checked; the threshold's arrows are buttons named Lower and Raise and keep the focus at either end
- The model and each action open an info card with Enter; Esc or a click outside closes it
- Pause stops the loop; paused, Previous and Next step through the events, each shown decided
- A focus ring shows only for the keyboard
Responsive
- Fills its container's width; below 760px the cards stack – input, model, rules, actions – and the connectors step aside
- Long titles and names end in … and show in full on hover; long rule names shorten before their values do
- Counts read 1,284 – and 12.4K or 1.3M once they get long
- Dark mode built in: switches when an ancestor (usually <html>) has the class dark or data-theme="dark"
Requirements
- React 19
Related
- Agent Router – A router agent sorting incoming requests to the agents that handle them – a light runs to the chosen agent with a confidence, and unsure requests go to a person
- Decision Table – An agent deciding by a DMN decision table – the request on top, rules below checked row by row until the matching rule lights up with its outputs
- Approval Gates – The approval requests of an agent run as a stack of cards – the one to decide now on top with the diff or arguments, approve, reject or change it, then the next rises
- Guardrail Funnel – The guardrails an agent's traffic passes through, as a funnel – input check, PII redaction, tool allowlist, output check – with how many each stage stopped and what it caught