ViteHub is still experimental. Expect bugs and breaking changes.

Chat

Add chat-oriented Agent Trigger behavior and Chat History state requirements.

chat() adds chat-oriented runtime behavior to an Agent Definition. It contributes a chat.message Agent Trigger, Chat History state requirements, and a chat finish extension.

The Chat Capability turns message-shaped input into Agent Invocations and exposes the trigger to the CLI Dev Loop. Message-shaped Channels own route admission and delivery into that trigger.

Configure chat

Attach chat() to call the Agent from a chat interface through the Agent Trigger API. Use Channels to deliver messages from Slack, Telegram, Teams, web chat, or another adapter.

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

export default defineAgent({
  driver: { model },
  capabilities: [
    chat(),
  ],
})

How chat works

chat() registers the chat.message trigger with ui-message[] input and ui-message-stream output. It prepares Chat History state when available, records chat context, and provides chat finish data after the Agent Invocation completes.

Requirements

Chat History state is optional in local development but needs an Agent State Provider when the deployed stack requires durable sessions or concurrency coordination. External Chat Platform Adapters remain explicit application dependencies configured through Channels.

Driver support

Agent DriverSupport
Model-backedReceives message-shaped input and can stream chat output through the model-backed path.
Provider-backedReceives the prepared invocation input and chat context; provider chat behavior follows the provider adapter.
Custom-run-backedReceives the chat trigger input and context; driver.run owns the response shape.

Verify chat

Run vitehub agent dev --agent <name> --prompt "hello" and confirm the Agent responds through the configured Chat Capability. Send one message through vitehub agent dev and verify the invocation origin, Chat Session behavior, and finish extension through traces or run events.

For adapter-backed delivery, inspect the Channel-generated webhook registrations for the expected route metadata.

Options

OptionTypeDefaultDescription
hooksAgentChatEventHooksnoneChat event hooks such as onDirectMessage.
lifecycleHooksRecord<string, unknown>noneAdditional lifecycle-hook settings for integrations that consume Chat Capability configuration.
event"directMessage"noneChat event binding hint.
triggerHistory"none" | { source: "thread"; maxMessages?: number }last 20 messages, or threadHistory.maxMessages when derivedChat History Window sent into the chat.message Agent Trigger.
threadHistory{ maxMessages?: number; ttlMs?: number }inheritedAdapter thread backfill/cache; stores messages but does not by itself define model input.
messageHistoryChat SDK message-history configurationinheritedAdapter message-history behavior passed to the Chat SDK.
loggerChat SDK loggerinheritedLogger passed to adapter-backed Chat SDK delivery.
sessionsboolean | AgentChatSessionOptionsinheritedChat Session behavior, including strategy, idleTimeoutMs, and metadataKey.
stateAgentChatStateResolverruntime stateChat State adapter override.
transcriptsChat SDK TranscriptsConfignoneTranscript persistence configuration for adapter-backed Channels.
identityIdentityResolverchannel-qualified user id when transcripts are enabledResolve the identity used to partition transcripts.
streambooleaninheritedStreams chat trigger output when enabled.
streamingUpdateIntervalMsnumberinheritedMinimum interval between streamed Channel message updates.
concurrency"drop" | "parallel" | "queue" | "reject" | "serial" | "steer" | stringinheritedOverlapping message behavior. serial runs each retained message as a separate awaited Agent Invocation in queue order; queue coalesces retained messages into one invocation. steer is accepted for API compatibility and currently uses the same coalescing behavior as queue. Queue retention and failure guarantees come from the configured Chat State runtime.
lockScope"agent" | "channel" | "thread" | stringinheritedScope used for message locks.
dedupeTtlMsnumberinheritedTime-to-live for Chat SDK duplicate-message keys.
userNamestring"vitehub"Agent username used by adapter-backed Chat SDK delivery.
fallbackStreamingPlaceholderTextstring | string[] | null | functioninheritedPlaceholder text while streaming starts. Arrays pick one entry per Agent Invocation; empty arrays skip the placeholder.
errorFallbackTextstring | null | functioninheritedFallback message when chat handling fails.