> ## Documentation Index
> Fetch the complete documentation index at: https://opencomputer.manicule.dev/llms.txt
> Use this file to discover all available pages before exploring further.
> For every page in one file, fetch https://opencomputer.manicule.dev/llms-full.txt (large).
> To search and read these docs as tools, connect the MCP server at https://opencomputer.manicule.dev/api/mcp.
> Every agent surface: https://opencomputer.manicule.dev/.well-known/llms-manifest.json

# Agent hooks (/agents/hooks)

<!-- agent-signals: reading_time_min: 2 · est_tokens: 861 · updated: 2026-10-05 -->
Related: [Serverless Agents](/agents/overview.md), [How it works](/agents/mental-model.md), [Quickstart](/agents/quickstart.md), [Projects and agents](/agents/projects.md), [Reactive agents](/agents/reactive-agents.md), [Sessions and turns](/agents/sessions.md)

> Compose agent capabilities with reactive hooks

An agent function returns instructions. Hooks give that agent the model,
tools, services, and context it needs to follow those instructions.

```tsx
import { useInput, useModel, useTool } from "@opencomputer/agent";

export default function Agent() {
  const input = useInput();
  useModel("anthropic/claude-sonnet-4.6");

  if (input.text?.includes("latest")) {
    useTool("web-search");
  }

  return "Answer directly. Use current sources when web search is available.";
}
```

## How hooks work

OpenComputer renders the exported function before each model step. Every hook
called during that render contributes to the next step's configuration. Hooks
describe capabilities; they do not call the model or run a tool themselves.

Unlike React component hooks, OpenComputer resource hooks can be conditional.
The example above exposes `web-search` only when the current input asks for
recent information.

Hooks can only run while OpenComputer is rendering an agent. Keep network
requests and other asynchronous work inside [tools](/agents/tools), not in the
agent function.

## Built-in hooks

| Hook                     | What it does                                                              | Guide                                |
| ------------------------ | ------------------------------------------------------------------------- | ------------------------------------ |
| `useInput()`             | Reads the current input source, text, and structured payload              | [Inputs](/agents/inputs)             |
| `useCurrentInput()`      | Alias for `useInput()`                                                    | [Inputs](/agents/inputs)             |
| `useModel(model)`        | Selects the model used for the next step                                  | [Models](/agents/models)             |
| `useTool(tool)`          | Exposes a named or code-defined tool                                      | [Tools](/agents/tools)               |
| `useMcpServer(server)`   | Exposes tools from a managed HTTPS MCP server                             | [MCP servers](/agents/mcp)           |
| `useSessionData<T>(key)` | Reads a durable value associated with the session                         | [Session data](/agents/session-data) |
| `useMemory(memory)`      | Reads bound memory and selects its permitted tools for this model request | [Memory](/agents/memory)             |

[Skills](/agents/skills) are also agent capabilities, but they are discovered
from the agent's `skills/` directory rather than attached with a hook.

## Compose your own hooks

Hooks are ordinary synchronous functions. Group related capabilities in a
custom hook when several agents use the same setup:

```tsx
import { useTool } from "@opencomputer/agent";

function useGitHubResearch() {
  useTool("github-search");
  return "Check GitHub before making claims about repositories or issues.";
}

export default function Agent() {
  const githubInstructions = useGitHubResearch();
  return `Research the request carefully. ${githubInstructions}`;
}
```

Custom hooks keep agent functions readable and make capability bundles
reusable. Prefix them with `use` so their purpose is obvious.

## Next steps

* [Read and route inputs](/agents/inputs)
* [Choose a model](/agents/models)
* [Give the agent tools](/agents/tools)
* [Connect an MCP server](/agents/mcp)
* [Add reusable skills](/agents/skills)
