# Add verbs and buttons

AI agent getting started? Read [Agents: start here](https://docs.openeng.io/agents/start-here.md) first.

Define a validated operation and make it available from a view.

Source: https://docs.openeng.io/configure/verbs/

A verb is a named operation defined in your ontology. It accepts declared inputs and runs a defined change with the user's permissions. Use one when people or agents should perform a meaningful operation, such as closing a requirement, rather than construct its mutations themselves.

## Define the operation

A verb declares the types it can act on, its input and result schemas, and an implementation. A template implements a bounded sequence of object and relationship changes. It can use the selected object, declared inputs and results from earlier steps.

For example, a close-requirement template changes a requirement's status from `open` to `closed`. This example needs a Requirement type whose status accepts those exact values; it is not a verb bundled with the turbine demo.

The template checks that the status is still `open` before changing it, so it cannot silently overwrite a newer value.

## Publish a verb

Save this complete change-set input as `close-requirement.json`. It assumes a published `requirement` type with the `open` and `closed` status values described above:

```json
{
  "close_requirement": {
    "typeCategory": "verb",
    "typeKey": "close_requirement",
    "version": 1,
    "displayName": "Close requirement",
    "description": "Close an open requirement.",
    "allowedSubjectTypes": {
      "kind": "types",
      "types": [
        "requirement"
      ]
    },
    "inputSchema": {
      "kind": "null"
    },
    "resultSchema": {
      "kind": "null"
    },
    "template": {
      "operations": [
        {
          "kind": "update-object",
          "typeKey": "requirement",
          "target": {
            "slot": "subject"
          },
          "changes": {
            "status": {
              "from": {
                "slot": "literal",
                "value": "open"
              },
              "to": {
                "slot": "literal",
                "value": "closed"
              }
            }
          }
        }
      ]
    },
    "schemaLanguageVersion": "1"
  }
}
```

Use the [type publication sequence](https://docs.openeng.io/configure/types.md#put-it-in-a-complete-type-definition), substituting this file for the requirement example. Include any other intended draft changes in the revision; do not replace someone else's open work. Validate the complete change set, inspect its diff and accept only the revision you reviewed.

## Discover and execute

Discover the verb on an existing requirement with status `open`:

```sh
openeng objects-sdk discoverVerbs --selector '{"projectId":"<project-id>","ref":"<branch>"}' --input '{"objectId":"<object-id>"}'
```

Use the returned type key and version. For the example's first published version:

```sh
openeng objects-sdk executeVerb --selector '{"projectId":"<project-id>","ref":"<branch>"}' --input '{"verb":{"typeKey":"close_requirement","typeVersion":1},"subjectIds":["<object-id>"],"input":null,"reason":"<why the verb runs>"}'
```

Replace the placeholders with the returned project, branch and object identifiers. The `reason` says why the verb runs; the platform writes it first in the commit message. Keep the idempotency key printed by the CLI.

Read back the object after success. For the example, the status should be `closed` on your working branch. If the result is uncertain, follow [write recovery](https://docs.openeng.io/developers/overview.md#write-through-a-branch) before retrying.

## Add a button

In an object view, a Button can call the verb for the displayed object:

```json
{
  "type": "Button",
  "props": {
    "label": "Close requirement",
    "variant": "secondary"
  },
  "children": [],
  "on": {
    "press": {
      "action": "run-verb",
      "params": {
        "verb": "close_requirement"
      }
    }
  }
}
```

Add the element to the view's tree and validate the type change. In a collection or app page, a button needs an object context from a supported repeated list or table. Validation checks placement and the verb's allowed subject type.

A button does not add authority. Project access, branch rules and object locks still apply. See [View components](https://docs.openeng.io/reference/view-components.md#button) for exact supported placement.
