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

# Agents as Code YAML & CI Reference

> Complete YAML schema, triggers, action approvals, skills as code, validation API, and GitHub Action reference for Response Agents as Code.

This reference covers the YAML schema, skills directory layout, validation API, and GitHub Actions workflow for [Response Agents as Code](https://docs.cotool.ai/agents/response-agents-as-code.md).

## File Format

Each file defines one response agent. The format is intentionally distinct from the UI's bulk export/import format — here it's **one agent per file**, with the system prompt either inline or in a separate `.md` file.

```yaml theme={null}
apiVersion: cotool.ai/v1
kind: ResponseAgent
metadata:
    sync_key: triage-suspicious-login
    name: Triage Suspicious Login
    description: First-pass triage for IdP suspicious-login alerts.
    tags:
        - auth
        - p1
spec:
    modelAlias: auto:chat:default
    planningMode: auto
    toolNames:
        - cotool_runQuery
    acceptanceCriteria:
        - Cites evidence supporting the verdict or explains why it is inconclusive.
    systemPrompt:
        inline: |
            # Triage Suspicious Login

            For a suspicious sign-in alert, review identity log events around
            the supplied timestamp and user. Report the evidence, missing data,
            and a verdict of expected, suspicious, or inconclusive.
```

### Top-level fields

| Field | Required | Notes |
| - | - | - |
| `apiVersion` | optional | Schema version, e.g. `cotool.ai/v1`. |
| `kind` | optional | Must be `ResponseAgent` when present. |
| `metadata` | required | Identity and human-readable info (see below). |
| `spec` | required | The agent definition (see below). |

### `metadata`

| Field | Required | Notes |
| - | - | - |
| `sync_key` | optional | Stable, org-unique identity for the agent (see [Identity](#identity)). |
| `name` | required | Human-readable name. Can change freely — it is not the identity. |
| `description` | optional | What the agent does. |
| `tags` | optional | Free-text tags for categorizing the agent. |

### `spec`

| Field | Required | Notes |
| - | - | - |
| `modelAlias` | required | Model alias, e.g. `anthropic:chat:sonnet-5.5`. For Auto, use `auto:chat:default` (not `auto`). |
| `systemPrompt` | required | Either `{ inline: "..." }` or `{ file: "prompt.md" }` (path relative to the YAML file). |
| `planningMode` | optional | `auto` (default), `never`, or `always`. See [Planning Modes](https://docs.cotool.ai/agents/planning-modes.md). |
| `agentFilesystem` | optional | Mount a persistent [Agent Filesystem](https://docs.cotool.ai/agents/agent-filesystem.md) across runs (default `false`). |
| `toolNames` | optional | Non-agent tool ids the agent may use. Prefer full action names such as `slack_sendMessage` — these are what the agent page's tool picker shows. A bare integration id (for example, `slack`) is also accepted and grants every matching `slack_*` action, but the UI cannot display it as a selection. |
| `agentTools` | optional | Other managed agents this agent may call, by `sync_key` (see [Agent-to-agent](#agent-to-agent-references)). |
| `cliNames` | optional | CLI integration ids the agent may use. |
| `skills` | optional | Attached [skills](https://docs.cotool.ai/agents/skills.md), each a **name** referencing a skill that exists in your org (created in the UI or defined as a `SKILL.md` synced from the repo). See [Skills](#skills). |
| `acceptanceCriteria` | optional | [Acceptance criteria](https://docs.cotool.ai/improving-agents/acceptance-criteria.md) checked during evaluation. |
| `triggers` | optional | Inline triggers (see [Triggers](#triggers)). |
| `structuredOutputSchema` | optional | JSON schema for [structured output](https://docs.cotool.ai/agents/structured-outputs.md). |
| `contextDocs` | optional | [Context documents](https://docs.cotool.ai/agents/context-documents.md) attached to the agent. |
| `reasoningEffort` | optional | Model-supported reasoning effort; omit to use the model default. Applies with token-based pricing. |
| `fastMode` | optional | Use faster generation on supported models on token-based plans. |
| `toolSelectionMode` | optional | `manual` (default); `all_read_only` resolves read-only tools at runtime; `all_read_only_plus_selected` also includes explicitly selected actions, agents, and CLIs. |
| `toolActionConfigs` | optional | Per-action configuration. |
| `slackReplyScope` | optional | `anyone` or `cotool_users` (default); applies to runs not started by a Slack trigger. |
| `slackDisplayName` | optional | Display name for messages the agent posts in Slack. |
| `slackIcon` | optional | Emoji shortcode or HTTPS image URL for the agent's Slack messages. |

> [!NOTE]
>
> The YAML is **strict** — unknown or misspelled keys (for example `syncKey`
> instead of `sync_key`) are rejected with a validation error for that file
> rather than being silently ignored.

## Identity

Each file maps to exactly one agent. Cotool decides which agent a file represents by:

1. **`metadata.sync_key`** — an author-chosen identity, unique within your organization. **Recommended.** Because identity is independent of file content and location, you can rename the agent or move/rename the file without churning the agent or losing its triggers and history.
2. **File path** — used when no `sync_key` is set. Renaming or moving the file then changes its identity (Cotool treats it as a new agent).

If several files declare the same `sync_key`, the file a managed agent already syncs from keeps syncing and only the copies are rejected. When no agent owns the `sync_key` yet, every file declaring it is rejected.

> [!NOTE]
>
> Set a `sync_key` for any agent you expect to rename or reorganize. It's the
> only way to keep a webhook trigger's minted secret and URL stable across a
> rename.

## Triggers

Declare triggers inline under `spec.triggers`. The sync engine materializes them as engine-owned, read-only triggers on the agent. Supported sources: `cron`, `webhook`, `jira`, `jira-automation`, `slack`, `linear`, and `email`. A trigger from any other source, such as Bugcrowd or HackerOne, can't be declared in YAML, so the sync leaves it on the agent instead of deleting it.

```yaml theme={null}
spec:
    triggers:
        - source: cron
          name: Daily report
          schedule: '0 9 * * *'
        - source: webhook
          name: Inbound events
          sync_key: inbound # stable id; preserves the minted secret across renames
        - source: jira
          name: New security issues
          events:
              - jira:issue_created
          jqlFilter: project = SEC
        - source: slack
          name: Security channel
          allowedChannelIds:
              - C0123456789
```

> [!WARNING]
>
> **Secrets never live in YAML.** Webhook secrets and inbound URLs are minted
> server-side; Slack and Linear bind to your organization's connected
> integration at sync time. If the required integration isn't connected, that
> trigger is **skipped with a diagnostic** — the agent itself still syncs, and
> the file's status shows *integration not connected* rather than failing.

A trigger's `sync_key` is its stable identity **within the agent** (it defaults to a slug of `name`). Set it explicitly to rename a trigger without recreating its row — which, for webhook-family triggers, is what preserves the minted secret and URL.

Use `eventMode: direct` to run without creating a Cotool alert, or `eventMode: alert_source` to create an alert first. If omitted, Cotool uses the source default. Slack triggers also accept `reactionEmojis` (names without colons), `allowedUserIds`, `allowedUsergroupIds`, and `replyScope`. For source setup, see [Trigger an agent](https://docs.cotool.ai/agents/triggering-agents.md).

## Action approvals

Use `toolActionConfigs` to [require approval](https://docs.cotool.ai/agents/response-approvals.md) for a selected tool action. For example, to let the agent create an issue only after a person reviews the call in Cotool:

```yaml theme={null}
spec:
    toolNames:
        - jira_createIssue
    toolActionConfigs:
        - type: tool_approvals
          rules:
              - toolName: jira_createIssue
```

Merge the settings into your existing `spec` rather than replacing the rest of the definition. The action still needs a connected integration and usable provider permissions. After syncing, [run a safe test](https://docs.cotool.ai/agents/running-agents.md) and review the approval and tool result before routing live alerts to the agent.

## Agent-to-Agent References

A YAML agent can call another managed agent as a tool by referencing its `sync_key`:

```yaml theme={null}
spec:
    toolNames:
        - slack_sendMessage
        - slack_replyToThread
    agentTools:
        - sync_key: enrich-alert
        - sync_key: notify-oncall
```

References are resolved in a second pass after all agents exist, so **forward references work** — the order of files doesn't matter. Always reference other agents via `agentTools` and `sync_key`, not via `toolNames`.

## Skills

An agent **references** skills by name. It never defines a skill inline — skills are first-class resources whose lifecycle is independent of any one agent:

```yaml theme={null}
spec:
    toolNames:
        - crowdstrike_listDetections
        - crowdstrike_getDeviceDetails
        - slack_sendMessage
    skills:
        - enrich-user # exists in your org (created in the UI)
        - triage-runbook # defined as code in a SKILL.md synced from this repo
```

A referenced skill resolves to a skill that exists in your organization — either one created in the **UI**, or one defined as code in a **`SKILL.md`** synced from your repo (below). A reference that doesn't resolve is **skipped** with a note (it does **not** fail the agent), so the agent still loads with the skills that resolve and the rest of its spec. References track each skill's latest version.

### Defining skills as code

Skills live in their own directory in the repo — the **skills path** (`skills_path`, default `cotool/skills`), configured separately from the agents path. Each skill is a directory containing a standard [`SKILL.md`](https://docs.cotool.ai/agents/skills) — YAML frontmatter (`name`, `description`, `allowed-tools`) plus a Markdown body — with any sibling `references/`, `assets/`, and `scripts/` files synced too:

```text theme={null}
cotool/
  agents/
    triage.yaml          # references skills by name
  skills/
    phishing/
      SKILL.md
      references/playbook.md
      assets/report-template.md
    triage-runbook/
      SKILL.md
```

Cotool discovers each `SKILL.md` **on its own** — a skill exists because its file exists, not because an agent points at it. The skill's `name` (from frontmatter) is its identity, so:

* The skill is **engine-managed**: Cotool creates it and records a new version only when its content actually changes (a no-op re-sync adds none). Like a managed agent, it's **read-only in the UI** — edit or remove it by changing its `SKILL.md`, not from the Skills page.
* Any number of agents can reference it by name — and so can an agent **managed in the UI**. The skill is a single org-wide resource; referencing it never copies it.
* If the `SKILL.md` is **removed**, the skill is **gently soft-deleted** (and resurrected if the file returns), just like agents. Because lifecycle tracks the *file*, retiring an agent that referenced the skill never deletes it — other agents keep working.
* Two `SKILL.md` files with the **same name** are a conflict: both are flagged and neither is synced (names must be unique across the repo).
* If the name collides with an existing **non-managed organization skill** created in the UI, the `SKILL.md` skill is **not** synced — Cotool never overwrites it. The collision is flagged on the skill file's sync status. Personal skills use a separate per-user namespace and can share the managed skill's name.

> [!WARNING]
>
> A skill's required tools (its `SKILL.md` `allowed-tools`) must also be
> granted to every agent that attaches it, via `toolNames` (or `cliNames`). A
> requirement named by integration id (for example `crowdstrike`) is satisfied
> by granting any action from that integration, such as
> `crowdstrike_listDetections`. In the example above an agent attaching
> `triage-runbook` therefore needs an action from each of that skill's
> integrations in its `toolNames`. If a required tool is missing, that one
> agent file syncs with a `schema_error` and is skipped — the rest of your
> agents still reconcile.

> [!NOTE]
>
> Skills round-trip through export cleanly, since agents carry only name
> references.

## Validate Before Syncing

`POST /api/agent-sync/validate` runs the **exact same** parse, schema, and cross-file graph validation as the sync engine, statelessly, over files you post — so it cannot drift from real sync behavior. It's the engine behind the CI Action below, and you can call it directly:

```bash theme={null}
curl -X POST https://app.cotool.ai/api/agent-sync/validate \
  -H "Authorization: Bearer $COTOOL_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "files": [
      { "path": "cotool/agents/triage.yaml", "content": "apiVersion: cotool.ai/v1\nkind: ResponseAgent\nmetadata:\n  name: Triage Suspicious Login\nspec:\n  modelAlias: auto:chat:default\n  systemPrompt:\n    inline: Review the supplied sign-in evidence and report any gaps.\n" }
    ]
  }'
```

The response carries a result per file — both agent YAML and any posted `SKILL.md` — with `errors` (would block sync) and `warnings`, plus an overall `valid` flag. Warnings are checks that depend on live org state the request can't see: an unprovided `systemPrompt.file`, an `agentTools` sync\_key not in the posted set, or a skill reference whose `SKILL.md` wasn't posted (it may be a UI-created org skill). Post your `SKILL.md` files (and set `skillsPath` if it isn't the default `cotool/skills`) to validate skill references and skill definitions too — with a skill's `SKILL.md` posted, validation also **errors** on any agent that attaches it without granting the skill's `allowed-tools`, exactly as sync would. See the [API Reference](https://docs.cotool.ai/api-reference/agents-as-code/validate-response-agent-as-code-yaml.md) for the full schema.

> [!WARNING]
>
> **Prefer GitHub OIDC over an API key.** The `$COTOOL_API_KEY` above is shown
> for direct or manual calls and for CI outside GitHub. For GitHub Actions,
> use the [OIDC-based Action](#validate-in-ci) below instead — it mints a
> short-lived, repo-scoped token, stores no secret, and authorizes as a
> **validate-only** principal.
>
> A Cotool API key, by contrast, is **long-lived** and carries the **full
> permissions of the user who created it** — it is *not* narrowed to
> validation, even though the endpoint only needs `tool.manage` — so a leaked
> key is as powerful as that user. If you must use one (non-GitHub or
> self-hosted CI), create it under a dedicated, least-privilege service
> account, keep it in a secrets manager, and rotate it regularly.

## Validate in CI

The [`cotool/validate-agents`](https://github.com/cotool/validate-agents) GitHub Action validates your agent YAML on every pull request and annotates problems inline.

The Action authenticates **only** via GitHub OIDC — there is no API-key input, and it is the **recommended** way to validate in CI. The job mints a short-lived, repo-scoped OIDC token; Cotool verifies it and maps the repository to your org via your GitOps sync configuration. Nothing to store or rotate, and the token grants validate-only access — never your broader API-key permissions.

```yaml theme={null}
# .github/workflows/validate-agents.yml
on:
    pull_request:
        paths: ['cotool/agents/**']
permissions:
    contents: read
    id-token: write # lets the job mint the OIDC token
jobs:
    validate:
        runs-on: ubuntu-latest
        steps:
            - uses: actions/checkout@v5
            - uses: cotool/validate-agents@v1
              with:
                  dir: cotool/agents
```

> [!NOTE]
>
> OIDC requires that this repository is configured as your org's agents source
> in the GitHub integration's **Response Agents as Code** card. That
> registration authorizes the repository. To validate before configuring sync,
> or outside GitHub CI, call the endpoint directly with an API key (the `curl`
> example above) rather than the Action — subject to the API-key trade-offs
> noted above.

### Inputs

| Input | Default | Description |
| - | - | - |
| `dir` | `cotool/agents` | Directory to scan for agent YAML (and referenced prompt `.md`). |
| `file` | — | Comma-separated explicit file list; overrides directory discovery. |
| `recursive` | `true` | Recurse into subdirectories of `dir`. |
| `audience` | `cotool-validate` | OIDC audience requested from GitHub and verified by the Cotool API. |
| `api_url` | `https://app.cotool.ai` | Base URL of the Cotool API. |
| `fail_on_warnings` | `false` | Fail the check on warnings (errors always fail). |

### How validation gates a merge — and how syncing stays safe

The Action (and the `/validate` endpoint behind it) is **advisory by default**: it reports problems on the pull request, but on its own it does not stop anything from syncing. Cotool's sync engine polls whatever is on your **configured branch** and reconciles it — it does not know or care whether a CI check ran or passed. Two separate mechanisms turn that into a safe GitOps workflow:

1. **Branch protection makes validation a merge gate (recommended).** In your repository settings, mark the validation check as a **required status check** on the branch you sync from. GitHub then blocks any pull request from merging until validation passes, so only validated YAML ever reaches the branch Cotool polls. This is the piece that actually *gates* syncing, and it lives in **your** GitHub settings — not in Cotool.
2. **The sync engine re-validates changes as a backstop.** Independently of CI, Cotool checks syntax, schema, and cross-file references before applying a changed definition. An invalid file is **skipped per-file** — its last good version is kept and the error is recorded against that file (see [Reconcile Behavior](https://docs.cotool.ai/agents/response-agents-as-code.md#reconcile-behavior)).

**1. Open a pull request**

An author edits agent YAML under your synced path and opens a PR. The
`validate-agents` Action runs against the PR's files and annotates any
errors or warnings inline.

**2. The required check gates the merge**

With branch protection enabled on your sync branch, the PR cannot merge
until the validation check is green. Reviewers only ever merge validated
YAML; broken YAML is blocked at the door.

**3. Merge to the sync branch**

Once approved and green, the PR merges into the branch you configured in
the GitHub integration's **Response Agents as Code** card (commonly your
default branch).

**4. Cotool polls and reconciles**

Within \~5 minutes the sync engine fetches the branch HEAD, re-validates,
and applies the changes — recording each as a version. Anything still
invalid is skipped per-file, never blocking the rest.

> [!NOTE]
>
> Cotool never reads your CI status — **branch protection** is what ensures
> only validated YAML lands on the sync branch. If you sync from an
> unprotected branch (or commit directly to it), the Action becomes a
> non-blocking signal and the **server-side backstop** is your only guard
> against invalid files.


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