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

# Evaluate agent behavior

> Grade turns with the Evaluation library, and record people's ratings in a table of your own.

## Grade turns

The [Evaluation library](https://github.com/bijectionhq/bijection/tree/main/npm-packages/libraries/evaluation),
`@bijectionhq/library-evaluation`, measures AI behavior for the app that
includes it. A judge is a typed model task, and a grade is a check on
`(subject, digest, kind)`. Place its subtree in your tree, then:

* record offline runs with `runs.register` and `runs.observe`, and read them
  with `runs.report`;
* grade live items with `grades.grade`, sampled at the monitor's rate, and
  read `grades.summary`.

Grade a turn from the continuation that receives its result (see
[Turns from your code](https://docs.bijection.com/agents/turns.md)): pass the question, the
`TurnResult.text` and the evidence your tools returned. Key each grade by the
turn, so a grade is recorded once per turn.

## Record ratings

A rating is a fact in a table of your own, under the transcript label, written
by an exposed mutation that first checks the turn is the caller's:

```ts theme={"theme":{"light":"github-light-default","dark":"github-dark-default"}}
import { mutation, t, table } from "@bijectionhq/bijection";
import { support } from "./agents";
import { desk } from "./access";

export const ratings = table(
  { turn: t.string, by: t.principal, helpful: t.boolean, comment: t.maybe(t.string) },
  { key: ["turn", "by"], label: desk },
);

export const rate = mutation(
  {
    under: desk,
    allow: [support.participant],
    args: { turn: t.string, helpful: t.boolean, comment: t.maybe(t.string) },
    refuses: { NoTurn: null },
  },
  async (ctx, { turn, helpful, comment }) => {
    const own = await ctx.call(support.turns.get, { id: turn });
    if (own === null || !["completed", "failed", "stopped"].includes(own.state)) {
      ctx.refuse("NoTurn", "No settled turn of yours");
    }
    await ctx.insert(ratings({ turn, by: ctx.frame.as.id }), { helpful, comment });
    return null;
  },
);
```

`turns.get` returns `null` for a turn that is not the caller's, so a rating
can only name the rater's own settled turn. `insert` refuses `Exists` for a
second rating of the same turn by the same person.


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