patchwise-agent-studio / docs /AI_MONITORING.md
EnergyVenom's picture
Astra: PO/GL actions, usage coverage, assisted sign-in, self-healing, recorder, new top navigation and theme (172a4e22a2bf)
fb62a97 verified
|
Raw History Blame Contribute Delete
3.96 kB

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.