# AgentSession and AgentSessionConfig

> For the complete documentation index, see [llms.txt](https://docs-stg.ringleader.dev/llms.txt).


> An AgentSession is one run of a coding agent on a workstation, and an AgentSessionConfig is a reusable layer of settings that Ringleader folds into sessions.


An **AgentSession** is one run of a coding agent on a workstation: which agent, which prompt, which limits. An
**AgentSessionConfig** is a reusable layer of settings that Ringleader folds into the sessions it matches. Both kinds
are namespaced, in `workstations.ringleader.dev/v1`. This page lists the fields of both.
[Agent sessions](https://docs-stg.ringleader.dev/workstations/sessions/agent-sessions/) explains how a session works and how to use one.
[Agent session commands](https://docs-stg.ringleader.dev/reference/cli/commands/agent-sessions/) lists the commands.

Agent sessions are hidden until the `agent-sessions.visible` setting is on for you, as
[Agent session visibility](https://docs-stg.ringleader.dev/workstations/sessions/agent-sessions/#agent-session-visibility) says.
The kinds and their commands work either way.

## AgentSession

The smallest session names a workstation and a prompt:

```yaml
apiVersion: workstations.ringleader.dev/v1
kind: AgentSession
metadata:
  name: fix-login
  namespace: local
spec:
  workstationRef:
    name: my-agent-box
  prompt:
    inline: Fix the failing login test.
```

A session with an agent, limits and a transcript store looks like this:

```yaml
apiVersion: workstations.ringleader.dev/v1
kind: AgentSession
metadata:
  name: fix-login
  namespace: local
spec:
  workstationRef:
    name: my-agent-box
  prompt:
    inline: Fix the failing login test.
  agent: claude
  lifecycle:
    maxCost: 5
    idleTimeout: 2h
    transcriptStore: daemon
```

You own every session you create. Nobody else can author one in your name. The schema is closed, so an unknown key is
refused. A name is a lowercase DNS subdomain name of up to 253 characters.

### Placement and prompt

Give exactly one of `workstationRef` and `workstationPoolRef`.

| Field | Type | Description |
|-------|------|-------------|
| `workstationRef.name` | `string` | The workstation that runs the agent. `workstationRef.uid` is optional, and Ringleader fills it in. |
| `workstationPoolRef.name` | `string` | A [WorkstationPool](https://docs-stg.ringleader.dev/reference/resources/workstationpool/) that lends the session a workstation. |
| `prompt.inline` | `string` | The prompt. It cannot change once the session exists. A running agent is never re-prompted. |

### What to run

| Field | Type | Description |
|-------|------|-------------|
| `agent` | `string` | `claude`, `codex`, `agy`, `pi` or `opencode`. Any other value is refused. |
| `model` | `string` | The model, as the agent's own catalog spells it. |
| `modelProvider` | `string` | The provider that serves the model. It must be a known provider name. `pi` and `opencode` need it with `model`. |
| `modelParams.effort` | `string` | One word of up to 64 bytes, with no spaces and no leading `-`. The values `low`, `medium`, `high`, `xhigh`, `max` and `ultra` are known. Another value reaches the agent with a warning. |
| `modelParams.extraArgs.<agent>` | `[]string` | Extra arguments for that agent, each one argument. A plain string is refused. |
| `workdir` | `string` | Where the agent runs. A relative path resolves against the login user's home. Without one, the session uses a configuration layer's `workdir`, else the workstation's first source checkout, else the home directory. |
| `env` | `map` | Environment variables for the agent. Layers merge them key by key. |
| `worktreeSetRef` | `object` | A [WorktreeSet](https://docs-stg.ringleader.dev/reference/resources/worktreeset/) on the workstation for the agent to work in. |
| `announceSpeaker` | `bool` | Tells the agent who sent each turn in a shared session. |
| `configs` | `[]object` | AgentSessionConfig layers to fold in, each `{name, priority}`. `name` is required. |

### Permissions and identity

| Field | Type | Description |
|-------|------|-------------|
| `permissions.mode` | `string` | `ask`, `acceptEdits` or `unattended`. Unset leaves the agent's own default. |
| `permissions.allow` | `[]string` | Tool patterns, such as `Bash(go test:*)`. Ringleader enforces the list, and a blank entry is refused. A list on the session replaces a layer's list. |
| `identity.secrets` | `[]string` | Names of Secrets that become the session's identity. |

### Lifecycle

Every `lifecycle` field is optional. A duration takes the Go form (`90m`, `2h`) or whole days (`7d`), and
must be positive.

| Field | Type | Description |
|-------|------|-------------|
| `idleTimeout` | `string` | Stops the session after this long with no activity. No default: a session that waits rests indefinitely. |
| `maxDuration` | `string` | Stops the session after this much agent run time. Time spent waiting for a workstation or stopped does not count. |
| `maxCost` | `number` | Stops the session once it has spent this many US dollars. It must be above 0. A provider that reports no cost never trips it. |
| `startDeadline` | `string` | A timestamp by which the agent must have started. |
| `endOnFirstIdle` | `bool` | Ends the session at the agent's first turn boundary: `Done`, or `Failed` if that turn failed. Default `false`. |
| `endWhen.done`, `endWhen.failed` | `string` | A pattern for a line the agent writes when it has finished or failed. It matches a whole line, holds up to 256 bytes and must not match an empty line. |
| `maxAutoResumes` | `int` | How many times `autoResumePrompt` may resume the session. Default `5`, and `0` never resumes. |
| `autoResumeProgress` | `string` | How long a resumed session must run to count as productive, which restarts the count. Default `1m`. |
| `continueInterruptedTurn`, `interruptedTurnText` | | Continue a turn that a restart or crash interrupted, and what to say. Off by default. |
| `transcriptStore` | `string` | `box`, `daemon` or `plane`. Without it, Ringleader chooses one when it creates the session and records the choice and the reason in `status.transcript`. |
| `transcriptStorageRef` | `string` | The name of a [Storage](https://docs-stg.ringleader.dev/reference/resources/storage/) in the namespace that a `plane` transcript is sealed into. Refused unless the store is `plane`. Default: the namespace's default Storage. |
| `transcriptRetention` | `string` | How long sealed transcript segments stay in the Storage. Default 90 days. |
| `transcriptHotWindow` | `string` | The time a recent transcript stays in a cache in front of sealed storage. `plane` only. Default `30m`. |
| `transcriptFreeze` | `string` | How long a session may rest before its transcript stops changing. Default: never. |
| `rawTranscript` | `string` | `off`, `box`, `daemon` or `plane`. Also keep the agent's own raw record. It cannot exceed the transcript store. Default `off`. |
| `retention` | `string` | How long a session that can no longer be resumed is kept after its last activity. Default 90 days. |
| `resumeWindow` | `string` | How long after a limit ended a session it can still be resumed. No default for a session you start. |
| `poolRelease` | `string` | For a pool session: `Done` deletes the workstation, and `Recycle` returns it to the pool. Default `Done`. |
| `startWorkstation` | `string` | `Never` or `IfIdleStopped`. Whether the session starts its workstation when the workstation's idle policy stopped it. Never a workstation a person or a run limit stopped. Default `Never`. |

Naming `transcriptHotWindow` or `transcriptStorageRef` with a store other than `plane` is refused. A transcript store
that the workstation cannot reach is refused when you create the session.
[Transcript storage and retention](https://docs-stg.ringleader.dev/workstations/sessions/agent-sessions/#transcript-storage-and-retention) says how
long each store keeps a transcript.

### Fields only a session carries

A configuration layer cannot set these, so a layer cannot stop or speak for another person's session.

| Field | Type | Description |
|-------|------|-------------|
| `stopped`, `stopReason` | `bool`, `string` | Stops the session, with a reason of up to 1024 bytes. `rl agentsession stop` writes them. |
| `done`, `doneReason` | `bool`, `string` | Marks the session done, with a reason of up to 1024 bytes. |
| `takesTurns` | `bool` | `false` means nobody will send a turn: Ringleader refuses every input and the session ends at the agent's first turn boundary. It cannot be combined with `autoResumePrompt`. |
| `autoResumePrompt` | `string` | The text sent as the first input after each resume. |
| `displayName` | `string` | A label of up to 64 characters, with no control characters and no space at either end. The owner or an administrator sets it. |
| `restartNonce` | `string` | `rl agentsession restart` writes it. |
| `input` | `object` | The input the commands `send`, `approve`, `deny` and `interrupt` write. Leave it to them. |

## Phases

| Phase | Meaning |
|-------|---------|
| `Pending` | The session waits to start. `status.startWait` says what it waits on. |
| `Starting` | The agent is starting. |
| `Running` | The agent is working. |
| `WaitingForInput` | The agent is blocked on a person, for a permission answer or the next turn. |
| `Stopped` | A person stopped the session, or its workstation stopped. You can resume it. |
| `Failed` | The agent failed, an `endWhen.failed` line matched, or a one-shot session's last turn failed. |
| `Done` | The agent finished, or a person marked the session done. You can resume it. |

A workstation that stops always yields `Stopped`, never `Failed`.

## Status fields

A session reports a message and no conditions. `rl agentsession describe` prints the spec, the status and the events.

| Field | Type | Description |
|-------|------|-------------|
| `phase` | `string` | One of the phases above. |
| `message` | `string` | The one-line headline. |
| `endedBy` | `string` | The declared limit that ended the session: `endOnFirstIdle`, `endWhen`, `idleTimeout`, `maxDuration`, `maxCost`, `startDeadline` or `maxAutoResumes`. Empty when a person ended it. |
| `stoppedBy`, `doneBy`, `resumedBy` | `object` | Who did it, when and why. |
| `pendingRequest` | `object` | What the agent waits for, a `turn` or a `permission` answer. |
| `workstation`, `agentSessionID` | `string` | The workstation that runs the session, and the agent's own conversation id. |
| `cost`, `usage` | `object` | Spend in US dollars, and token use. |
| `startedAt`, `lastActivity` | `string` | When the agent started, and when it last did something. |
| `transcript` | `object` | The `store` in use, the `reason` Ringleader chose it, the `storage` it seals into, and `keptUntil`. |
| `startWait`, `startWaitReason` | `string` | Why a `Pending` session has not started. |
| `appliedConfigs` | `[]object` | The configuration layers that reached the session. |
| `permissions`, `effort`, `model` | `object` | What the agent honored, ignored or refused. |
| `steps`, `autoResume`, `notes` | | The session's runs, its auto-resume count and its notes. |

`rl agentsession get` prints the namespace, name, owner, display name, phase, what the session waits for, the
workstation and the age. `rl agentsession wait` takes a phase name for `--for`, such as `Running` or `WaitingForInput`.

## AgentSessionConfig

A configuration layer sets defaults for the sessions it matches. This one gives every session labeled `team: platform`
in the `dev` namespace the same agent, model and limits:

```yaml
apiVersion: workstations.ringleader.dev/v1
kind: AgentSessionConfig
metadata:
  name: team-defaults
  namespace: dev
spec:
  selector:
    matchLabels:
      team: platform
  priority: 10
  agent: claude
  model: sonnet
  permissions:
    mode: acceptEdits
  lifecycle:
    idleTimeout: 30m
    maxCost: 5
```

A member authors a layer for their own sessions, and an administrator authors a shared layer for a team. A session
gets a layer when its labels match the selector, or when `spec.configs` names the layer.
`rl agentsession create -l team=platform` puts a label on a session.

A configuration layer takes every field of the sections "What to run" (except `configs` and `worktreeSetRef`),
"Permissions and identity" and "Lifecycle", plus these:

| Field | Type | Description |
|-------|------|-------------|
| `selector.matchLabels` | `map` | Sessions that receive the layer automatically. |
| `selector.workstationLabels` | `map` | Sessions whose workstation carries these labels. |
| `selector.ownerScope` | `bool` | Only sessions that the layer's owner owns. |
| `selector.matchOwners` | `[]object` | Only sessions these owners own. Each entry is `{kind, name, namespace}`, where `kind` is a user, a service account or a group. |
| `priority` | `int` | The layer's place in the order. A lower number applies first. |

A selector reaches only sessions that its author has the reach to affect. A layer that a session names in `spec.configs`
always applies. `rl agentsessionconfig` has no verbs in its help. Create and read a layer with `rl apply -f` and
`rl get agentsessionconfig`.

### How layers merge

Ringleader folds the layers into the session in `priority` order, and the session's own fields win:

| Field | How layers combine |
|-------|--------------------|
| Scalars such as `agent` and `model` | The last layer by priority wins. The session's own value wins over every layer. |
| `env` | Merged key by key. |
| `permissions.allow`, `identity` and `modelParams.extraArgs.<agent>` | Taken whole, and the session's own value replaces a layer's. |

`rl agentsession get-resolved-configuration fix-login` prints the merged result. It lists the layers that reached the
session, including those that Ringleader refused and why.

## Limits

| What | Limit |
|------|-------|
| Name | Up to 253 characters, lowercase letters, digits, `-` and `.`. |
| Display name | 64 characters. |
| Stop or done reason | 1024 bytes. |
| `effort` | One word, 64 bytes. |
| `endWhen` pattern | 256 bytes. |
| `maxCost` | Above 0, in US dollars. |
| `maxAutoResumes` | 0 or more. Default 5. |
| Move | A conversation file up to 64 MiB, for `claude`, `codex` and `pi`. |

## Next steps

- [Agent sessions](https://docs-stg.ringleader.dev/workstations/sessions/agent-sessions/): how a session works, and how to start and manage one.
- [Agent session commands](https://docs-stg.ringleader.dev/reference/cli/commands/agent-sessions/): every command and flag.
- [TerminalSession and LocalTerminalSession](https://docs-stg.ringleader.dev/reference/resources/terminalsession/): the kinds for plain shells.
- [Storage](https://docs-stg.ringleader.dev/reference/resources/storage/): the bucket a `plane` transcript is sealed into.
- [Grant](https://docs-stg.ringleader.dev/reference/resources/grant/): the kind that `rl agentsession share` creates.

