# Correct this, and an agent's Instructions page — the screens people teach an agent on (Agents.Teaching kit)

> Osysharp.Agents.Teaching draws the two places people teach an agent. WorkTeaching(task) goes on the page of one piece of work: what it handed back, what it was told when it ran, each step of its record, and "Correct this" on each — what was wrong, what it should have been, why, and an instruction proposed from it in the same breath. AgentInstructions(agent) is an agent's Instructions page: what is waiting to be read, what is active and since when, who decided, what each was drawn from, how much work was sent it and how often it was still corrected, and the history of every set — with Activate, Edit, Reject, Retire and Roll back for those who teach.

<!-- id: agent-teaching-screens · area: agent · stability: preview · html: https://osysharp.com/reference/agent/teaching-screens/ -->

## Summary        {#summary}
```osy syntax
use Osysharp.Agents.Teaching;

[Route("/work/{task}")] [Authorize(UsesAgents)]
component WorkPage(Guid task) { render { WorkTeaching(task); } }                    // correct a piece of work

[Route("/agents/tagger")] [Authorize(UsesAgents)]
component TaggerPage() { render { AgentInstructions(Agents.Of<Tagger>().Name); } }  // read, activate, retire, roll back
```

## Signature      {#signature}
```osy syntax
component WorkTeaching(Guid task, bool beside = false)   // beside: only what teaching adds, under a page that shows the work
component CorrectThis(Guid task, int step = 0, Guid? proposal = null, string label = "Correct this",
                      string agent = "the agent", Action? changed = null, bool quiet = false)
component AgentInstructions(string agent)
component CorrectionLine(CorrectionCard c)

WorkTeachingOf(Guid task) → WorkTeachingView?       // null: not whoever-is-looking's to read
InstructionBoardOf(string agent) → InstructionBoard
SendCorrection(Guid task, CorrectionForm form) → CorrectionSent
class CorrectionForm { string Wrong, Right, Because; CorrectionSeverity Severity; int Step; Guid? Proposal;
                       bool Propose; string Guidance; bool OnlyForMe; }
```

## Description    {#description}

### What goes on a piece of work's page?   {#work}
`WorkTeaching(task)` draws, for whoever may read that work: what it is about and how it ended; **what it handed
back**, with **Correct this** under it; **what it was told** — the sentence `InstructionsOf` says, the instructions
it was sent, and those made active since that it was not; the **corrections** made so far, each with who wrote it
and how much it mattered; and its **steps**, each with its own button once they are shown.

On a page that already shows the work — the inspector ([The inspector — one piece of an agent's work, readable by a person who was not there (Agents.Inspector kit)](https://osysharp.com/reference/agent/inspector/)) — `WorkTeaching(task, beside: true)`
draws only what teaching adds: **Correct this**, the corrections made so far, and each step's own button.

Correct this opens in place: *What was wrong?*, *What should it have been?*, *Why?* — nothing is sent until all
three say something — *How much did it matter?*, and **Propose an instruction from this**, which is on unless the
person turns it off: *From now on* is what the agent would be told (left empty, what it should have been is used),
for all that skill's work or *only for the work it does for me*. Sending says what happened in a sentence, and that
the agent does nothing differently until somebody who teaches the agents makes the instruction active.

`CorrectThis(task, step: n, label: "Correct step " + n)` is the button alone, for a run page of your own; give each
its own `label` so that they can be told apart, and `quiet: true` in a row of them.

### What is on the Instructions page?   {#page}
`AgentInstructions(agent)`, top to bottom:

- **Where it stands** — the set the agent is on, and how many things it is told beyond what its developers wrote.
- **Waiting to be read** — each proposed instruction: its words, its reason, what work it is for, who proposed it
  and from how many corrections (shown on request), with **Activate**, **Edit** and **Reject**. Shown only when
  something waits.
- **Active** — the same, with who made it active and when, and **whether it helped** as counts; **Retire** asks why.
- **Retired and rejected** — folded away; a retired one can be made active again.
- **History** — every set, newest first: who changed what, when and why. **Roll back to set N** on each earlier one
  says what will happen and asks why.

Somebody who gives the agent work and does not teach it sees what it is told for their own work, what they proposed
themselves, and no buttons. What a press is refused — a fourth instruction where three are the bound — is said on
the row, in the kit's own words.

### What do the screens decide?   {#decide}
Nothing. Each press calls [`Osysharp.Agents`](https://osysharp.com/reference/agent/teaching/)' own function for it, which says who may; the
screens offer a control only to somebody it will work for.

### How is it tested?   {#tests}
As a person: `Ui.Click("Correct this")`, fill the three questions by their labels, `Ui.Click("Send correction")`;
on the page `Ui.Click("Activate")`, `Ui.Click("Retire")` then fill "Why is it retired?", `Ui.Click("Roll back to
set 1")` then fill "Why is it put back?". Regions are named for `within:` — "Result", "What it was told",
"Corrections", "Step 6", "Waiting to be read", "Active", "History", "Set 2". An agent's own run goes in a `runas`
block with a [scripted model](https://osysharp.com/reference/agent/testing/).

## Examples       {#examples}
```osy title="a work page and an agent's page, each one line" test app=agent-teaching-screens
app Nursery {
  use Osysharp.Agents;
  use Osysharp.Agents.Teaching;
  use Osysharp.Llm;
  use Osysharp.Identity;
  use Osysharp.Observability;
  use Osysharp.Workflow;
  use Osysharp.Ui;
  model "model/**/*.osy";
}

using Osysharp.Agents;
using Osysharp.Agents.Teaching;
using Osysharp.Identity;
using Osysharp.Llm;

app.Llm = new LlmSetup {
  Models = [ new LlmModel { Name = "Everyday", Client = new ScriptedModel { Name = "Everyday" }, Model = "scripted-everyday",
                            Price = new LlmPrice { Input = 1, Output = 5 }, MaxOutputTokens = 1000 } ],
  Default = "Everyday",
};
app.Agents = new AgentsSetup { Agents = [new Tagger()] };

[Role] enum NurseryRole { Authenticator, Grower, Head, Tags }
partial entity RoleGrant { security { allow read when IsAuthenticated; } }
policy IsGrower => RoleGrant.Any(g => g.Member == user && g.Role == NurseryRole.Grower);
policy IsHead   => RoleGrant.Any(g => g.Member == user && g.Role == NurseryRole.Head);

policy UsesAgents       => IsGrower || IsHead;
policy SupervisesAgents => IsHead;
policy TeachesAgents    => IsHead;

entity Person : Principal {
  security { allow read when IsAuthenticated || IsAuthenticator; allow create when IsAuthenticator; }
}

public class Tag { public string Words = ""; }
public class WriteTag : Skill<string, Tag> { public override string Description => "Write the tag for one plant."; }

[Actor(Roles = [NurseryRole.Tags])]
public class Tagger : Agent {
  public static Person Principal => new Person { Email = "tagger@nursery.example", DisplayName = "Tagger" };
  public override string Purpose => "You write the tags that hang on the plants of a small nursery.";
  public override List<SkillBase> Skills => [new WriteTag()];
}

/// One piece of the tagger's work: what it handed back, what it was told, and "Correct this".
[Route("/work/{task}")] [Authorize(UsesAgents)] [Render(CSR)] [Title("The tagger's work")]
component WorkPage(Guid task) {
  render { Stack(p: 5, maxW: "860px") { WorkTeaching(task); } }
}

/// What the tagger is told: proposed, active, retired, and the history of every set.
[Route("/")] [Authorize(UsesAgents)] [Render(CSR)] [Title("Tagger")]
component TaggerPage() {
  render {
    Stack(gap: 5, p: 5, maxW: "860px") {
      PageHead("Tagger", subtitle: "Writes the tags that hang on the plants.");
      AgentInstructions("Tagger");
    }
  }
}
```

## See also       {#see-also}
- [Correcting an agent, and what it is told from then on — corrections, instructions, instruction sets and rollback (Agents kit)](https://osysharp.com/reference/agent/teaching/) — corrections, instructions, sets and rollback: what the screens call
- [An agent's proposals and questions in a person's inbox, and an inbox item in an agent's hands (Agents.HumanRequests kit)](https://osysharp.com/reference/agent/requests/) — the other screen people meet an agent on: its proposals and questions in the inbox
