# Capabilities

A Capability gives an Agent one named ability, such as web search, through `defineAgent({ capabilities })`. It can add tools, triggers, input processing, output metadata, and checks that run before an Invocation (one Agent run).

App code calls Server Primitives with full trust. A Capability picks which operations the Agent can use. Write the behavior in [Instructions](https://vitehub.dev/docs/agents/instructions) first, then attach the tools it needs.

## Choose a Capability by task

| Task | Start with |
| --- | --- |
| Read project files | [Workspace tools](https://vitehub.dev/docs/workspace/agent-capability) and [Skills](https://vitehub.dev/docs/agents/capabilities/skills) |
| Query application data | [Database](https://vitehub.dev/docs/database/agent-capability), [KV](https://vitehub.dev/docs/kv/agent-capability), or [Blob](https://vitehub.dev/docs/blob/agent-capability) |
| Search or call an external service | [Web search](https://vitehub.dev/docs/agents/capabilities/web-search), [Fetch](https://vitehub.dev/docs/agents/capabilities/fetch), [OpenAPI](https://vitehub.dev/docs/agents/capabilities/openapi), or [MCP](https://vitehub.dev/docs/agents/capabilities/mcp) |
| Work the person's open page | [Page](https://vitehub.dev/docs/agents/capabilities/page) |
| Continue a conversation | [Chat](https://vitehub.dev/docs/agents/capabilities/chat), [Chat History](https://vitehub.dev/docs/agents/chat-history-sessions), and [Memory](https://vitehub.dev/docs/agents/capabilities/memory) |
| Restrict work | [Access](https://vitehub.dev/docs/agents/capabilities/access), [Budget](https://vitehub.dev/docs/agents/capabilities/budget), and [Rate Limit](https://vitehub.dev/docs/rate-limit/agent-capability) |
| Inspect cost and results | [Usage](https://vitehub.dev/docs/agents/capabilities/usage), [Diagnostics](https://vitehub.dev/docs/agents/capabilities/diagnostics), and [OTLP](https://vitehub.dev/docs/agents/capabilities/otlp) |

The [official catalog](https://vitehub.dev/docs/agents/capabilities/official) lists more. Write a [custom Capability](https://vitehub.dev/docs/agents/capabilities/custom) for your own tools.

## Choose the API by its caller

Installing a Server Primitive does not give the Agent access. Attach a Capability for that.

| | Server Primitive | Capability |
| --- | --- | --- |
| Caller | Application server code | An Agent during an Invocation |
| Access | A documented server import | Selected tools, policy, requirements, or context |
| Selection | Application code calls it | The Agent Definition or invocation selects it |
| Model access | None | Only the operations the Capability contributes |

A Capability never gives the full Runtime Context or host access. Its tools, requirements, policy, and metadata set what the Agent can use. App code still calls the primitives through their server APIs.

## Attach a Capability

Import factories from `vite-hub/agent/capabilities`, or `@vite-hub/agent/capabilities` in a standalone package.

```ts [server/agents/support.ts]
import { defineAgent } from 'vite-hub/agent'
import { workspaceShell } from 'vite-hub/agent/capabilities'
import { file } from 'vite-hub/workspace'

export default defineAgent({
  driver: { model: 'openai/gpt-5.1-mini' },
  workspace: { sources: { policy: file('support.md') } },
  capabilities: [
    workspaceShell({ mode: 'read' }),
  ],
})
```

Create `support.md` in the project root first.

Tool policy defaults to `allow`. Set `policy: 'require-approval'` or `'deny'` when a tool needs another runtime check. Modes, scopes, allowlists, requirements, and input validation still apply before policy.

To pick Capabilities per run, pass a callback. ViteHub calls it once, after it resolves the Agent Invoker (who started the run) and before Capability setup. Capabilities from the active Channel still apply.

```ts [server/agents/support.ts] fragment
export default defineAgent({
  driver: { model },
  capabilities: ({ invoker }) => [
    workspaceShell({ mode: 'read' }),
    ...(invoker.meta?.support === true ? [internalDiagnostics] : []),
  ],
})
```

Keep Capabilities that add Agent Triggers, chat admission, or static Workspace Sources in a static list. ViteHub registers those before a run exists.

## What Capabilities can contribute

| Contribution | What it changes |
| --- | --- |
| Requirements | Primitive, Workspace mode, path, or policy checks that must pass first. |
| Tools | Model operations, for compatible Drivers only. |
| Provider tools | Provider-native tool requests, such as model web search mode. |
| Agent Triggers | Events that start runs through the trigger API. |
| Input behavior | Input transforms, transcription, decisions, gates, and rate limits before the run. |
| Output behavior | Stream renderers, finish extensions, usage records, titles, and summaries. |
| Metadata | Configuration for diagnostics and CLI inspection. |

Agent inspection shows metadata under each Capability id. ViteHub keeps JSON values, sorts keys and ids, drops unsupported or cyclic values, and redacts keys that look like auth, API keys, credentials, passwords, secrets, or tokens.

> [!WARNING]
> Metadata must describe configuration or a check result. Never put Env values, authentication material, or credentials in it.

For data read after a run by evals, finish hooks, or Channel delivery, use `defineCapability({ finish })`. Agent Evals read it with `observation.extensions.get(capabilityId)` and the `hasCapabilityExtension(capabilityId)` scorer.

## Finish without the Driver

A Capability `input` phase can finish an Invocation only with a `Response`. When app code decides the result for some inputs, such as mail rules that label an email before a model runs, use `defineAgent({ data, intercept })` instead. `intercept` returns a typed value that becomes the Invocation output, and `runAgent()` types `result.output` as the union of that value and the Driver output.

```ts [server/agents/labeller.ts] fragment
export default defineAgent({
  data: email,
  intercept: ({ data }) => data.from.endsWith('@github.com') ? { source: 'rule' as const, label: 'GitHub' } : undefined,
  driver: { model, output: { schema: modelLabel } },
})
```

Read [Finish before the Driver](https://vitehub.dev/docs/agents/agent-definitions#finish-before-the-driver) for hooks, traces, and layer rules.

## Driver support

- **Model-backed** Drivers use model tools and Provider Tools (tools the provider runs, such as model web search).
- **Provider-backed** Drivers get Agent tools through a private MCP bridge and scoped Workspace behavior. They do not support model-specific Provider Tools such as `webSearch({ mode: 'model' })`.
- **Custom-run** Drivers get prepared input and run context. `driver.run` decides which Capability outputs to read.

Put guidance on when to use a Capability in the Driver Instructions or deterministic imported instruction Markdown. Tool descriptions and schemas stay part of the model's tool contract.

## Capability lifecycle

ViteHub applies Capabilities in list order. It checks duplicate ids and runtime requirements, applies trigger contributions, then runs configure, prepare, bind, input, resolve, and output for each run.

Only `access()` has a fixed position: first, so later Capabilities get the restricted Workspace and tools.

## Next steps

- [Official capabilities](https://vitehub.dev/docs/agents/capabilities/official)
- [Custom capabilities](https://vitehub.dev/docs/agents/capabilities/custom)
- [Instructions](https://vitehub.dev/docs/agents/instructions)
- [Chat History and sessions](https://vitehub.dev/docs/agents/chat-history-sessions)
- [Workspace context](https://vitehub.dev/docs/agents/workspace-context)

<!-- vitehub-docs:section-links -->
## In this section

- [Start](https://vitehub.dev/raw/docs/agents.md)
- [Define and run](https://vitehub.dev/raw/docs/agents/agent-definitions.md)
- Instructions and tools
  - [Instructions](https://vitehub.dev/raw/docs/agents/instructions.md)
  - [Capabilities](https://vitehub.dev/raw/docs/agents/capabilities.md) (this page)
  - [Official capabilities](https://vitehub.dev/raw/docs/agents/capabilities/official.md)
  - [Agent UI](https://vitehub.dev/raw/docs/agents/ui.md)
- [History and context](https://vitehub.dev/raw/docs/agents/chat-history-sessions.md)
- [Channels](https://vitehub.dev/raw/docs/agents/channels.md)
- [Inspect and evaluate](https://vitehub.dev/raw/docs/agents/observability.md)
- [Advanced](https://vitehub.dev/raw/docs/agents/agent-presets.md)
- [Recipes](https://vitehub.dev/raw/docs/agents/support-agent.md)
- [Presets](https://vitehub.dev/raw/docs/agents/presets.md)
- [Capabilities](https://vitehub.dev/raw/docs/agents/capabilities/access.md)

Next: [AGENT_R0021](https://vitehub.dev/raw/docs/agents/diagnostics/agent_r0021.md)

All pages: [llms.txt](https://vitehub.dev/llms.txt)
