Skip to content

An open-source, faster Devin alternative

TypeScript

docs: approval is an option on defineTool, and secrets can be scoped to a tenant or a person — the tools page still taught a defineGatedTool that no longer exists, and useSecret's scope was undocumented entirely despite being the thing that stops one deployment handing every customer's agent every other customer's credential

Brian Reardon4acfa1f7e7e4
diff --git a/docs/agents/capabilities.mdx b/docs/agents/capabilities.mdx
index 6adb7a95..1938a3db 100644
--- a/docs/agents/capabilities.mdx
+++ b/docs/agents/capabilities.mdx
@@ -9,6 +9,7 @@ the narrowest capability that fits the job.
| Capability | Use it for | Where the work happens | How it is attached |
| --- | --- | --- | --- |
| Code-defined tool | One typed operation you implement | Your TypeScript `run()` function | `useTool(tool)` |
+| Tool that waits for approval | A write a person should agree to first | Your `preview()` shows it; your `apply()` runs after a decision | `useTool(tool)` — the same tool, defined with `preview`/`apply` instead of `run` |
| MCP server | A service that already publishes a collection of tools | The remote MCP server | `useMcpServer(server)` |
| Skill | A reusable procedure, checklist, or supporting files | The agent follows the loaded instructions | Place it under `skills/` |
| Subagent | Delegating a focused task to another project agent | The delegated agent | `useSubagent(agentId)` |
diff --git a/docs/agents/secrets.mdx b/docs/agents/secrets.mdx
index 0b05d5cd..4afee5b1 100644
--- a/docs/agents/secrets.mdx
+++ b/docs/agents/secrets.mdx
@@ -92,6 +92,69 @@ npx --package @opencomputer/cli opencomputer secrets remove GITHUB_TOKEN --envir
List output contains metadata such as the name, scope, environment, and
allowed origins. Secret values are never returned.
+## Scope a secret to a tenant or a person
+
+One deployment answers every installation of a channel app, and each
+installation may be a different customer with their own account. A project
+secret would mean every customer's agent holding every other customer's
+credential.
+
+`useSecret` takes a scope:
+
+```tsx
+import { bearer, defineConnection, useSecret } from "@opencomputer/agent";
+
+export const billing = defineConnection({
+ id: "billing",
+ origin: "https://api.example.com",
+ headers: {
+ // Resolved from the installation this message arrived through.
+ Authorization: bearer(useSecret("BILLING_API_KEY", { scope: "tenant" })),
+ },
+});
+```
+
+| Scope | Resolved from | Use it for |
+| --- | --- | --- |
+| `project` | the project (default) | A credential that is yours, not a customer's |
+| `tenant` | the channel installation the message arrived through | One account per customer workspace |
+| `user` | the person being acted for | A write that should carry someone's own authority |
+
+Both are fixed when the session starts, so nothing the model says or is sent
+can influence which credential it gets.
+
+For a [tool that waits for approval](/agents/tools#wait-for-a-person-before-writing)
+the two scopes behave differently, and the difference is deliberate. The write
+inherits the **tenant** of the proposal, so a card approved hours later still
+applies to the right account. But it runs as the **person who approved it**,
+not the person who asked — so a `user`-scoped credential is the approver's.
+A billing change is then made with the authority of whoever took
+responsibility for it.
+
+**They fail closed.** If no secret is set for that tenant or user, the request
+is refused and never leaves the runtime. There is no fallback to the project
+secret, because that fallback is the leak this prevents. Someone who has not
+connected their own account can still propose a change; they cannot apply one.
+
+Set them per installation, or per person on an installation:
+
+```bash
+# The installation's own credential
+curl -X PUT ".../v1/channels/slack/apps/$APP/installations/$CONNECTION/secrets/BILLING_API_KEY" \
+ -H "x-api-key: $OPENCOMPUTER_API_KEY" -H "content-type: application/json" \
+ -d '{"value":"...","allowedOrigins":["https://api.example.com"]}'
+
+# One person's own credential on that installation
+curl -X PUT ".../v1/channels/slack/apps/$APP/installations/$CONNECTION/users/$USER/secrets/BILLING_API_KEY" \
+ -H "x-api-key: $OPENCOMPUTER_API_KEY" -H "content-type: application/json" \
+ -d '{"value":"...","allowedOrigins":["https://api.example.com"]}'
+```
+
+`GET` the same path without a name to list what is set, and `DELETE` with a
+name to remove one. Values are write-only: listing returns names and allowed
+origins, never a value. You can also pass `secrets` when importing an
+installation, so a tenant is never live and unconfigured.
+
## Agent runtime variables
Use an agent runtime variable when code or a command must receive a value as a
diff --git a/docs/agents/tools.mdx b/docs/agents/tools.mdx
index 064a67a7..37e3db59 100644
--- a/docs/agents/tools.mdx
+++ b/docs/agents/tools.mdx
@@ -59,7 +59,11 @@ the result to the model.
| `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 |
+| `run` | yes* | Synchronous or asynchronous implementation |
+| `preview` / `apply` | no | Supply these *instead of* `run` to [wait for a person](#wait-for-a-person-before-writing) |
+
+\* A tool has either `run`, or `preview` and `apply` — never both, and never
+just one of the pair.
Descriptions are the model's documentation. Include the action, when it is
appropriate, and any important precondition.
@@ -127,15 +131,21 @@ call the connection's `fetch()` method. See
## Wait for a person before writing
-Some writes should not happen because a model decided they should. A gated tool
+Some writes should not happen because a model decided they should. Such a tool
proposes instead: the model calls it, nothing is written, and the person the
agent is talking to sees a card with the exact change and decides.
+There is no separate primitive for this. Give `defineTool` a `preview` and an
+`apply` instead of a `run`, and the model's call becomes a proposal. `run` is
+written for you. `useTool` selects the tool exactly as it selects any other,
+and the model cannot tell the difference — waiting for approval is a property
+of a tool, not a different kind of thing.
+
```tsx
-import { defineGatedTool } from "@opencomputer/agent";
+import { defineTool } from "@opencomputer/agent";
import { billing } from "./connections/billing";
-export const attach = defineGatedTool({
+export const attach = defineTool({
name: "attach",
description: "Move a customer onto a plan",
input: {
@@ -195,18 +205,18 @@ is what makes it safe.
### What this does and does not guarantee
-A gated tool is a convention your code cooperates with. Nothing stops a tool
-from writing inside `preview`. What the platform guarantees is narrower and
+Approval is a convention your code cooperates with. Nothing stops a tool from
+writing inside `preview`. What the platform guarantees is narrower and
still worth having: an approved write runs **once**, from the arguments the
person agreed to, whether or not the session that proposed it still exists.
-Gated tools need a conversation to ask in. Called from the playground, a
-schedule or a webhook, there is nobody to ask, and the call fails saying so.
+A tool that waits needs a conversation to ask in. Called from the playground,
+a schedule or a webhook, there is nobody to ask, and the call fails saying so.
## Tools versus skills and MCP
- A tool executes TypeScript you own.
-- A [gated tool](#wait-for-a-person-before-writing) does the same, once a
- person approves it.
+- The same tool with `preview` and `apply` instead of `run`
+ [waits for a person](#wait-for-a-person-before-writing) before it does it.
- A [skill](/agents/skills) teaches the agent a reusable procedure.
- An [MCP server](/agents/mcp) supplies a remote collection of tools.