File size: 3,959 Bytes
fb62a97
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# AI monitoring, evaluations and LangSmith

Admins can see the page at **More → AI monitoring** (`/ai-monitoring`). It has three parts.

## How the models behave

Every model call the LLM router makes is one row in `llm_calls`. That covers runs, the assistant and evaluations.

**What each row holds**

- Task, node, run and prompt name.
- The route the privacy policy planned (`frontier`, `local` or `stub`) and what actually answered: route, provider and
  model.
- Each attempt: route, model, latency, tokens, and why it failed. The failure kinds are `provider` (unreachable or an
  error), `schema` (the answer did not fit) and `validation` (the answer broke the task's rule, such as an invented
  number or an element name that is not on the page).
- Whether the deterministic baseline had to stand in, and the total latency and tokens.

**What is never stored:** prompts and answers. Rows older than 90 days are removed at startup.

**What the page shows:** calls, the share answered as planned (with the split between external model, local model and
built-in rules), rule checks failed, p50 and p95 latency, and tokens. It shows calls per day, tables by task and by
model, and the latest problems with a link to the run. Evaluation calls are left out of these numbers.

**API:** `GET /api/ai/monitoring?days=7` and `GET /api/ai/calls?limit=100&task=triage`.

## Evaluations

Datasets live in `coworker/evals/datasets/*.json`: synthetic cases drawn from real Patchwise work. Each case lists
its expectations.

| task | what is checked |
|---|---|
| `triage` | the failure category (ui_change, data, timing, environment, real_defect) |
| `self_heal` | the new name of a renamed element, chosen from the page's own elements |
| `chat_intent` | the assistant's tool, among the plausible ones |
| `summary` | the summary keeps the key counts, invents no number and states no go/no-go |
| `chat_answer` | the rephrased answer keeps the facts and stays short and plain |

Each case is scored on three things:

1. The answer fits the task's schema.
2. It passes the task's rules, using the same `llm.router.validate_task` the app enforces.
3. It meets the case's expectations (`equals`, `in`, `contains_all`, `not_contains`, `len_between`).

The model is called directly, with no routing and no fallback, so the score is the model's own. The targets are:

- `local`: the Ollama model;
- `external`: the frontier model, only on tasks that may go to it, so local-only tasks are skipped;
- `stub`: the deterministic baseline, which gives a reference score to compare a model against.

The API is `GET /api/ai/evals/datasets`, `POST /api/ai/evals {"target": "local", "tasks": ["triage"]}`,
`GET /api/ai/evals` and `GET /api/ai/evals/{id}`. To add a case, add it to the dataset file; no code change is
needed.

## LangSmith (optional)

The export is off by default. Turn it on in the LangSmith card, or set `LANGSMITH_TRACING=true` with
`LANGSMITH_API_KEY` (and optionally `LANGSMITH_PROJECT` and `LANGSMITH_ENDPOINT`) as Space secrets. A key saved in the
app is write-only (vault `langsmith.api_key`).

- **Runs:** each model call becomes an `llm` run in the project. It carries the task, route, model, latency, tokens,
  attempts and the Patchwise run id, and is tagged with the task and route.
- **Content policy:**
  - Calls on **client** data (from the pod, results or chat) are sent as metadata only. Their prompt and answer are
    replaced by a note.
  - Calls on **public or redacted** data send their content only if "Also send prompts and answers" is on.
  - **Evaluation** calls use synthetic data, so they are sent with content plus a `correct` feedback score (1 or 0),
    with the failed checks as the comment.
- **Transport:** everything goes through the egress gate (https, LangSmith's host only), in batches every few
  seconds. A failure is retried once and then dropped, so monitoring never blocks a run. **Send a test run** checks
  the key.