ViteHub

Agent

Define model and tool-loop agents for Vite and Nitro apps.

@vitehub/agent defines server-side agents. An agent owns model instructions, model-facing capabilities, and the run or stream call that produces a response. It consumes @vitehub/runtime capabilities when it needs host resources.

Use Agent when a server feature needs a model loop with ViteHub message input.

server/agents/triager.ts
import { defineAgent, type AgentToolDefinition } from '@vitehub/agent'
import { getMessageText } from '@vitehub/agent'

const classifyTicket: AgentToolDefinition<{ message: string }, { queue: string; priority: string }> = {
  name: 'classifyTicket',
  description: 'Classify a support request before queue handoff.',
  policy: ({ input }) => {
    const message = typeof input === 'object' && input && 'message' in input
      ? String(input.message)
      : ''

    return /refund|invoice|payment/i.test(message) ? 'require-approval' : 'allow'
  },
}

export default defineAgent({
  description: 'Triage support requests and prepare a queue handoff.',
  async run({ input }) {
    const latest = input.messages?.at(-1)
    const message = latest ? getMessageText(latest) : ''

    return {
      raw: { tool: classifyTicket.name },
      text: `Classify and route: ${message}`,
    }
  },
})

What Agent owns

Agent definitions

Keep model instructions, capabilities, and custom run behavior in defineAgent().

Message input

Accept @vitehub/agent input and convert it to model calls inside Agent.

Optional routes

Expose discovered agents over HTTP only when you enable generated routes.

What Agent does not own

Agent does not own chat webhooks, Chat SDK adapters, workflow runs, runtime capability registration, or sandbox lifecycle. Use the package that owns each boundary:

NeedUse
Receive Slack, Discord, Telegram, or Teams events@vitehub/agent/chat
Store or replay conversation state@vitehub/agent
Resolve shared capabilities, approvals, and trace context@vitehub/runtime
Coordinate durable work@vitehub/workflow
Execute isolated code@vitehub/sandbox

Start here

Quickstart
Register Agent and define a first discovered agent.
Usage
Discover agents, expose routes, customize runs, and bind Chat to Agent.
Runtime API
Review exports, runtime context, module options, and handler input.
Troubleshooting
Fix missing routes, unknown agents, model errors, and duplicate ownership.
Copyright © 2026