# Online evaluation

Record a metric from inside the agent, during the session it describes — it attaches to that session automatically.

Online evaluation means scoring inside the agent's own process while the session is live: an inline judge grades the reply it just produced, a guardrail reports pass/fail, a timer reports how long a step took. The metric needs no ids — inside a session, it attaches to that session automatically.

## Record a metric

:::tabs
:::tab[Python]

```python
from brizz import record_metric, start_session

with start_session("session-123"):
    reply = agent.run(prompt)

    score = my_evaluator.score(prompt, reply)
    record_metric("quality_score", score, unit="score", min_value=0, max_value=1, polarity="positive")
```

:::tab[Node.js]

```typescript
import { startSession, recordMetric } from '@brizz/sdk';

await startSession('session-123', async () => {
  const reply = await agent.run(prompt);

  const score = await myEvaluator.score(prompt, reply);
  recordMetric({
    name: 'quality_score',
    value: score,
    unit: 'score',
    minValue: 0,
    maxValue: 1,
    polarity: 'positive',
  });
});
```

:::

The metric is filed under the service you initialized Brizz with, and stamped with the current time. Pass `attributes` to label it — which evaluator produced it, which rubric version, which variant the user saw:

```python
record_metric("quality_score", score, attributes={"evaluator": "gpt-4o", "rubric": "v2"})
```

## Attribute it to one turn

When called inside a [message](/docs/instrument/message-ids.md) scope, the metric also carries that message id, so it can be attributed to a single turn rather than the whole session.

## When you're not in the session any more

If the score arrives after the session scope has closed — or from a different process altogether — pass the conversation explicitly instead. See [Offline evaluation](/docs/instrument/record-metric/offline-evaluation.md).

## See also

- [Record metrics](/docs/instrument/record-metric.md) — fields, validation, and describing a metric once.
- [Sessions](/docs/instrument/sessions.md) — the scope the metric picks its session up from.
- [Message IDs](/docs/instrument/message-ids.md) — per-turn attribution.

---

[All Brizz documentation](https://docs.brizz.ai/llms.txt) · [Full documentation (single file)](https://docs.brizz.ai/llms-full.txt)
