> ## Documentation Index
> Fetch the complete documentation index at: https://docs.goyappr.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Teach an agent from a test call

> Update a workflow agent's instructions from what you said on a web test call, and publish them live.

Requires `agents:update` and `calls:read` (reading the run needs `agents:read` and `calls:read`): Teach reads the call's transcript. After a **web test call** (a call made from the
dashboard's test panel or a test link), you can tell the agent what to do
differently, in your own words, during the call. Teach reads the finished call,
makes a small checked edit to the agent's instructions, and publishes it live.
The next call runs the new instructions.

**id** `string` *required*

Local agent UUID. It must be the agent the call was made to.

**call\_id** `string` *required*

The finished web test call's id.

**retry** `boolean` (default: false)

`true` runs again a run that ended `held` or `failed`, up to 5 times per run.

```bash theme={null}
curl -X POST 'https://api.goyappr.com/agents/AGENT_ID/workflow/train' \
  -H 'Authorization: Bearer YOUR_API_KEY' \
  -H 'x-company-id: COMPANY_ID' \
  -H 'Content-Type: application/json' \
  -d '{"call_id":"CALL_ID"}'
```

## Who and what it works on

* **Web test calls only.** A phone call is refused with `422 TEACH_CALL_NOT_WEB`.
  The call must be less than 30 minutes old and must have run on the agent's
  version that is live now (`409 TEACH_CALL_NOT_ON_LIVE_VERSION` otherwise).
* **Owner or admin only.** The API key's owner must be an owner or admin of the
  workspace (`403 TEACH_FORBIDDEN_ROLE`). Any owner or admin of the workspace can
  teach from a recent browser test call of the agent, not only the person who took
  the call. A key with no owner is refused with `403 TEACH_ACTOR_REQUIRED`.
* **Workflow agents with a published version.** Other agents answer
  `422 AGENT_ENGINE_UNSUPPORTED` or `422 TEACH_AGENT_NOT_PUBLISHED`.
* **Three applied runs per agent in 24 hours** (`429 TEACH_DAILY_LIMIT`), and one
  run at a time per agent (`409 TEACH_AGENT_BUSY`).

## It is idempotent per call

Sending the same request again returns the same run, so the way to wait is to
send it again. The answer is `200` when the run has finished and `202` while it
is working:

```json theme={null}
{ "run": { "id": "…", "status": "running", "step": "llm", "retry_after_ms": 3000 }, "retry_after_ms": 3000 }
```

Wait `retry_after_ms` and send the same request. If the call has not ended yet,
the answer is `202` with `run: null` and `wait: "call_running"`. A run that
finished is never started again for the same call, except by `retry`.

## What a finished run says

`status` is one of:

| Status | Meaning |
| - | - |
| `applied` | The new instructions are live. `changes[]` shows each edit as it read before and after, with the words you said that it rests on, and `summary` is one sentence on what changed, or `null` when none could be written (read `changes[]`). |
| `no_change` | There was nothing to change (you gave no instruction, the call was too short, the request was only role-play, or it was about the opening line, which Teach does not edit). `reason` says which. |
| `held` | Refused on purpose, and nothing live changed: the edit would have gone beyond a small change, lost a tool or a variable, touched a number or a prohibition the call did not support, or the agent had unpublished changes in its draft. `reason` and `reasons[]` say why. |
| `failed` | Something went wrong (the transcript did not arrive, the model did not answer, publishing could not be confirmed). `can_retry` says whether `retry: true` is allowed; it is `false` for anyone but the person who requested the run. |
| `reverted` | The run was undone from the dashboard. |
| `claimed`, `waiting_transcript`, `running`, `put_done` | In progress. Ask again after `retry_after_ms`. |

`GET /agents/{id}/workflow/train?call_id=CALL_ID` returns the same run without
starting or changing anything (`run` is `null` when nobody taught from that call).

## Undo

An applied run publishes a new version. To undo it, call
[Restore workflow version](https://docs.goyappr.com/api-reference/workflows/restore.md) with the run's
`base_revision.id`. The restore is a roll-forward: it publishes the earlier
workflow as another new version and is not guaranteed to be byte-identical to
it. In the version list the run's version shows `source: "teach"`, and the
restored one `source: "restore"`.

## Refusals

| Status | Code | Meaning |
| - | - | - |
| 400 | `WORKFLOW_REQUEST_INVALID` | `call_id` missing or not a UUID, another field, or a query parameter. |
| 403 | `TEACH_FORBIDDEN_ROLE`, `TEACH_ACTOR_REQUIRED`, `TEACH_DISABLED` | See above. `TEACH_DISABLED`: teaching is switched off. |
| 404 | `AGENT_NOT_FOUND`, `TEACH_CALL_NOT_FOUND`, `TEACH_RUN_NOT_FOUND` | Nothing with that id in this workspace. |
| 409 | `TEACH_AGENT_BUSY`, `TEACH_CALL_NOT_ON_LIVE_VERSION`, `TEACH_RETRY_NOT_ALLOWED` | Another run is working on the agent; the call ran on an older version; the run cannot be retried (not `held` or `failed`, 5 retries used, or another owner or admin started the run, in which case the answer's `reason` is `not_requester`). |
| 422 | `TEACH_CALL_AGENT_MISMATCH`, `TEACH_CALL_NOT_WEB`, `TEACH_CALL_TOO_OLD`, `TEACH_CALL_RUN_UNAVAILABLE`, `TEACH_ENVIRONMENT_MISMATCH`, `AGENT_ENGINE_UNSUPPORTED`, `TEACH_AGENT_NOT_PUBLISHED` | The call or the agent cannot be taught from. |
| 429 | `TEACH_DAILY_LIMIT` | Three applied runs for this agent in the last 24 hours. |

Every refusal carries `error` and `code`; see [Errors](https://docs.goyappr.com/api-reference/errors.md#teach).


## OpenAPI

````yaml POST /agents/{id}/workflow/train
openapi: 3.1.0
info:
  title: Yappr API
  description: >
    Create and manage AI voice agents, purchase phone numbers, configure tools,
    and initiate calls — all via REST.
  version: 1.0.0
  contact:
    url: https://goyappr.com
servers:
  - url: https://api.goyappr.com
    description: Production
security:
  - apiKey: []
paths:
  /agents/{id}/workflow/train:
    parameters:
      - in: path
        name: id
        required: true
        schema:
          type: string
          format: uuid
      - in: header
        name: x-company-id
        schema:
          type: string
          format: uuid
        description: >-
          Explicit active workspace. Optional; when sent it must be the API
          key's own workspace — any other value is refused with 403
          WORKSPACE_MISMATCH.
    post:
      tags:
        - Workflows
      summary: Teach the agent from a test call
      description: >
        Requires agents:update and calls:read (it reads the call's transcript).
        Reads a finished web test call (a call made from the dashboard's test
        panel or a test link; never a phone call) and, when the person testing
        told the agent how to behave, rewrites that agent's instructions and
        publishes the result live. The call must be a recent browser test call
        of this agent (any owner or admin of the workspace can teach from it,
        not only the person who took it), the API key's owner must be an owner
        or admin of the workspace, the agent must run a published workflow, and
        the call must have run on the agent's current version. The edit is small
        and checked (a few changes at most, wording that was not asked for is
        refused, tools and numbers are protected); when it cannot be applied
        safely the run ends held and nothing changes. Idempotent per call_id:
        sending the same request again returns the same run, so repeat it to
        poll. The answer is 200 when the run has finished and 202 while it is
        working (wait retry_after_ms and send it again). To undo an applied run,
        restore its base_revision with POST /agents/{id}/workflow/restore.
      operationId: trainWorkflow
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/WorkflowTrainRequest'
      responses:
        '200':
          description: The run has finished (applied, no_change, held, failed or reverted).
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/WorkflowTrainResponse'
        '202':
          description: >-
            The run is still working, or the call has not ended yet (run null,
            wait call_running). Send the same request again after
            retry_after_ms.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/WorkflowTrainResponse'
        '400':
          description: >-
            WORKFLOW_REQUEST_INVALID: call_id missing or not a UUID, another
            field, or a query parameter.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/WorkflowError'
        '401':
          description: >-
            MISSING_KEY, INVALID_KEY or EXPIRED_KEY - the key was not accepted.
            A valid key without the scope this operation needs is 403
            INSUFFICIENT_SCOPE, naming the scope.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Error'
        '403':
          description: >-
            TEACH_FORBIDDEN_ROLE (the key's owner is not an owner or admin),
            TEACH_DISABLED (teaching is switched off), TEACH_ACTOR_REQUIRED (the
            key has no owner to act as) or WORKSPACE_MISMATCH.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TeachError'
        '404':
          description: AGENT_NOT_FOUND, TEACH_CALL_NOT_FOUND or TEACH_RUN_NOT_FOUND.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TeachError'
        '409':
          description: >-
            TEACH_AGENT_BUSY (another run is working on this agent),
            TEACH_CALL_NOT_ON_LIVE_VERSION (the call ran on an older version
            than the one live now) or TEACH_RETRY_NOT_ALLOWED.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TeachError'
        '422':
          description: >-
            AGENT_ENGINE_UNSUPPORTED, TEACH_AGENT_NOT_PUBLISHED,
            TEACH_CALL_AGENT_MISMATCH (the call is another agent's),
            TEACH_CALL_NOT_WEB (a phone call), TEACH_CALL_TOO_OLD (older than 30
            minutes), TEACH_CALL_RUN_UNAVAILABLE or TEACH_ENVIRONMENT_MISMATCH.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TeachError'
        '429':
          description: >-
            TEACH_DAILY_LIMIT: three applied runs for this agent in the last 24
            hours.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TeachError'
        '500':
          description: TEACH_INTERNAL.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/TeachError'
components:
  schemas:
    WorkflowTrainRequest:
      type: object
      additionalProperties: false
      required:
        - call_id
      properties:
        call_id:
          type: string
          format: uuid
          description: The finished web test call to teach from, the call's id.
        retry:
          type: boolean
          default: false
          description: >-
            True starts a run that ended held or failed again (up to 5 times per
            run).
    WorkflowTrainResponse:
      type: object
      required:
        - run
      properties:
        run:
          oneOf:
            - type: 'null'
            - $ref: '#/components/schemas/WorkflowTrainRun'
        wait:
          type: string
          const: call_running
          description: >-
            Present with run null while the call has not ended; ask again after
            retry_after_ms.
        retry_after_ms:
          type: integer
    WorkflowError:
      allOf:
        - $ref: '#/components/schemas/Error'
        - type: object
          required:
            - code
          properties:
            error:
              type: string
            code:
              type: string
            warnings:
              type: array
              description: >
                On WORKFLOW_VALIDATION_FAILED from Check or publish, the
                advisories beside the issues, in the shape of
                WorkflowValidation's warnings - strict_off_guidance when
                strict_mode is off, and every advisory about a binding or an
                input. The compiler's own graph advisories
                (during_output_advisory, sequence_branch_advisory,
                before_reference_missing_fallback, override_needs_strict,
                after_ending_coverage, after_any_end_waits,
                before_budget_inbound) arrive once the document compiles.
              items:
                type: object
                required:
                  - code
                  - message
                properties:
                  code:
                    type: string
                  message:
                    type: string
                  path:
                    type: string
                    maxLength: 1000
                  node_id:
                    type: string
                    maxLength: 64
                  label:
                    type: string
                    maxLength: 200
                    description: The step's label. Present only with node_id.
                  tool_name:
                    type: string
                    maxLength: 200
                  field:
                    type: string
                    maxLength: 200
            issues:
              type: array
              maxItems: 100
              items:
                type: object
                required:
                  - code
                  - path
                  - message
                properties:
                  code:
                    type: string
                    maxLength: 100
                  path:
                    type: string
                    maxLength: 1000
                  message:
                    type: string
                    maxLength: 2000
                  node_id:
                    type: string
                    maxLength: 64
                    description: >-
                      The step the issue belongs to - a conversation step, a
                      before-call step, a follow-up or a step inside a sequence,
                      by its `id`. An issue about a binding names the first step
                      that runs or offers it; absent only when no single step is
                      concerned (a binding no step uses, a schema).
                  label:
                    type: string
                    maxLength: 200
                    description: >-
                      That step's label, as the workflow document spells it - on
                      every code. Present only with `node_id`.
                  tool_name:
                    type: string
                    maxLength: 200
                    description: >-
                      On an issue about a binding, the name of the tool it runs.
                      `label` is never the tool's name.
                  field:
                    type: string
                    maxLength: 200
                    description: >-
                      On an issue about one input of a binding
                      (`/bindings/{n}/inputs/{field}`), that input's name.
    Error:
      type: object
      required:
        - error
        - code
      description: >
        Every error response - the secret-key API and the browser data plane
        alike - carries a

        human-readable `error` and a stable machine `code`, and a refusal that
        names what is

        wrong with the request carries `issues[]` too. Branch on `code`, never
        on the `error`

        text. A refusal that names nothing more specific carries the code its
        status means:

        `BAD_REQUEST` (400), `UNAUTHORIZED` (401, the browser data plane; the
        secret-key API

        answers `MISSING_KEY`, `INVALID_KEY` or `EXPIRED_KEY`), `BILLING_ERROR`
        (402),

        `FORBIDDEN` (403), `NOT_FOUND` (404), `METHOD_NOT_ALLOWED` (405),
        `CONFLICT` (409),

        `GONE` (410), `PAYLOAD_TOO_LARGE` (413), `UNSUPPORTED_MEDIA_TYPE` (415),

        `UNPROCESSABLE_REQUEST` (422), `RATE_LIMIT` (429), `INTERNAL_ERROR`
        (500),

        `UPSTREAM_ERROR` (502), `SERVICE_UNAVAILABLE` (503), `UPSTREAM_TIMEOUT`
        (504). Some

        refusals add members of their own beside these (a call request's
        `status`, a workflow's

        `current_version`); the operation says which.
      properties:
        error:
          type: string
          description: The refusal, in one sentence for a person. Its wording may change.
        code:
          type: string
          description: The stable code to branch on.
        issues:
          type: array
          description: >
            Each thing at fault, on a 400 or 422 that names them: every query
            parameter or body field, not just the first. `path` is the
            parameter's name or the field's location.
          items:
            type: object
            required:
              - code
              - message
            properties:
              code:
                type: string
                description: >-
                  query_param_unknown, query_param_repeated, query_param_blank,
                  query_param_invalid, field_unknown, field_required,
                  field_invalid, or the route's own word.
              path:
                type: string
              message:
                type: string
    TeachError:
      allOf:
        - $ref: '#/components/schemas/Error'
        - type: object
          properties:
            reason:
              type: string
              description: A finer reason beside code
              when there is one.: null
            retry_after_ms:
              type: integer
    WorkflowTrainRun:
      type: object
      required:
        - id
        - call_id
        - agent_id
        - status
        - reasons
        - can_undo
        - can_retry
        - created_at
        - updated_at
      properties:
        id:
          type: string
          format: uuid
        call_id:
          type: string
          format: uuid
        agent_id:
          type: string
          format: uuid
        status:
          type: string
          enum:
            - claimed
            - waiting_transcript
            - running
            - put_done
            - applied
            - no_change
            - held
            - failed
            - reverted
          description: >
            `claimed`, `waiting_transcript`, `running` and `put_done` are in
            progress (poll again). `applied` - the new instructions are live.
            `no_change` - nothing to change (see reason). `held` - refused on
            purpose, nothing live changed (see reason). `failed` - something
            went wrong; retry may help. `reverted` - the change was undone.
        step:
          type:
            - string
            - 'null'
          enum:
            - gates
            - wait_transcript
            - llm
            - validate
            - entail
            - put
            - publish
            - rollback
            - undo
            - done
            - null
        attempt:
          type: integer
        reason:
          type:
            - string
            - 'null'
          description: >-
            The first reason a run ended without a change, or null. The full
            list is in reasons.
          enum:
            - no_instruction
            - roleplay_only
            - ambiguous
            - too_short
            - out_of_scope
            - call_too_short
            - call_not_completed
            - transcript_unreliable
            - transcript_empty
            - draft_has_unpublished_changes
            - stale_base
            - conflict
            - validation_failed
            - limits_exceeded
            - tool_reference_lost
            - token_mismatch
            - evidence_unverified
            - needs_confirmation
            - publish_refused
            - rollback_skipped_draft_changed
            - teach_disabled
            - transcript_timeout
            - model_unavailable
            - model_output_unreadable
            - model_truncated
            - publish_unavailable
            - abandoned
            - internal_error
            - null
        reasons:
          type: array
          items:
            type: object
            required:
              - code
            properties:
              code:
                type: string
              op_index:
                type: integer
              detail:
                type: string
        summary:
          type:
            - string
            - 'null'
          description: One sentence on what changed
          or null when none could be written (read changes).: null
        changes:
          type:
            - array
            - 'null'
          items:
            $ref: '#/components/schemas/WorkflowTrainChange'
        base_revision:
          type:
            - object
            - 'null'
          description: >-
            The version that was live before the run. Restore it to undo the
            run.
          properties:
            id:
              type: string
              format: uuid
            version:
              type: integer
        result_revision:
          type:
            - object
            - 'null'
          description: The version the run published. Null unless applied.
          properties:
            id:
              type: string
              format: uuid
            version:
              type: integer
        can_undo:
          type: boolean
          description: >-
            True while the run's version is still the live one and the draft has
            not moved.
        can_retry:
          type: boolean
          description: >-
            True for a held or failed run the caller may retry (the person who
            requested it
          with retries left).: null
        retry_after_ms:
          type:
            - integer
            - 'null'
          description: While the run is in progress
          when to ask again.: null
        created_at:
          type: string
          format: date-time
        updated_at:
          type: string
          format: date-time
        finished_at:
          type:
            - string
            - 'null'
          format: date-time
    WorkflowTrainChange:
      type: object
      required:
        - op_index
        - op
        - target
        - target_label
        - before
        - after
        - directive
        - evidence
      properties:
        op_index:
          type: integer
          minimum: 0
        op:
          type: string
          enum:
            - add
            - remove
            - replace
            - edit
            - move
        target:
          type: object
          description: >-
            Where the change is: {"kind":"global"} for the global instructions,
            or {"kind":"node","node_id":"..."} for one conversation step.
          required:
            - kind
          properties:
            kind:
              type: string
              enum:
                - global
                - node
            node_id:
              type: string
        target_label:
          type: string
          description: The step's label
          or "Global instructions".: null
        title:
          type:
            - string
            - 'null'
          description: The heading of the section changed
          when it has one.: null
        before:
          type:
            - string
            - 'null'
          description: The section as it read before. Null for an addition.
        after:
          type:
            - string
            - 'null'
          description: The section as it reads now. Null for a removal.
        directive:
          type: string
          description: What the person asked for
          in one sentence.: null
        evidence:
          type: array
          description: Words the person said on the call that this change rests on.
          items:
            type: object
            required:
              - turn
              - quote
            properties:
              turn:
                type: integer
                minimum: 0
              quote:
                type: string
        sensitive:
          type: array
          description: >-
            Present when the change touches a prohibition, a number, a link or
            phone number, or the text about a tool; such a change is applied
            only after a second check.
          items:
            type: string
            enum:
              - prohibition_removed
              - number_changed
              - url_or_phone_changed
              - tool_text_changed
  securitySchemes:
    apiKey:
      type: http
      scheme: bearer
      bearerFormat: API Key
      description: >-
        Your Yappr API key (e.g. `ypr_live_...`). Generate one in the dashboard
        under **Settings → API Keys**. No key is `401 MISSING_KEY`; a key that
        is not one of ours, or is revoked, is `401 INVALID_KEY`; an expired one
        is `401 EXPIRED_KEY`. A valid key without the scope an operation needs
        is `403 INSUFFICIENT_SCOPE` on every operation, and the message names
        the scope. Every response, a 401 included, carries X-RateLimit-Limit,
        X-RateLimit-Remaining and X-RateLimit-Reset: the budget is 60 requests a
        minute per API key. Every 429, whatever its code, carries Retry-After
        (whole seconds, never zero): the per-key budget's `RATE_LIMIT` asks for
        what is left of the minute, a route's daily cap (`RATE_LIMITED`) for the
        time until that cap resets. All four headers are listed in
        Access-Control-Expose-Headers, so a browser can read them. A path the
        API does not serve (an unknown sub-path, an id left empty) is `404
        ROUTE_NOT_FOUND`, and a method a served path does not take is `405
        METHOD_NOT_ALLOWED` with an `Allow` header; both are answered before any
        scope check, and nothing is read or changed. A trailing slash is ignored
        where it cannot be an id left empty (`POST /calls/` is `POST /calls`)
        and refused where it can (`GET /calls/`). A doubled slash inside a path
        is merged into one before the request reaches the API (`GET //calls` is
        `GET /calls`).

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.