For a person or a model about to write an app; a model gets the same text from oad guide.
# Agents
An app can be used by agents as well as people. The agent surface turns the app's actions into tools an agent calls and its state into resources it reads. There is no separate logic for agents: a tool is an action, with the same `allow`, `require` and `confirm`.
## The agent surface
```json example=reading#/surfaces/agent
{
"instructions": "Use addBook once per book, with the author when the person gives one. Read books to say what is on the list. removeBook asks the person to confirm.",
"tools": {
"include": ["addBook", "setStatus", "removeBook"],
"describe": { "setStatus": "Say whether the person has not started a book, is reading it, or has read it. Take its id from the books resource." }
},
"resources": { "include": ["books", "toRead"] },
"events": { "include": ["allRead"] }
}
```
The surface exists only when `surfaces.agent` is there: `"agent": {}` is a complete one, and without the key an app gives agents nothing.
| Field | What it does |
| --- | --- |
| `instructions` | What an agent should know to use the app well: which tool to use for what, units, what needs the person. |
| `tools` | Every action that is not `internal` is a tool. `include` or `exclude` (one of them) narrows the list; `describe` replaces an action's description for agents. |
| `resources` | Every state entry that is neither sensitive nor `internal` is a resource. `include` or `exclude` narrows the list; `include` is the only way to give an agent a sensitive entry. |
| `events` | App events (from `emit`) and `flow:<name>` that an agent is told of when work done for its person raises them. |
A name in these lists must exist (`surface.unknownName`), and an `internal` entry or action cannot be included (`state.internal`, `action.internal`):
```json wrong=reading#/surfaces/agent/resources expect=state.internal
{ "include": ["heading"] }
```
## What makes a good tool
- **The description is the documentation.** An agent learns what a tool does from the action's `description` (or its `describe` text) and the descriptions of its input fields. Say what the action does, what each field means, and its units.
- **Inputs with defaults.** An agent leaves out what it does not know; a field with a `default` lets it.
- **Refusals with words.** A `require` entry's `message` reaches the agent, which can tell the person or try again. An `allow` refusal says nothing, and an unknown tool, an `internal` action and an action the agent may not use are refused alike (`action.forbidden`).
- **Return something useful.** `output` and `return` give the agent what it needs next, such as the id of what it created.
## What an agent may do
An agent acts for a person, with the access that person gave it, and never with more. In expressions, `user` is the agent (`user.kind` is `agent`) and `user.person` is the person it acts for (see `people` for records and acts that belong to the person). So:
- An action with `confirm` asks the person, never the agent. The agent's call waits for the answer, and fails with `action.declined` when the person says no.
- An agent never runs a screen's handlers or writes a binding: only tools.
## Keeping things from agents
- Mark an entry `"sensitive": true` to keep it off the surface unless `resources.include` names it, or `"internal": true` so it is never a resource (see `state`).
- Mark an action `"internal": true` for steps that only the app's own screens and steps should run.
## Trying it
`oad run reading.oad.json --agent` starts the app and serves the agent surface, printing where an agent connects and a client configuration for it.
## Next
- `actions` for descriptions, input, `require` and `confirm`.
- `people` for who the agent acts for.
- `state` for `sensitive` and `internal`.
Contents
An app can be used by agents as well as people. The agent surface turns the app's actions into tools an agent calls and its state into resources it reads. There is no separate logic for agents: a tool is an action, with the same allow, require and confirm.
{"instructions":"Use addBook once per book, with the author when the person gives one. Read books to say what is on the list. removeBook asks the person to confirm.","tools":{"include":["addBook","setStatus","removeBook"],"describe":{"setStatus":"Say whether the person has not started a book, is reading it, or has read it. Take its id from the books resource."}},"resources":{"include":["books","toRead"]},"events":{"include":["allRead"]}}
The surface exists only when surfaces.agent is there: "agent": {} is a complete one, and without the key an app gives agents nothing.
Field
What it does
instructions
What an agent should know to use the app well: which tool to use for what, units, what needs the person.
tools
Every action that is not internal is a tool. include or exclude (one of them) narrows the list; describe replaces an action's description for agents.
resources
Every state entry that is neither sensitive nor internal is a resource. include or exclude narrows the list; include is the only way to give an agent a sensitive entry.
events
App events (from emit) and flow:<name> that an agent is told of when work done for its person raises them.
A name in these lists must exist (surface.unknownName), and an internal entry or action cannot be included (state.internal, action.internal):
The description is the documentation. An agent learns what a tool does from the action's description (or its describe text) and the descriptions of its input fields. Say what the action does, what each field means, and its units.
Inputs with defaults. An agent leaves out what it does not know; a field with a default lets it.
Refusals with words. A require entry's message reaches the agent, which can tell the person or try again. An allow refusal says nothing, and an unknown tool, an internal action and an action the agent may not use are refused alike (action.forbidden).
Return something useful.output and return give the agent what it needs next, such as the id of what it created.
An agent acts for a person, with the access that person gave it, and never with more. In expressions, user is the agent (user.kind is agent) and user.person is the person it acts for (see people for records and acts that belong to the person). So:
An action with confirm asks the person, never the agent. The agent's call waits for the answer, and fails with action.declined when the person says no.
An agent never runs a screen's handlers or writes a binding: only tools.
Mark an entry "sensitive": true to keep it off the surface unless resources.include names it, or "internal": true so it is never a resource (see state).
Mark an action "internal": true for steps that only the app's own screens and steps should run.