agent tool selection api

AI agent tool selection and human-approval gate API

Guarantee closed-set tool selection and explicit human-in-the-loop approval gates before an autonomous agent executes refunds, deletes data, or mutates production state—in one ~39 ms pass.

Interactive AI agent tool selector & approval gate
Input state evaluated

Customer says: We accidentally bought two Pro keys today — please refund order #ord_912 and revoke the second key immediately.

Primary choice confidence
mutate_billing (97%)
Est. model spend / 1k calls
$0.0037 (~193 tok)
AUTO-ESCALATE · mutate_billing + require_human_approval P(require_human_approval) = 0.98
next_tool → mutate_billing 97%
curl --fail-with-body https://clef-flash.com/api/v1/decisions \
  -H "authorization: Bearer $CLEF_API_KEY" \
  -H "content-type: application/json" \
  --data-binary @- <<'CLEF_DECISION'
{
  "model": "cloudflare/clef-flash",
  "threshold": 0.88,
  "state": "Customer says: We accidentally bought two Pro keys today — please refund order #ord_912 and revoke the second key immediately.",
  "questions": {
    "next_tool": {
      "type": "choice",
      "instructions": "Select the single permitted tool the agent should invoke next.",
      "criteria": {
        "search_docs": "read-only documentation or knowledge-base lookup",
        "query_order_db": "read-only lookup of order status, plan or usage quota",
        "draft_reply": "compose a response without changing external state",
        "mutate_billing": "issue refund, cancel subscription, revoke key or modify credits"
      }
    },
    "require_human_approval": {
      "type": "noul",
      "instructions": "Does the next agent step mutate money, permissions or external production state?",
      "criteria": {
        "true": "refunds, key revocation, account deletion, outbound emails or DB writes",
        "false": "strictly read-only lookup or local draft generation"
      }
    }
  }
}
CLEF_DECISION
Pro API key · $19 / 30 days · no auto-renewal

Ship this in production with a $19 Pro key

2,000 decisions/day, 8 concurrent requests in flight, text + JSON + image states, and an API key emailed in about a minute.

Eliminate hallucinated tool calls and unsafe autonomous writes

Agent frameworks often ask a chat LLM to pick the next tool from twenty JSON schemas and hope it remembers to ask for human confirmation before issuing a refund or revoking an API key. When prompts get long, chat models occasionally invent nonexistent tool names or trigger mutations prematurely.

Clef-Flash separates decision control from prose generation. In one forward pass, it scores your exact permitted tools (2 to 12 closed options) and computes a calibrated require_human_approval probability so every state-mutating step enforces a deterministic safety gate.

  • Mathematically impossible to invent a tool name outside your request criteria.
  • Pairs read-only vs write classification with a dedicated boolean human-approval gate.
  • Runs at ~39 ms median model latency inside multi-step agent loops without stalling UX.

Agent tool routing and safety gate contract

Keep autonomous execution fast on safe read-only lookups while forcing explicit user confirmation on irreversible actions.

Tool CategorySafety ClassAgent Runtime Behavior
search_docsRead-onlyExecute immediately when confidence >= threshold
query_order_dbRead-onlyExecute scoped account lookup automatically
draft_replyLocal draftGenerate draft without sending external email
mutate_billingDestructive writePause and show approval button when P(require_human_approval) >= 0.50

Why two-tier agent architectures pair Clef-Flash with frontier models

Use Clef-Flash as the fast, cheap control-plane router on every step—selecting the tool subset, checking safety permissions, and deciding whether a step even needs a frontier reasoning model—then invoke your large language model only when complex synthesis or argument extraction is genuinely needed.

Try switching presets and dragging the confidence threshold in the studio above to inspect the exact curl and TypeScript request body accepted by POST /api/v1/decisions.

Built-in concurrency isolation for parallel multi-agent fleets

When dozens of background agents fire routing checks simultaneously, Clef-Flash tracks active in-flight concurrency per API key via a Durable Object (8 on Pro, 32 on Scale, 64 on Studio, 128 on Agency) so runaway agent loops fail cleanly with 429 concurrency_exceeded instead of burning unlimited credits.

Frequently asked questions

How many tools can I include in a single tool-selection question?

Each choice question supports 2 to 12 options with plain-English criteria descriptions. For larger tool catalogs, route to a domain group first, then pick the specific tool in a second ~39 ms call.

Can Clef-Flash enforce a human-in-the-loop gate on the same request?

Yes. Include a noul question like require_human_approval alongside next_tool in the same POST /api/v1/decisions body and pause execution whenever its probability crosses your safety floor.

Does Clef-Flash generate function arguments or only choose the tool?

Clef-Flash is a decision model, not a prose generator—it selects the exact tool and safety verdicts with calibrated probabilities. Use deterministic code or a scoped LLM call once the tool is authorized.

How do I test agent routing without setting up billing first?

Run 25 free decisions/day on the browser playground or keyless /api/decide endpoint, then unlock 2,000/day and 8 concurrent calls with a $19 Pro API key.

Keep reading

Model notes

One short email when a new decision model lands or a benchmark changes. No spam, unsubscribe in one click.