# openspec/changes/wf-keep-an-agent-working/proposal.md

## Why

An agent that shipped drifts: a prompt goes stale, an integration breaks, a vendor document is missing. Nobody owns reading its sessions, so the first sign is a bad outcome. The upkeep that keeps an agent useful gets an owner and a schedule, and each verdict is on the ledger, so the next sample skips what is already fixed.

## What Changes

- Add the `keep-an-agent-working` workflow to the PromptReports workflow library, run by the workflow runner as an agent acting for a person.
- PromptCompute: Read the agent's owner and the sessions its owner already judged (upkeep_prepare) (today: Planned).
- RepoOps: Sample 10 of the agent's scored sessions since the last cycle, each scored with the team's rubric (sample_agent_sessions) (today: Planned).
- PromptCompute: Send each session under the pass mark to the agent's owner with its transcript, score and findings; an agent with no owner sends them to the org's admins and says so (upkeep_send) (today: Planned).
- PromptCompute: The owner's verdict on each low session (fixed, not a problem, needs a lesson) is a ledger entry the next cycle reads (today: Planned).
- RepoOps: File a finding seen in more sessions than the team's threshold as a lesson proposal, held until a person approves it (propose_brain_entry) (today: Built).
- Write a signed record at the end of each run and count one workflow request.

## Impact

- Products: RepoOps, PromptCompute.
- Outside the family: Session scoring on for the team in RepoOps, on each person's own model key.
- State: Partly built. The sample read is built in RepoOps (repo-dashboard #8054) and the workflow and the owner's questions in PromptCompute (promptcompute.ai #1046), each off. Nothing runs until an operator turns on session scoring (mp-10 4.1), WF_KEEP_AN_AGENT_WORKING and TEAMMATE_QUESTIONS for the house org, and RepoOps's connector lists sample_agent_sessions. Filing a lesson proposal through propose_brain_entry is built today.
- Plan row: none yet (Proposed).

# openspec/changes/wf-keep-an-agent-working/tasks.md

## 1. Connect and authorize

- [ ] 1.1 Confirm the org has a connection for each of: RepoOps, PromptCompute. Stop and tell the user which is missing.
- [ ] 1.2 Get a PromptReports ID agent token for each product the run calls (RFC 8693 exchange). Where a product does not accept ID tokens yet, use its connect key.
- [ ] 1.3 Confirm no step writes; this workflow reads only.

## 2. Build the steps

- [ ] 2.1 PromptCompute: Read the agent's owner and the sessions its owner already judged (upkeep_prepare). Blocked: this part is Planned; until it ships, record the step's evidence as `missing` and continue.
- [ ] 2.2 RepoOps: Sample 10 of the agent's scored sessions since the last cycle, each scored with the team's rubric (sample_agent_sessions). Blocked: this part is Planned; until it ships, record the step's evidence as `missing` and continue.
- [ ] 2.3 PromptCompute: Send each session under the pass mark to the agent's owner with its transcript, score and findings; an agent with no owner sends them to the org's admins and says so (upkeep_send). Blocked: this part is Planned; until it ships, record the step's evidence as `missing` and continue.
- [ ] 2.4 PromptCompute: The owner's verdict on each low session (fixed, not a problem, needs a lesson) is a ledger entry the next cycle reads. Blocked: this part is Planned; until it ships, record the step's evidence as `missing` and continue.
- [ ] 2.5 RepoOps: File a finding seen in more sessions than the team's threshold as a lesson proposal, held until a person approves it (propose_brain_entry).

## 3. Verify and record

- [ ] 3.1 Run a dry run with the user's inputs: Agent = the agent in the registry, and the address its sessions are recorded under; Repository = optional: one repository's sessions.
- [ ] 3.2 Run it once for real; approve each gate as the user.
- [ ] 3.3 Measure the outcomes: Low sessions with an owner's verdict within the cycle; Repeated findings turned into an approved lesson.
- [ ] 3.4 Confirm the run left a signed record with a task id and one workflow request counted.

# openspec/changes/wf-keep-an-agent-working/specs/workflow-keep-an-agent-working/spec.md

## ADDED Requirements

### Requirement: Low sessions go to the agent's owner

A sampled session under the pass mark SHALL go to the agent's owner with its transcript, its score and its findings, and the owner's verdict SHALL be recorded on the ledger.

#### Scenario: Low sessions go to the agent's owner

- **WHEN** 2 of 10 sampled sessions score under the pass mark
- **THEN** the owner gets both, and each verdict is a ledger entry

### Requirement: A repeated finding becomes a lesson proposal

A finding seen in more sampled sessions than the team's threshold SHALL be filed as a lesson proposal, and MUST NOT reach a brief before a person approves it.

#### Scenario: A repeated finding becomes a lesson proposal

- **WHEN** three sampled sessions share one finding and the threshold is two
- **THEN** one lesson proposal is filed with the three sessions as evidence, and the next brief does not hold it until a person approves

### Requirement: Evidence stays honest

Each step SHALL report what it saw as measured, inferred or missing, and SHALL never report missing as measured.

#### Scenario: A product part is not built

- **WHEN** a step depends on a part that is Planned or Proposed
- **THEN** the step records `missing`, names the part, and the approval card shows the gap

### Requirement: One run is one workflow request

The runner SHALL count one workflow request at the run's first connector action, and SHALL NOT count retries, resumes, dry runs or a run a filter stops first.

#### Scenario: A gated step resumes after two days

- **WHEN** a person approves a step and the run resumes
- **THEN** the org's usage does not change
