Confidence

An answer with how sure the agent is, the evidence for and against, and what would change its mind, so the user can ask it to verify or accept.

Pattern

≈ 1,338 tokens per use (tool 771 · guidance 314 · typical payload 253)How token costs are estimated

Example: Confidence

Why did Fernhill Labs’ churn risk jump this week?

2 sources agree, 1 is stale

Fernhill’s churn risk appears to have risen because active seats fell about 40% after the pricing change on the 2nd. Billing and their support threads agree, but the usage export is a day old.

When to use

  • The user will act on a claim the agent isn't fully sure of: a cause, a diagnosis, a figure pieced together from several sources.
  • The sources disagree, are stale or thin, and the user should see that before relying on the answer.
  • The agent could check further (fresher data, another source), but it costs time, so the user should decide.

When not to use

  • The answer is a plain fact the agent is sure of. Just answer.
  • The uncertainty is in guesses the user could correct, such as party size or budget. Use Assumptions.
  • The point is where each sentence came from. Use Citations.

How the agent should use it

  • Set level honestly from the evidence (high, medium, low) and hedge the claim to match. Put the hedge words in hedges; they're underlined in the claim.
  • Keep reason to one short line, such as "2 sources agree, 1 is stale". It sits next to the level; the detail goes in evidence.
  • Include evidence against whenever it exists. source and url come from tool results, never from memory.
  • Give changeMind as concrete checks, especially at low and medium: what fresh data would move the level.
  • Name the check in verifyLabel ("Check live usage", "Pull full logs"). Set canVerify: false when there's nothing more to check.
  • Only send score if a tool or calibrated model produced it. The level is enough on its own.
  • On verify, check further and show a new confidence card with the updated level. On accept, carry on with the answer.

Interaction

  • The level shows as three bars and a label; colour marks high and low only. A low level adds a "Treat this as a hypothesis" line and opens the evidence.
  • Evidence is a disclosure listing what supports the claim, what cuts against it, and what would change the agent's mind.
  • Verify and Accept are pill buttons; Verify is the primary one at low confidence. After either, the buttons are replaced by a record, which takes focus and is announced.
  • While streaming, the claim, level and evidence arrive in turn and the buttons are disabled. A result from history restores the record without calling onResult.

Installation

npx shadcn@latest add https://your-site.com/r/confidence.json

Usage

app/api/chat/route.ts
import { tool } from "ai"
import { confidenceTool } from "@/components/genui/confidence.schema"

const tools = {
  [confidenceTool.name]: tool({
    description: confidenceTool.description,
    inputSchema: confidenceTool.inputSchema,
  }),
}
components/message.tsx
import { Confidence } from "@/components/genui/confidence"

function ToolPart({ part, addToolResult }) {
  if (part.type !== "tool-show_confidence") return null

  return (
    <Confidence
      {...part.input}
      status={part.state === "input-streaming" ? "streaming" : undefined}
      result={part.state === "output-available" ? part.output : undefined}
      onResult={(result) =>
        addToolResult({
          tool: "show_confidence",
          toolCallId: part.toolCallId,
          output: result,
        })
      }
    />
  )
}

The result tells the agent what the user chose:

{ action: "verify" } // check further, then show an updated card
{ action: "accept" } // carry on with the answer

Schema

PropTypeNotes
questionstring?Shown above the card
claimstringThe answer, up to 400 characters
level"low" | "medium" | "high"How sure the agent is
reasonstringOne line next to the level, up to 120 characters
scorenumber?0–100. Data-bound; omit unless a tool produced it
hedgesstring[]?Up to 4 words from the claim to underline
evidence{ id, stance, text, source?, url? }[]?Up to 8. stance is for or against; source and url are data-bound
changeMindstring[]?Up to 4 things that would change the agent's mind
verifyLabelstring?Verify button label. Default Verify
canVerifyboolean?false offers only Accept. Default true

Host props: status (streaming, ready), onResult, result and className.

Source

On this page