# Tool guides

Every schema ships in every request, and long schemas are read less carefully. A tool keeps a short schema; the agent loop delivers its other instructions into tool results. Single-entry tools use this: one tool, a few parameters, the instructions for each target or action on first use. Codex computer use and Claude Code skills are the same progressive disclosure.

## Declaring

```
guides.register("self_update", [
    Guide("self_update", overview, mode="open", activates=("worktree_create",)),
    Guide("self_update.prepare", prepare_text, summary="parameters, iteration policy and verification plan",
          required_for=lambda args: args.get("action") == "prepare"),
])
```

| Field | Meaning |
| --- | --- |
| `name` | Dotted name passed to `help`; unique across tools |
| `text` | The guide, or a function returning it (platform variants, lists read from code) |
| `when(args)` | Calls an `included` or `on_error` guide applies to; for `lookup`, whether it is in the index |
| `required_for(args)` | Calls that may not run until the guide is known |
| `activates` | Deferred tools the guide teaches; delivery ends the guide with a line naming them and the `tool_search select:` call that loads them ([Deferred tools](https://fzkuji.github.io/OpenProgram/docs/reference/design/function/deferred-tools.html#activation)) |

| `mode` | Delivered | Use for |
| --- | --- | --- |
| `open` | First result of the tool | What every use needs |
| `included` | First result of a call matching `when` | One target or platform |
| `lookup` | Indexed by name and `summary`; read with `help` | With `required_for`: costly mistakes, long arguments. Without: situational background |
| `on_error` | A failed result of a matching call | Recovery advice |

`open` and `included` guides end with the index of the tool's applicable lookup guides.

## Delivery

1. `_run_loop` opens a view (`guides.begin_loop`). Outside a loop guides do nothing: direct Python calls and tests see plain results.
2. Before each model request, `_stream_assistant_response` records the text being sent (`guides.observe_request`).
3. Before a call is decided, `prechecks.call_problem` returns `GUIDE_REQUIRED` if a `required_for` guide is unknown: an ordinary tool error, no approval card. The model reads the attached guide and calls again.
4. When a call ends, `_rewrite_tool_result` (`guides.attach`) records due guides, each wrapped in `<guide name="…">`, on the result's attachment (`details["attachment"]`), not in the tool's own text; they are sent after the group of results and counted as part of the request's text ([Tool output](https://fzkuji.github.io/OpenProgram/docs/reference/design/context/overview.html#cross-turn-tool-context)).

A guide is **known** while its marker is in the last request's text, or it was delivered since. No ledger: compaction, microcompaction, a worker restart or a fresh agent removes the marker, and the next call that needs the guide receives it. An agent whose prompt already holds a marked guide is not sent it again.

## `help`

`help(name)` is a resident tool that returns a guide, or a tool's opening guide for a tool name, marked like any delivered guide. No approval; `runtime.control` authority. An unknown name lists the guides. Inside `computer_use` code, Python's `help` and `dir` work on the `cu` object, the call's target: each docstring is its action's line from the family guide.

## Single entries

| Tool | Guides |
| --- | --- |
| `self_update` | `self_update`: open, activates `worktree_create`. `.prepare`, `.retry`, `.undo`: lookup, required for that action |
| `computer_use` | `.app`, `.screen`, `.browser`: a family guide, included when a call operates a target of that family. `.note.<target>`: the target note (its machine, operating system, what it lacks, its shortcut keys), included when a call operates that target. `.code`: included with the first call operating any target; no call waits for it |

Two levels: the tool, then an `action` or `target`. Permission, authority and approval decide per action.

| `self_update` action | Authority | Approval |
| --- | --- | --- |
| `status`, `versions` | `fs.read` | None |
| `begin` | `process.exec` | None |
| `cancel` | `runtime.control` | None |
| `prepare`, `retry`, `undo` | `process.exec` | Owner (`APPROVED_ACTIONS`) |

Argument-only checks run before the approval card, after the guide check: a `prepare` with a malformed SHA, or an out-of-bounds iteration policy or verification plan, returns `INVALID_ARGUMENTS`.

**Implementation files**

- `openprogram/programs/_authoring/guides.py`, `prechecks.py`
- `openprogram/programs/tools/runtime/help.py`
- `openprogram/runtime/agent/loop/`: `_run_loop`, `_stream_assistant_response`, `_rewrite_tool_result`
- `openprogram/runtime/permissions/policy.py`: `permission_decision`
- `openprogram/programs/tools/system/self_update/__init__.py`
- `openprogram/programs/tools/computer_use/computer_use/type_guides.py`, `code_mode/calls.py`
- `tests/unit/programs/test_guides.py`, `test_prechecks.py`
