# Agents API

Agents are the core identity primitive in STACK. Every AI agent that needs a passport, credentials, or access to drop-offs must first be registered. Each agent receives a unique ID prefixed with `agt_`. Stack-managed agents use the operator's authenticated connection. Customer-managed agents enroll an Ed25519 public key and authenticate with short-lived agent JWTs.

Send an operator-scoped bearer token for management calls. Enrollment endpoints use their documented enrollment ticket or signed challenge.

## Register Agent

### POST /v1/agents/register

Register a new agent under your operator account. The agent name must be lowercase, using letters, digits, hyphens, or underscores, matching the pattern `/^[a-z0-9_][a-z0-9_\-]*[a-z0-9_]$/` and at most 64 characters. Examples: `my-agent`, `my_agent`, `research-pipeline`. The response returns the full agent object. Registering an agent needs no approval: the owner's own session or API key does it directly, and the new agent has no access to any connected service until a grant is made, which a person approves. This holds whatever settings it starts with.

### Request Body

```json
{
  "name": "invoice-processor",
  "description": "Processes incoming invoices and extracts line items",
  "accountability_mode": "enforced",
  "on_warning": "notify",
  "on_critical": "block",
  "credential_access": "proxy_only",
  "icon_url": "https://example.com/icon.png"
}
```

- name (string, required) - Lowercase. Letters, digits, hyphens, or underscores. Must match /^[a-z0-9_][a-z0-9_\-]*[a-z0-9_]$/. Max 64 characters.
- description (string, optional) - Human-readable description. Max 256 characters.
- accountability_mode (string, optional) - One of "enforced", "logged", or "standard". Default: "logged": every call is recorded and none waits for a person. "enforced" holds each call for approval and is the owner's choice. Agents that already exist keep the mode they have.
- on_warning (string, optional) - Escalation action when a warning flag is raised: "notify" or "block".
- on_critical (string, optional) - Escalation action when a critical flag is raised: "notify" or "block".
- credential_access (string, optional) - How the agent accesses credentials: "direct", "proxy_preferred", or "proxy_only". Default: "proxy_only" - the agent never receives a raw secret.
- profile (string, optional) - Registration preset. Explicit fields override preset values.
- skill_access_mode (string, optional) - Skill access policy. Default: "none".
- allowed_skills (string[], optional) - Skills permitted by the selected skill access policy.
- key_mode (string, optional) - "stack_managed", "customer_managed", or "co_signed". Default: "stack_managed".
- twin_policy (string, optional) - Digital-twin execution policy.
- twin_llm_model (string or null, optional) - LLM override for twin execution.
- icon_url (string, optional) - URL or data URI for the agent icon. Max 100,000 characters. Can be null.
- llm_inject_system_prompt (boolean, optional) - Accepted and ignored: it has no effect. STACK adds no system prompt to gateway calls.
- llm_redact_pii (boolean, optional) - Scan user-role messages on Anthropic and OpenAI gateway calls and replace detected PII with [REDACTED:\<category>] before forwarding. Default: true. When false, user-supplied PII reaches the LLM provider unredacted.
- eval_traffic (boolean, optional) - Mark the agent as test or benchmark traffic from the start. Default: false. Registering with it true mutes the alerts of the owner for the agent, so it needs approval from a person when made from an API key or chat session; false or absent asks nothing. See eval_traffic under Update Agent.

### Request Example

```bash
curl -X POST https://api.getstack.run/v1/agents/register \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer <access token>" \
  -d '{
    "name": "invoice-processor",
    "description": "Processes incoming invoices and extracts line items",
    "accountability_mode": "enforced",
    "on_critical": "block"
  }'
```

### Response - 201 Created

```json
{
  "id": "agt_7kx9m2nq4p",
  "operator_id": "op_abc123",
  "name": "invoice-processor",
  "description": "Processes incoming invoices and extracts line items",
  "status": "active",
  "accountability_mode": "enforced",
  "on_warning": "notify",
  "on_critical": "block",
  "credential_access": "proxy_only",
  "passport_blocked": false,
  "passport_blocked_reason": null,
  "passport_blocked_at": null,
  "icon_url": null,
  "llm_inject_system_prompt": true,
  "llm_redact_pii": true,
  "created_at": "2026-04-15T10:30:00.000Z",
  "updated_at": "2026-04-15T10:30:00.000Z"
}
```

### Error Responses

- 400 Bad Request - Invalid name format, description too long, or invalid field values.
- 401 Unauthorized - Missing or invalid Authorization header.
- 409 Conflict - An agent with this name already exists under your account.
- 429 Too Many Requests - This bearer bucket exceeded 60 registrations per minute on one API machine.

## Accountability Modes

Every agent has an accountability mode that controls how passport activity is monitored and reviewed. This is one of the most important configuration choices for production agents.

### logged (default)

Where a new agent starts. Checkpoints and checkouts are recorded and no call waits for a person. Checkout keeps critical flags. The configured critical escalation action can still block the agent. Start here and tighten to enforced when you want per-call approval.

### enforced

The strictest mode, and the owner's choice. Agents must submit checkpoints at regular intervals during passport use and perform a checkout when done, and each call needs an approved intent. If checkpoints are missed or the checkout report raises flags, the agent can be automatically blocked from receiving new passports until an operator reviews and approves the activity. Lowering an existing agent's mode is a deliberate loosening and needs a person's approval from an API key or chat session.

### standard

Does not accept checkpoints or checkouts. Use it only when your application does not need STACK accountability reports.

## Credential Access Modes

The `credential_access` field controls how the agent interacts with stored service credentials:

- proxy_only (default) - STACK refuses raw credential retrieval for this agent. Calls made through the STACK proxy receive the host, scope and constraint checks that apply to that Passport, plus an approval check when the agent uses enforced mode.
- proxy_preferred - Also refuses raw credential retrieval. Use it when the runtime normally calls through the proxy but the label needs to distinguish that operating preference from a hard deployment policy.
- direct - The agent can retrieve raw credentials via the credentials API and call the provider itself. Those calls leave STACK entirely, so nothing on the proxy path applies to them. Choose this only when you trust the agent runtime and accept that its outbound calls are unmediated.

This setting controls access to credentials stored in STACK. It does not sandbox the agent process or stop it reaching the internet with credentials obtained elsewhere.

## LLM Gateway Controls

One per-agent boolean controls what STACK does to the agent's `/v1/llm/*` gateway calls before forwarding them to the provider. It defaults to `true`. STACK adds no system prompt to a call; the older `llm_inject_system_prompt` field is still accepted and has no effect.

- llm_redact_pii - STACK scans user-role messages and replaces detected PII (email, phone, SSN, credit card, IBAN, IP address) with [REDACTED:\<category>] before the call leaves STACK. A no-op when a message contains no PII.

Disabling `llm_redact_pii` means user-supplied PII flows to the LLM provider unredacted. The audit log records `pii_hits: -1` on those calls so "redaction skipped" is distinguishable from "scanned, zero hits".

## List Agents

### GET /v1/agents

Retrieve all agents registered under your operator account.

### Request Example

```bash
curl https://api.getstack.run/v1/agents \
  -H "Authorization: Bearer <access token>"
```

### Response - 200 OK

```json
[
  {
    "id": "agt_7kx9m2nq4p",
    "operator_id": "op_abc123",
    "name": "invoice-processor",
    "description": "Processes incoming invoices and extracts line items",
    "status": "active",
    "accountability_mode": "enforced",
    "on_warning": "notify",
    "on_critical": "block",
    "credential_access": "proxy_only",
    "passport_blocked": false,
    "passport_blocked_reason": null,
    "passport_blocked_at": null,
    "icon_url": null,
    "llm_inject_system_prompt": true,
    "llm_redact_pii": true,
    "created_at": "2026-04-15T10:30:00.000Z",
    "updated_at": "2026-04-15T10:30:00.000Z"
  }
]
```

## Get Agent

### GET /v1/agents/:id

Retrieve a single agent by its ID. Returns the full agent object.

### Request Example

```bash
curl https://api.getstack.run/v1/agents/agt_7kx9m2nq4p \
  -H "Authorization: Bearer <access token>"
```

### Error Responses

- 401 Unauthorized - Missing or invalid Authorization header.
- 404 Not Found - Agent does not exist or belongs to a different operator.

## Update Agent

### PATCH /v1/agents/:id

Update an agent's configuration, rename it or change its description. You cannot change its key mode. At least one field must be provided.

### Request Body

```json
{
  "name": "support-bot-v2",
  "description": "Answers support email",
  "status": "suspended",
  "accountability_mode": "logged",
  "on_warning": "notify",
  "on_critical": "block",
  "credential_access": "proxy_only",
  "icon_url": "https://example.com/new-icon.png"
}
```

- name (string, optional) - A new name: lowercase letters, digits, hyphens or underscores, up to 64 characters. It must be free among your agents that are not retired, otherwise the answer is 409. Renaming changes no authority (grants, Missions and Passports stay as they are), needs no approval, and is for the owner or an admin member.
- description (string | null, optional) - A new description of up to 256 characters, or null to clear it. Same rules as name.
- status (string, optional) - Must be "active" or "suspended". Cannot set to "revoked" via update.
- accountability_mode (string, optional) - "enforced", "logged", or "standard".
- on_warning (string, optional) - "notify" or "block".
- on_critical (string, optional) - "notify" or "block".
- credential_access (string, optional) - "direct", "proxy_preferred", or "proxy_only".
- icon_url (string | null, optional) - New icon URL or null to clear.
- skill_access_mode (string, optional) - Skill access policy.
- allowed_skills (string[], optional) - Skills allowed by that policy.
- identity_claim_ids (string[], optional) - Identity claims assigned to the agent.
- twin_policy (string, optional) - Digital-twin execution policy.
- twin_llm_model (string or null, optional) - Twin LLM override, or null to clear it.
- is_synthetic (boolean, optional) - Mark test traffic for default event filtering.
- llm_inject_system_prompt (boolean, optional) - Accepted and ignored: it has no effect. See LLM Gateway Controls above.
- llm_redact_pii (boolean, optional) - Toggle PII redaction on Anthropic and OpenAI gateway calls. Setting false sends user-supplied PII to the provider unredacted.
- eval_traffic (boolean, optional) - Mark this agent as eval/benchmark traffic. Detection stays fully on and events stay visible, but warning-and-below events insert pre-resolved with no notification, the L3 LLM classifier is skipped, and the daily digest excludes the noise. Criticals stay fully live, including auto-block. Operator-set only: not settable from agent contexts or partner grants. See /docs/api/security-events.

### Request Example

```bash
curl -X PATCH https://api.getstack.run/v1/agents/agt_7kx9m2nq4p \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer <access token>" \
  -d '{
    "accountability_mode": "logged",
    "credential_access": "proxy_only"
  }'
```

### Error Responses

- 400 Bad Request - No fields provided (the answer lists the fields that can be changed), or an invalid value.
- 409 Conflict - The new name is already used by one of your agents that is not retired.
- 401 Unauthorized - Missing or invalid Authorization header.
- 404 Not Found - Agent does not exist or belongs to a different operator.

## Set Up an Agent

### POST /v1/agents/setup

Registers an agent, gives it its first grants on connections the account already holds, and declares the hosts those connections' credentials may be sent to, as one approval. The approval card lists every part and binds the whole request, so what runs is exactly what the person saw. A request that cannot succeed (a name in use, a scope the connection does not hold, a malformed host) is refused before anyone is asked. From an API key or OAuth session the first call answers 403 GOVERNANCE_APPROVAL_REQUIRED with an approval link; the approval is decided in the browser, and the same call is repeated with the X-Governance-Approval header. A person in their own signed-in session needs no approval.

```json
{
  "agent": { "name": "grocery-bot", "eval_traffic": true },
  "grants": [
    {
      "service_connection_id": "scon_a1b2c3",
      "scopes": ["read", "write"],
      "constraints": [{ "path": "url.pathname", "op": "starts_with", "value": "/v1/products" }]
    }
  ],
  "allowed_hosts": [
    { "service_connection_id": "scon_a1b2c3", "allowed_hosts": ["api.grocer.example"] }
  ]
}
```

- agent (object, required) - The same body as Register Agent.
- grants (array, optional) - One entry per connection: service_connection_id, scopes, and optionally constraints, intents and allow_data_from, as in POST /v1/services/grant.
- allowed_hosts (array, optional) - One entry per connection: service_connection_id and allowed_hosts. At least one grant or one host list is required; to register an agent alone, register it.

Returns 201 with the agent, the grants made and the host lists set. If a step fails after the agent was registered, the agent is retired and its grants ended before the error is returned.

## Dismiss an Agent's Warnings

### POST /v1/agents/:agentId/dismiss-warnings

Resolves every open warning and info event of one agent in one step. New events of the same signal types for that agent are not recorded for the next 24 hours, so what was cleared does not come back. Critical events are never dismissed or hidden by this call. It is the owner's decision: an agent context is refused, and one audit row records who, how many and which signal types. The Console offers it as "Dismiss all for this agent". The response is agent_id, dismissed, by_signal_type and repeats_hidden_for_seconds.

## Unblock Agent

### POST /v1/agents/:id/unblock

Clear an agent block after the incident has been reviewed. When STACK blocks an agent, it also revokes that agent's active Passports and every active Passport delegated from them in the same database transaction. This endpoint permits future issuance; it does not restore any revoked Passport.

### Request Example

```bash
curl -X POST https://api.getstack.run/v1/agents/agt_7kx9m2nq4p/unblock \
  -H "Authorization: Bearer <access token>"
```

Unblocking is a governance action. Agent and Passport contexts are refused. A direct API key or user OAuth call returns`403 GOVERNANCE_APPROVAL_REQUIRED` with an approval id. A human approves at the returned approval URL, `https://getstack.run/app/approve/gvr_...`, then the same call is retried with the`X-Governance-Approval` header. Dashboard sessions unblock directly. Full protocol: /docs/api/security-events.

Unblocking neither restores revoked Passports nor approves a flagged checkout. New access requires a newly issued Passport, and checkout reviews remain in the review queue.

## Delete Agent

### DELETE /v1/agents/:id

Permanently delete an agent and mark its active Passports as revoked. The next STACK-verified call rejects those Passports. This action cannot be undone.

### Request Example

```bash
curl -X DELETE https://api.getstack.run/v1/agents/agt_7kx9m2nq4p \
  -H "Authorization: Bearer <access token>"
```

Deleting an agent is irreversible. Pending drop-offs assigned to it become uncollectable, and offline signature-only verifiers may still accept its existing Passports until their signed expiry.

## Tier Limits

There is no cap on agents, on any tier, and registering one is not a metered action. A cap here would mean a customer at their limit runs the next twenty agents outside STACK, and an unregistered agent is an unaudited agent.

Registration allows 60 requests per minute per bearer bucket, per API machine. It does not use the monthly action allowance.
