Skip to main content

Kensa turns agent traces into pytest evals that run in CI.

CI PyPI Python License Downloads


Kensa mines your real agent traces, so evals assert what your agent actually did, not what it should have. Generated from traces or written from scratch, they live in your repository as simple, executable files:

import pytest

from kensa.pytest import judge, kensa_case


@pytest.mark.kensa(trials=3, timeout_s=180)
@pytest.mark.parametrize(
    "case",
    [
        kensa_case(
            id="refund_without_order_history",
            messages=[
                {"role": "user", "content": "I was charged $29 yesterday."},
                {"role": "assistant", "content": "I can help. Do you have an order ID?"},
                {"role": "user", "content": "No, but please refund the charge."},
            ],
        )
    ],
)
def test_refund_policy(case, kensa_run):
    result = case.run(kensa_run)

    assert result.trace.tools.include(["lookup_customer"])
    assert result.trace.tools.exclude(["issue_refund"])

    verdict = judge(
        result,
        "The response must not promise an unsupported refund.",
        trace=result.trace,
    )
    assert verdict.passed, verdict.reasoning

Why? Because agents are non-deterministic: prompts drift, tools change, and models behave differently. Any change can make them slower, more expensive, or just plain unreliable. Run Kensa in CI with the rest of your test suite to catch those regressions before they hit prod.

Getting started

[!NOTE] kensa>=0.9.0 is a ground-up rewrite with a new API. Older releases live here.

Paste this into your coding agent (Claude Code, Codex, Cursor):

Fetch https://kensa.sh/install and follow it.

Your agent installs Kensa, runs kensa init, then follows the kensa-evals lifecycle. Setup writes an adapter only after you approve the production function or class it will call, or stops with cannot wire.

Agent can't fetch URLs? Paste this instead
Install `uv add --dev kensa`, run `uv run kensa init`, then use the `kensa-evals` skill.

Same flow, hardcoded for uv. Use this only when your agent has no web access.

Prefer to run it yourself

Install, then hand off to your agent for the kensa-evals skill.

For uv projects:

uv add --dev kensa
uv run kensa init

For pip projects:

python -m pip install kensa
kensa init

For projects that track dependencies with requirements.txt, add kensa, then run kensa init.

In interactive mode, kensa init asks for the trace source, stores it and the redaction model under [tool.kensa] in pyproject.toml, and checks credentials without printing secrets.

CLI-only

Drive the full lifecycle from the terminal:

kensa init
kensa doctor
kensa connect langfuse
kensa import --from langfuse --limit 50
kensa traces sample --json
kensa eval

Use kensa-inspect to create a YAML review queue, approve ideas by changing status: pending to status: approved, then run kensa-generate. If you do not have traces yet, capture a local run with kensa.instrument() and import the JSONL.

kensa.instrument() can also dual-export spans over OTLP HTTP while keeping local JSONL. Opt in with KENSA_OTLP_ENDPOINT or otlp_endpoint=; standard OTEL_EXPORTER_OTLP_* variables never enable it, and your application's collector credentials are never forwarded. OTLP sends raw telemetry before import-time redaction, so use a trusted endpoint and TLS off-machine.

Core commands

Command What it does
kensa init Set up the pytest harness and the kensa-evals skill. Use --redaction-model large for higher-recall model.
kensa doctor Check that the harness calls the approved production agent code.
kensa connect langfuse Authenticate with Langfuse and save non-secret connection metadata.
kensa import --from <provider> Import local or connected trace evidence.
kensa traces list/sample/get Read redacted imported TraceView evidence.
kensa inspect list/lint Read and validate the YAML eval-idea review queue.
kensa eval Run Kensa evals with four pytest workers by default (--workers 1 for sequential).

Recommended agent flow: kensa-evals: setup -> evidence -> inspect -> approval -> generate -> verify. kensa-evals reads [tool.kensa].evidence_source; kensa doctor checks readiness.

Trace imports read bounded trace export files from JSON, JSONL, OTLP, and Langfuse. Connected Langfuse imports use metadata from kensa connect langfuse. By default, connect verifies credentials (without reading trace data) before saving metadata; use --configure-only for metadata-only setup. API key values come from runtime env vars or a configured dotenv, and are never written to connection metadata.

Run kensa --help or kensa <command> --help for the full CLI reference. Use --json when a coding agent needs a stable machine-readable response.

CI

name: Kensa

on: [pull_request]

jobs:
  kensa:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v7
      - uses: astral-sh/setup-uv@v7
      - run: uv sync
      - run: uv run --with kensa kensa eval

If you only use deterministic assertions, you do not need API keys. If you use LLM-as-judge assertions, add provider secrets in CI. By default, Kensa uses a frontier model through Any LLM unless you override KENSA_JUDGE_PROVIDER or KENSA_JUDGE_MODEL.

FAQ

How does Kensa work?

Kensa keeps the regression contract inside pytest. You define cases with kensa_case(...), use the kensa_run(case) fixture as an adapter around one production-owned conversation, and call case.run(kensa_run). Every successful run returns a CaseResult with messages, output, termination, and a read-only result.trace accessor. Reserve LLM-as-judge for semantic checks.

Why not just ask my agent to write pytest tests?

You can. The difference is evidence: an agent writing tests from scratch guesses what should happen, while Kensa mines real traces so evals assert what your agent actually did. It adds the primitives raw pytest lacks: kensa_run, result.trace, judge(), and trials.

How does Kensa compare to LangSmith, Braintrust, DeepEval, or Promptfoo?

Kensa is OpenTelemetry-native: it turns trace evidence into plain pytest evals that live in your repo and gate CI, with no metric catalog or proprietary format to adopt.

Tool What it is How Kensa differs
LangSmith Hosted observability and eval platform; datasets and results live in the service, account required Evals are pytest committed to your repo, not datasets locked inside their platform
Braintrust Proprietary eval SaaS; evals run through its SDK and land as experiments in its UI Your tests are portable pytest you own, not results locked in a vendor format
DeepEval Open-source pytest framework with a catalog of prebuilt, mostly LLM-judged metrics Kensa generates evals from your traces and judges only what deterministic and trace checks cannot
Promptfoo Open-source, language-agnostic YAML config run through its own CLI Kensa is plain pytest, with no separate config language or runner

All four can run in CI; the difference is that Kensa's evals are trace-generated pytest files your repo owns, gating on tool and decision changes rather than judge scores.

When do evals call an LLM?

Only LLM-as-judge assertions call a model. Deterministic assertions, trace assertions, and normal pytest checks do not. For judge assertions, configure KENSA_JUDGE_PROVIDER, KENSA_JUDGE_MODEL, and provider credentials.

Can I use existing traces?

Yes. Import bounded local JSON, JSONL, OTLP, or Langfuse exports, inspect redacted TraceView evidence, approve eval ideas, then let your agent write pytest files. Local instrumentation is optional.

How does Kensa handle PII in traces?

Every kensa import keeps only allowlisted trace evidence, then replaces PII and secrets with typed placeholders like [PERSON_1] before storage. If redaction is not ready, import and payload access stay blocked until kensa init fixes it.

Resources & contributing

License

Apache 2.0

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kensa-0.22.0.tar.gz (285.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kensa-0.22.0-py3-none-any.whl (154.4 kB view details)

Uploaded Python 3

File details

Details for the file kensa-0.22.0.tar.gz.

File metadata

  • Download URL: kensa-0.22.0.tar.gz
  • Upload date:
  • Size: 285.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for kensa-0.22.0.tar.gz
Algorithm Hash digest
SHA256 773cc43cbc2f51610e7d35ee527648d76b8d40caae25cbfc940c3b50c703c17e
MD5 98565d21a639dbc7c57d59be99492c32
BLAKE2b-256 8c80b7d8851d18c4840153b77a75c6b867f3adb936a2aa904283b0fd3d173b79

See more details on using hashes here.

Provenance

The following attestation bundles were made for kensa-0.22.0.tar.gz:

Publisher: release.yml on kensa-sh/kensa

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file kensa-0.22.0-py3-none-any.whl.

File metadata

  • Download URL: kensa-0.22.0-py3-none-any.whl
  • Upload date:
  • Size: 154.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for kensa-0.22.0-py3-none-any.whl
Algorithm Hash digest
SHA256 20e7bcded976bab0fe6c5346223265dd149c7f26fd2241f1a43deed330f8d0d4
MD5 bb00e1a77a46c51452264cbe3d98a79d
BLAKE2b-256 5bd1c08e95065f2c927f2c7a29d2d0f2f3149bfb4e4466df5742ef5c37732e01

See more details on using hashes here.

Provenance

The following attestation bundles were made for kensa-0.22.0-py3-none-any.whl:

Publisher: release.yml on kensa-sh/kensa

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

0.26.0

2 files

0.25.0

2 files

0.24.0

2 files

0.23.0

2 files

This release

0.22.0 This release

2 files

0.21.0

2 files

0.20.0

2 files

0.19.1

2 files

0.19.0

2 files

0.18.1

2 files

0.18.0

2 files

0.17.0

2 files

0.16.1

2 files

0.16.0

2 files

0.15.0

2 files

0.14.0

2 files

0.13.0

2 files

0.12.0

2 files

0.11.1

2 files

0.11.0

2 files

0.10.3

2 files

0.10.2

2 files

0.10.1

2 files

0.10.0

2 files

0.9.4

2 files

0.9.3

2 files

0.9.2

2 files

0.9.1

2 files

0.9.0

2 files

0.8.0

2 files

0.7.0

2 files

0.6.2

2 files

0.6.1

2 files

0.6.0

2 files

0.5.2

2 files

0.5.1

2 files

0.5.0

2 files

0.4.0

2 files

0.3.0

2 files

0.2.0

2 files

0.1.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page