Skip to content

An open-source, faster Devin alternative

TypeScript

docs: add serverless agent authoring guides and examples (#620)

Mohamed Habib62d5331f826a
diff --git a/docs/agents/examples/exa-research-session.mdx b/docs/agents/examples/exa-research-session.mdx
new file mode 100644
index 00000000..d2bf6100
--- /dev/null
+++ b/docs/agents/examples/exa-research-session.mdx
@@ -0,0 +1,39 @@
+---
+title: "Exa research session"
+description: "A web-research agent with live Exa results and durable follow-up questions"
+---
+
+The Exa research starter is a small React application backed by an
+OpenComputer agent. Ask a question in the browser and the agent searches the
+live web with Exa, compares relevant results, and streams a concise answer with
+source links.
+
+Follow-up questions reuse the same session, so the agent keeps the research
+conversation and can refine an earlier answer without starting over.
+
+## How it works
+
+1. The React application sends a question to an OpenComputer session.
+2. The agent uses its `exa_search` tool when the question needs current web
+ research.
+3. OpenComputer sends the search through a managed Exa connection and injects
+ the write-only `EXA_API_KEY` without exposing it to the agent or browser.
+4. The agent reads the results and streams an answer with clickable source
+ URLs back to the application.
+
+The starter also includes an agent-specific skill that guides the research
+workflow and a reusable React hook for streaming messages and continuing the
+same session.
+
+## Start with the example
+
+<Card
+ title="Exa research starter"
+ icon="github"
+ href="https://github.com/diggerhq/opencomputer-example-exa"
+>
+ Clone the complete React and OpenComputer project from GitHub.
+</Card>
+
+The repository README covers installation, setting the Exa secret, running the
+agent and React development processes, and deploying the finished application.
diff --git a/docs/agents/hooks.mdx b/docs/agents/hooks.mdx
new file mode 100644
index 00000000..caa733ed
--- /dev/null
+++ b/docs/agents/hooks.mdx
@@ -0,0 +1,89 @@
+---
+title: "Agent hooks"
+description: "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) |
+| `useSubagent(agent)` | Makes another project agent available for delegation | [Subagents](/agents/subagents) |
+| `useConnection(connection)` | Requires a managed user or HTTP connection | [Connections](/agents/connections) |
+| `useSessionData<T>(key)` | Reads a durable value associated with the session | [Session data](/agents/session-data) |
+
+[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 {
+ connection,
+ useConnection,
+ useTool,
+} from "@opencomputer/agent";
+
+const github = connection("github");
+
+function useGitHubResearch() {
+ useConnection(github);
+ 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)
diff --git a/docs/agents/inputs.mdx b/docs/agents/inputs.mdx
new file mode 100644
index 00000000..8f6466d9
--- /dev/null
+++ b/docs/agents/inputs.mdx
@@ -0,0 +1,109 @@
+---
+title: "Inputs"
+description: "Read text, structured payloads, and input sources with useInput"
+---
+
+`useInput()` reads the input that caused the current agent render. Use it to
+include the current request in the instructions or change behavior based on
+where the request came from.
+
+```tsx
+import { useInput } from "@opencomputer/agent";
+
+export default function Agent() {
+ const input = useInput();
+ return input.text
+ ? `Help the user with this request: ${input.text}`
+ : "Help the user with their request.";
+}
+```
+
+`useCurrentInput()` is an alias for `useInput()`.
+
+## Input shape
+
+```ts
+interface AgentInput {
+ readonly source:
+ | "user"
+ | "channel"
+ | "schedule"
+ | "webhook"
+ | "subagent"
+ | "system";
+ readonly text?: string;
+ readonly payload?: DataValue;
+}
+```
+
+| Field | Meaning |
+| --- | --- |
+| `source` | How the work entered the session |
+| `text` | Optional human-readable message |
+| `payload` | Optional structured JSON value supplied by the source |
+
+`DataValue` means any JSON-compatible value: `null`, a boolean, number,
+string, array, or object. Both `text` and `payload` are optional, so check them
+before use.
+
+## Adapt to the source
+
+One agent can handle direct user messages, channels, schedules, webhooks, and
+subagent calls without separate definitions:
+
+```tsx
+import { useInput } from "@opencomputer/agent";
+
+export default function Agent() {
+ const input = useInput();
+
+ switch (input.source) {
+ case "channel":
+ return "Reply naturally and keep the answer suitable for a shared chat.";
+ case "schedule":
+ return "Run the scheduled review and summarize anything that changed.";
+ case "webhook":
+ return `Process this event: ${JSON.stringify(input.payload)}`;
+ case "subagent":
+ return "Complete the delegated task and return a concise result.";
+ default:
+ return `Help with: ${input.text ?? "the current request"}`;
+ }
+}
+```
+
+## Read structured payloads
+
+Narrow or validate a payload before reading application-specific fields:
+
+```tsx
+import { useInput } from "@opencomputer/agent";
+
+type IssueEvent = {
+ action?: string;
+ issue?: { number?: number; title?: string };
+};
+
+export default function Agent() {
+ const input = useInput();
+ const event = (input.payload ?? {}) as IssueEvent;
+
+ if (input.source === "webhook" && event.issue?.number) {
+ return `Triage issue #${event.issue.number}: ${event.issue.title ?? "Untitled"}`;
+ }
+
+ return "Ask for an issue number before starting triage.";
+}
+```
+
+For untrusted webhook payloads, validate the value in a tool before performing
+side effects.
+
+## Input is not a prompt UI
+
+`useInput()` only reads admitted input. It does not pause the session to ask a
+person a question. The durable conversation and later messages are managed by
+the [session](/agents/sessions).
+
+Input payload also differs from [session data](/agents/session-data): a payload
+belongs to the current input, while session data can persist across renders.
diff --git a/docs/agents/mcp.mdx b/docs/agents/mcp.mdx
new file mode 100644
index 00000000..41cc01d0
--- /dev/null
+++ b/docs/agents/mcp.mdx
@@ -0,0 +1,97 @@
+---
+title: "MCP servers"
+description: "Attach managed HTTPS MCP servers with useMcpServer"
+---
+
+MCP (Model Context Protocol) connects an agent to tools hosted by an external
+service. Declare the server once with `defineMcpServer()`, then attach it to an
+agent render with `useMcpServer()`.
+
+## Connect a server
+
+```tsx
+import {
+ defineMcpServer,
+ useMcpServer,
+ useModel,
+} from "@opencomputer/agent";
+
+const docs = defineMcpServer({
+ id: "company-docs",
+ url: "https://mcp.example.com/server",
+});
+
+export default function Agent() {
+ useModel("anthropic/claude-sonnet-4.6");
+ useMcpServer(docs);
+ return "Answer questions using the company documentation when relevant.";
+}
+```
+
+Managed MCP URLs must use HTTPS. OpenComputer connects to the server and makes
+its tools available to the managed agent loop; agent code does not open or
+close the connection itself.
+
+## Definition fields
+
+| Field | Required | Purpose |
+| --- | --- | --- |
+| `id` | yes | Stable ID for the server in the deployment |
+| `url` | yes | HTTPS MCP endpoint |
+| `connection` | no | Managed connection used to authorize the server |
+
+`useMcpServer()` accepts either a definition or an existing server ID.
+
+## Attach authorization
+
+Reference a managed user connection when the server requires authorization:
+
+```tsx
+import {
+ connection,
+ defineMcpServer,
+ useMcpServer,
+} from "@opencomputer/agent";
+
+const github = connection("github");
+const githubMcp = defineMcpServer({
+ id: "github",
+ url: "https://mcp.example.com/github",
+ connection: github,
+});
+
+export default function Agent() {
+ useMcpServer(githubMcp);
+ return "Use GitHub tools to investigate repository questions.";
+}
+```
+
+The connection declaration contains an identifier, not an OAuth token. Each
+user authorizes their own account through OpenComputer. See
+[Connections and MCP](/agents/connections) for authorization commands and
+missing-connection behavior.
+
+## Attach MCP conditionally
+
+An agent can expose a server only when the current request needs it:
+
+```tsx
+import { useInput, useMcpServer } from "@opencomputer/agent";
+
+export default function Agent() {
+ const input = useInput();
+ if (input.text?.toLowerCase().includes("documentation")) {
+ useMcpServer(docs);
+ }
+ return "Use company docs when that capability is available.";
+}
+```
+
+Conditional attachment reduces the number of tools the model must choose from
+on unrelated requests.
+
+## MCP versus code-defined tools
+
+Use [code-defined tools](/agents/tools) when you own the operation or need
+custom validation and control. Use MCP when a service already publishes the
+tools you need or when several agents should consume the same remote tool set.
diff --git a/docs/agents/models.mdx b/docs/agents/models.mdx
new file mode 100644
index 00000000..0b3c3b16
--- /dev/null
+++ b/docs/agents/models.mdx
@@ -0,0 +1,77 @@
+---
+title: "Models"
+description: "Select a managed model with useModel"
+---
+
+`useModel()` selects the model that powers the next agent step. OpenComputer
+owns the provider connection, authentication, streaming, and managed model
+gateway.
+
+```tsx
+import { useModel } from "@opencomputer/agent";
+
+export default function Agent() {
+ useModel("anthropic/claude-sonnet-4.6");
+ return "You are a helpful assistant. Be concise and practical.";
+}
+```
+
+`useModel()` is a declaration. It returns nothing and does not make a model
+request itself.
+
+## Model identifiers
+
+Use a `provider/model` string:
+
+```tsx
+useModel("anthropic/claude-sonnet-4.6");
+```
+
+The object form is equivalent:
+
+```tsx
+useModel({
+ provider: "anthropic",
+ model: "claude-sonnet-4.6",
+});
+```
+
+Keep model selection in agent code so development and immutable deployments
+record the behavior together. Provider credentials are resolved by the
+managed gateway and are not added to source bundles or client applications.
+
+## Select a model conditionally
+
+Because the agent re-renders for each model step, selection can respond to the
+current input:
+
+```tsx
+import { useInput, useModel } from "@opencomputer/agent";
+
+export default function Agent() {
+ const input = useInput();
+ const needsDeepReview = input.text?.includes("deep review") ?? false;
+
+ useModel(
+ needsDeepReview
+ ? "anthropic/claude-sonnet-4.6"
+ : "anthropic/claude-haiku-4.5",
+ );
+
+ return needsDeepReview
+ ? "Review the request carefully and explain important tradeoffs."
+ : "Answer directly and briefly.";
+}
+```
+
+Select one model for the next step and keep the choice predictable: model
+changes affect cost, latency, context limits, and output behavior.
+
+## Keep credentials out of agent code
+
+Do not place provider API keys in `agent.ts`, tools, prompts, or the React
+application. OpenComputer's model gateway resolves the credential for the
+selected provider without exposing it to the agent.
+
+For credentials used by your own HTTP tools instead of model inference, use
+[Secrets and managed egress](/agents/secrets).
diff --git a/docs/agents/quickstart.mdx b/docs/agents/quickstart.mdx
index 2d19bc67..14a87c65 100644
--- a/docs/agents/quickstart.mdx
+++ b/docs/agents/quickstart.mdx
@@ -27,17 +27,7 @@ npx opencomputer login
The CLI opens the OpenComputer device-login flow and stores the login locally.
The production API at `https://app.opencomputer.dev` is used by default.
-## 3. Link a cloud project
-
-```bash
-npx opencomputer link
-```
-
-Choose an existing project or create a new one. OpenComputer stores this local
-binding for subsequent development, secrets, and logs commands. You can skip
-this step: the first project-scoped command will show the same prompt.
-
-## 4. Start cloud development
+## 3. Start cloud development
In the first terminal:
@@ -45,10 +35,11 @@ In the first terminal:
npm run dev
```
-The process stays open, watches `opencomputer/`, and syncs changes to
+On the first run, choose an existing cloud project or create a new one. The
+process then stays open, watches `opencomputer/`, and syncs changes to
`development`.
-## 5. Start React
+## 4. Start React
In a second terminal:
@@ -66,7 +57,7 @@ bridge details from `.opencomputer/dev.json`; those details are intentionally
not bundled into browser code.
</Warning>
-## 6. Change the agent
+## 5. Change the agent
Edit `opencomputer/agents/hello-world/agent.ts`:
@@ -84,7 +75,7 @@ export default function Agent() {
Saving the file publishes a new development deployment. Refreshing or
restarting the React app is not required for agent-only changes.
-## 7. Deploy to production
+## 6. Deploy to production
```bash
npm run deploy -- --alias production
diff --git a/docs/agents/reactive-agents.mdx b/docs/agents/reactive-agents.mdx
index 314a621d..41dd5d8a 100644
--- a/docs/agents/reactive-agents.mdx
+++ b/docs/agents/reactive-agents.mdx
@@ -134,3 +134,8 @@ useModel({ provider: "anthropic", model: "claude-sonnet-4.6" });
Provider credentials are resolved by the managed model gateway and are not
placed in the agent sandbox or React application.
+
+Continue with [Agent hooks](/agents/hooks), then use the focused guides for
+[inputs](/agents/inputs), [models](/agents/models), [tools](/agents/tools),
+[MCP servers](/agents/mcp), [skills](/agents/skills),
+[subagents](/agents/subagents), and [session data](/agents/session-data).
diff --git a/docs/agents/session-data.mdx b/docs/agents/session-data.mdx
new file mode 100644
index 00000000..aaf6d83b
--- /dev/null
+++ b/docs/agents/session-data.mdx
@@ -0,0 +1,80 @@
+---
+title: "Session data"
+description: "Read durable per-session values with useSessionData"
+---
+
+`useSessionData()` reads structured data associated with the current durable
+session. Use it for application context that should influence later renders,
+such as a campaign name, locale, audience, or workflow phase.
+
+```tsx
+import { useSessionData } from "@opencomputer/agent";
+
+export default function Agent() {
+ const campaign = useSessionData<string>("campaign_name");
+ const audience = useSessionData<string>("audience");
+
+ return [
+ "Help plan the campaign.",
+ campaign ? `Campaign: ${campaign}.` : undefined,
+ audience ? `Audience: ${audience}.` : undefined,
+ ]
+ .filter(Boolean)
+ .join(" ");
+}
+```
+
+## Read a value
+
+The key is a string. Pass a TypeScript type argument for the expected value:
+
+```tsx
+const locale = useSessionData<string>("locale");
+const approved = useSessionData<boolean>("brief_approved");
+const channels = useSessionData<readonly string[]>("channels");
+```
+
+The hook returns `undefined` when the key is absent. Handle that case rather
+than assuming every session has been initialized.
+
+Values must be JSON-compatible: `null`, booleans, numbers, strings, arrays,
+and objects containing those values.
+
+## Configure capabilities from session data
+
+Because session data is available during render, it can control instructions
+and resource hooks:
+
+```tsx
+import { useSessionData, useTool } from "@opencomputer/agent";
+import { publishCampaign } from "./tools/publish-campaign";
+
+export default function Agent() {
+ const approved = useSessionData<boolean>("brief_approved") ?? false;
+
+ if (approved) {
+ useTool(publishCampaign);
+ }
+
+ return approved
+ ? "The brief is approved. Publishing is available when the user asks."
+ : "Draft and revise the brief. Do not publish it yet.";
+}
+```
+
+## Session data versus input
+
+`useInput().payload` belongs to the current admitted input. Session data is
+associated with the durable session and can be read again on later renders.
+Use input for the event that just arrived and session data for context that
+outlives that event.
+
+## Current write behavior
+
+The current `@opencomputer/agent` API exposes session data as a read-only
+snapshot. It does not yet include a hook for setting or updating a value from
+agent code. Code should treat the returned value as immutable.
+
+See [Sessions and playground](/agents/sessions) for the durable conversation
+lifecycle and [Exa research session](/agents/examples/exa-research-session)
+for a starter that continues follow-up questions in one session.
diff --git a/docs/agents/skills.mdx b/docs/agents/skills.mdx
new file mode 100644
index 00000000..9102d189
--- /dev/null
+++ b/docs/agents/skills.mdx
@@ -0,0 +1,95 @@
+---
+title: "Skills"
+description: "Package reusable instructions and supporting resources with an agent"
+---
+
+A skill is a reusable instruction bundle that teaches an agent how to perform
+a task. A tool executes code; a skill provides a procedure, checklist, or
+domain playbook the managed coding-agent harness can load when relevant.
+
+## Create a skill
+
+Add a directory containing `SKILL.md` under the agent:
+
+```text
+opencomputer/agents/campaign-writer/
+├── agent.ts
+└── skills/
+ └── campaign-brief/
+ ├── SKILL.md
+ └── CHECKLIST.md
+```
+
+Write a clear name and routing description in the frontmatter, then put the
+full procedure in the body:
+
+```md
+---
+name: campaign-brief
+description: Create a sourced campaign brief. Use when planning a new campaign or revising its audience and messaging.
+---
+
+# Campaign brief
+
+1. Restate the product, audience, goal, and constraints.
+2. Research the audience before proposing messaging.
+3. Separate sourced facts from recommendations.
+4. Produce a positioning statement, three message pillars, and five concepts.
+5. Read `CHECKLIST.md` before returning the final brief.
+```
+
+The description should say both what the skill does and when it applies. It is
+the information the harness uses to decide whether to load the instructions.
+
+## Use the skill
+
+Skills do not need a hook in the current authoring API. OpenComputer packages
+the entire `skills/` directory with that agent, and the managed harness can
+load a matching skill during the session.
+
+Tell the agent when the skill should guide its work:
+
+```tsx
+export default function Agent() {
+ return [
+ "Plan and improve marketing campaigns.",
+ "For a new campaign brief, use the campaign-brief skill and follow its checklist.",
+ ].join(" ");
+}
+```
+
+## Add supporting files
+
+Keep the core procedure in `SKILL.md`. Put longer material beside it:
+
+```text
+campaign-brief/
+├── SKILL.md
+├── CHECKLIST.md
+├── VOICE.md
+└── examples/
+ └── launch-brief.md
+```
+
+Reference those files from `SKILL.md` so the agent knows when to read them.
+Supporting files are deployed with the skill and need no imports from
+`agent.ts`.
+
+## Scope skills to an agent
+
+Skills live under `opencomputer/agents/<agent-id>/skills/`, so each deployment
+receives only its own skill set. To reuse a skill, copy or generate the skill
+directory into each agent that needs it.
+
+## Skills versus tools
+
+| Skill | Tool |
+| --- | --- |
+| Markdown instructions and resources | Executable TypeScript |
+| Teaches a repeatable workflow | Performs a specific operation |
+| Loaded when its description matches | Called with JSON Schema arguments |
+| May tell the agent which tools to use | Produces a JSON-compatible result |
+
+Many useful workflows combine both: a research skill explains the process
+while an [Exa search tool](/agents/examples/exa-research-session) retrieves
+current sources.
diff --git a/docs/agents/subagents.mdx b/docs/agents/subagents.mdx
new file mode 100644
index 00000000..cab0e09e
--- /dev/null
+++ b/docs/agents/subagents.mdx
@@ -0,0 +1,79 @@
+---
+title: "Subagents"
+description: "Let an agent delegate focused work with useSubagent"
+---
+
+A subagent is another agent in the same project that can take a focused task.
+Use `useSubagent()` to make that agent available to the current render.
+
+## Add the specialist
+
+Create a second agent:
+
+```tsx
+// opencomputer/agents/researcher/agent.ts
+import { useModel, useTool } from "@opencomputer/agent";
+
+export default function Agent() {
+ useModel("anthropic/claude-sonnet-4.6");
+ useTool("web-search");
+ return "Research the delegated question. Return sourced findings only.";
+}
+```
+
+Register both agents in the project:
+
+```tsx
+// opencomputer/project.ts
+export default {
+ name: "Campaign workspace",
+ agents: ["campaign-planner", "researcher"],
+};
+```
+
+## Expose it with `useSubagent`
+
+```tsx
+// opencomputer/agents/campaign-planner/agent.ts
+import { useModel, useSubagent } from "@opencomputer/agent";
+
+export default function Agent() {
+ useModel("anthropic/claude-sonnet-4.6");
+ useSubagent("researcher");
+ return [
+ "Plan the campaign from evidence.",
+ "Delegate audience and competitor research to the researcher.",
+ ].join(" ");
+}
+```
+
+The value passed to `useSubagent()` is the agent ID from
+`opencomputer/project.ts`. Give the parent clear instructions about what it
+should delegate and what result it expects.
+
+Inputs created by delegation have `useInput().source === "subagent"`, so the
+specialist can adapt its response:
+
+```tsx
+import { useInput } from "@opencomputer/agent";
+
+export default function Agent() {
+ const input = useInput();
+ return input.source === "subagent"
+ ? "Complete only the delegated research task and return concise findings."
+ : "Help the user research their question.";
+}
+```
+
+## Attach conditionally
+
+Like other resource hooks, `useSubagent()` can be conditional:
+
+```tsx
+const input = useInput();
+if (input.text?.includes("research")) {
+ useSubagent("researcher");
+}
+```
+
+This keeps the delegate unavailable for requests where it adds no value.
diff --git a/docs/agents/tools.mdx b/docs/agents/tools.mdx
new file mode 100644
index 00000000..10a5bf96
--- /dev/null
+++ b/docs/agents/tools.mdx
@@ -0,0 +1,132 @@
+---
+title: "Tools"
+description: "Define TypeScript tools and expose them with useTool"
+---
+
+A tool is TypeScript code the model may call while it works. Use tools for
+actions such as searching an API, looking up an order, or updating an external
+system. The model decides when a tool fits; your `run` function controls what
+happens.
+
+## Define your first tool
+
+Create a tool beside the agent, for example
+`opencomputer/agents/support/tools/lookup-order.ts`:
+
+```tsx
+import { defineTool } from "@opencomputer/agent";
+
+export const lookupOrder = defineTool({
+ name: "lookup_order",
+ description: "Look up an order by ID and return its current status",
+ input: {
+ type: "object",
+ properties: {
+ orderId: { type: "string", description: "The customer order ID" },
+ },
+ required: ["orderId"],
+ additionalProperties: false,
+ },
+ async run({ input }) {
+ const orderId = String(input.orderId);
+ return { orderId, status: "processing" };
+ },
+});
+```
+
+Then attach it from `agent.ts`:
+
+```tsx
+import { useModel, useTool } from "@opencomputer/agent";
+import { lookupOrder } from "./tools/lookup-order";
+
+export default function Agent() {
+ useModel("anthropic/claude-sonnet-4.6");
+ useTool(lookupOrder);
+ return "Help customers check orders. Ask for an order ID before lookup.";
+}
+```
+
+The model sees the tool's name, description, and input schema. When it calls
+the tool, OpenComputer runs `run()` in the managed agent runtime and returns
+the result to the model.
+
+## Tool definition
+
+| Field | Required | Purpose |
+| --- | --- | --- |
+| `name` | yes | ID the model calls; letters, numbers, underscores, and hyphens only |
+| `description` | yes | Explains what the tool does and when to use it |
+| `input` | no | JSON Schema for tool arguments |
+| `output` | no | JSON Schema describing the result |
+| `run` | yes | Synchronous or asynchronous implementation |
+
+Descriptions are the model's documentation. Include the action, when it is
+appropriate, and any important precondition.
+
+## Execution context
+
+The `run` function receives:
+
+| Value | Purpose |
+| --- | --- |
+| `input` | Arguments created for the tool call |
+| `sessionId` | Current session ID |
+| `messageId` | Message containing the tool call |
+| `agentId` | Agent executing the call |
+| `signal` | Optional cancellation signal for abortable work |
+| `reportProgress(metadata)` | Emits JSON-compatible progress metadata |
+
+Use the cancellation signal with `fetch()` and report progress before slow
+steps:
+
+```tsx
+export const importCatalog = defineTool({
+ name: "import_catalog",
+ description: "Import the latest product catalog; use only when asked",
+ async run({ signal, reportProgress }) {
+ await reportProgress({ phase: "downloading" });
+ const response = await fetch("https://example.com/catalog.json", { signal });
+ await reportProgress({ phase: "processing" });
+ return { imported: response.ok };
+ },
+});
+```
+
+Tool results and progress metadata must be JSON-compatible values.
+
+## Conditional tools
+
+`useTool()` may be conditional. This keeps sensitive or specialized actions
+out of the tool set until they are relevant:
+
+```tsx
+import { useInput, useTool } from "@opencomputer/agent";
+import { issueRefund } from "./tools/issue-refund";
+
+export default function Agent() {
+ const input = useInput();
+
+ if (input.text?.toLowerCase().includes("refund")) {
+ useTool(issueRefund);
+ }
+
+ return "Resolve the support request. Confirm the order before a refund.";
+}
+```
+
+`useTool()` also accepts a tool ID such as `useTool("web-search")` when the
+runtime already provides that tool.
+
+## Call external APIs safely
+
+Do not embed API keys in a tool or read them from the runtime environment.
+Declare an HTTP connection, store the value as an OpenComputer secret, and
+call the connection's managed `fetch()` method. See [Secrets and managed
+egress](/agents/secrets) for a complete example.
+
+## Tools versus skills and MCP
+
+- A tool executes TypeScript you own.
+- A [skill](/agents/skills) teaches the agent a reusable procedure.
+- An [MCP server](/agents/mcp) supplies a remote collection of tools.
diff --git a/docs/docs.json b/docs/docs.json
index 6a8322ac..b982ab8b 100644
--- a/docs/docs.json
+++ b/docs/docs.json
@@ -33,12 +33,26 @@
"agents/quickstart",
"agents/projects",
"agents/reactive-agents",
+ "agents/hooks",
+ "agents/inputs",
+ "agents/models",
+ "agents/tools",
+ "agents/mcp",
+ "agents/skills",
+ "agents/subagents",
+ "agents/session-data",
"agents/sessions",
"agents/connections",
"agents/secrets",
"agents/logs",
"agents/channels"
]
+ },
+ {
+ "group": "Examples",
+ "pages": [
+ "agents/examples/exa-research-session"
+ ]
}
]
},
diff --git a/docs/llms.txt b/docs/llms.txt
index 65b06356..1d43f789 100644
--- a/docs/llms.txt
+++ b/docs/llms.txt
@@ -8,8 +8,20 @@
- [Quickstart](https://docs.opencomputer.dev/agents/quickstart.md): Create a project and sync its first agent to Development (Cloud).
- [Projects and agents](https://docs.opencomputer.dev/agents/projects.md): Organize multiple agents and a React application.
- [Reactive agents](https://docs.opencomputer.dev/agents/reactive-agents.md): Render instructions, models, tools, subagents, connections, and MCP servers from code.
+- [Agent hooks](https://docs.opencomputer.dev/agents/hooks.md): Compose agent capabilities with reactive hooks.
+- [Inputs](https://docs.opencomputer.dev/agents/inputs.md): Read text, structured payloads, and input sources with `useInput()`.
+- [Models](https://docs.opencomputer.dev/agents/models.md): Select a managed model with `useModel()`.
+- [Tools](https://docs.opencomputer.dev/agents/tools.md): Define TypeScript tools and expose them with `useTool()`.
+- [MCP servers](https://docs.opencomputer.dev/agents/mcp.md): Attach managed HTTPS MCP servers with `useMcpServer()`.
+- [Skills](https://docs.opencomputer.dev/agents/skills.md): Package reusable instructions and supporting resources with an agent.
+- [Subagents](https://docs.opencomputer.dev/agents/subagents.md): Let an agent delegate focused work with `useSubagent()`.
+- [Session data](https://docs.opencomputer.dev/agents/session-data.md): Read durable per-session values with `useSessionData()`.
- [Sessions and playground](https://docs.opencomputer.dev/agents/sessions.md): Create and inspect durable conversations.
- [Connections and MCP](https://docs.opencomputer.dev/agents/connections.md): Attach user-scoped services and managed MCP servers from code.
- [Secrets and managed egress](https://docs.opencomputer.dev/agents/secrets.md): Store scoped secrets and inject them only into declared outbound requests.
- [Logs](https://docs.opencomputer.dev/agents/logs.md): Inspect and follow runtime and managed-egress logs.
- [Channels](https://docs.opencomputer.dev/agents/channels.md): Connect deployed agents to Slack.
+
+## Examples
+
+- [Exa research session](https://docs.opencomputer.dev/agents/examples/exa-research-session.md): Start from a React web-research agent with live Exa results, source links, and durable follow-up questions.