ViteHub is still experimental. Expect bugs and breaking changes.

LLM gate

Allow or reject an Agent Invocation with a pre-invocation model decision.

llmGate() adds a pre-invocation model decision that classifies a request into allow or reject categories. It can stop the Agent Invocation before the main Agent Driver runs.

The Capability asks a model to choose one configured allow or reject category. It records the decision as an Agent Invocation Context Value, exposes it as a finish extension, and throws ViteHubError with code LLM_GATE_REJECTED when the selected category is rejected.

Configure the gate

Define allow and reject categories with stable keys. Set message to return a product-specific rejection message from the host.

server/agents/support.ts
import { defineAgent } from 'vite-hub/agent'
import { llmGate } from 'vite-hub/agent/capabilities'

export default defineAgent({
  driver: { model },
  capabilities: [
    llmGate({
      allow: {
        support: 'Support request the Agent can answer.',
      },
      reject: {
        unrelated: 'Request unrelated to support.',
      },
    }),
  ],
})

How the gate works

llmGate() runs during the input phase. It resolves a model, renders a classifier prompt from the latest user text and configured categories, validates the structured output, and stores the decision in invocation context.

When the decision rejects the request, ViteHub throws ViteHubError with code LLM_GATE_REJECTED; the HTTP handler maps that code to 403.

Requirements

llmGate() requires at least one allow category and one reject category. Category keys must be stable identifiers.

The Capability requires either an explicit model option or an Agent model resolver available to Capabilities.

Driver support

Agent DriverSupport
Model-backedRuns the pre-invocation gate before model execution.
Provider-backedRuns the pre-invocation gate before provider execution when a model resolver is available.
Custom-run-backedRuns before driver.run; rejected requests do not reach custom code.

Verify the gate

Run one allowed and one rejected invocation. Inspect the context value for llm-gate or your custom id, then verify rejected requests stop with code LLM_GATE_REJECTED.

Check that the gate does not attach, remove, or grant Capabilities. It records a decision; later behavior must read that decision explicitly.

Options

OptionTypeDefaultDescription
allowRecord<string, choice>requiredAllowed categories.
rejectRecord<string, choice>requiredRejected categories.
historyboolean | numberfalseInclude recent conversation history in the classifier prompt.
idstring"llm-gate"Capability id and invocation context key.
messagestring | functiondefault rejection messageError message when the gate rejects.
modelAgentModelResolverAgent modelModel used for the pre-invocation decision.
promptstringgeneratedAdditional classifier prompt text.