Skip to content

feat(verifier): Port/re-implement Quality Verifier functionality from the Python LIP #345

Description

@matdev83

feat(verifier): Port/re-implement Quality Verifier functionality from the Python LIP

Reaserch transcript:

Found it. The feature is called the Quality Verifier (the circuit-breaker config still references its earlier codename "Angel" — see the quality_verifier_cooldown_seconds comment in config/config.example.yaml).

What it is

When enabled, every N eligible turns (quality_verifier_frequency, default 10) the proxy holds the main-model completion, calls a secondary verifier LLM (quality_verifier_model) with the conversation history so far, and asks it to audit the last completion. The verifier replies with exactly one of:

  • <status>NO_STEERING_NEEDED</status> → original output is returned
  • <steering>…</steering> → the proxy does an inline "recall" call of the main model with a private steering system message

It's off by default — enabled by setting quality_verifier_model (CLI --quality-verifier-model backend:model or YAML under session:).

Key functions

Function Location
QualityVerifierService.is_enabled() / should_run_verification() / should_run_for_request() — scheduling "every N turns" src/core/services/quality_verifier_service.py
build_verification_messages() — builds the verifier request (prompt + sanitized/truncated session history + completion under audit) src/core/services/quality_verifier_service.py
validate_quality_verifier_output_format() / maybe_retry_verifier_for_valid_xml() / build_invalid_format_retry_request() src/core/services/quality_verifier_service.py
Circuit breaker: is_healthy() / report_success() / report_failure() src/core/services/quality_verifier_service.py
run_quality_verifier_decision() — core decision flow (call verifier → parse verdict → steer/pass/fail-open) src/core/services/quality_verifier_orchestrator.py
QualityVerifierStreamVerifier.verify_or_passthrough() — streaming path: buffers chunks, verifies, replays or issues inline recall src/core/services/backend_request_manager/quality_verifier_stream_verifier.py
Turn ledger: _get/_set_quality_verifier_turn_count, reset_quality_verifier_eligible_turn_count() src/core/services/request_processor_service.py
_extract_quality_verifier_config() src/core/services/backend_request_manager/streaming_response_handler.py

Most important files

  1. src/core/services/quality_verifier_service.py — the service itself (scheduling, message building, format validation, circuit breaker)
  2. src/core/services/quality_verifier_orchestrator.pyrun_quality_verifier_decision(), the actual verify-and-steer flow
  3. src/core/services/backend_request_manager/quality_verifier_stream_verifier.py — streaming integration (verify_or_passthrough)
  4. src/core/services/request_processor_service.py — eligible-turn counting/reset (the "every N turns" trigger)
  5. src/core/services/quality_verifier_prompt_loader.py + config/prompts/quality_verifier_prompts/ — the verifier role prompt, steering template, tail reminder
  6. src/core/services/quality_verifier_steering_messages.py — renders/injects the private steering system message for the recall call
  7. src/core/di/registration_helpers/request_processing/_rp_backend_components.py + src/core/services/backend_request_manager_service.py — DI wiring into the request pipeline
  8. config/config.example.yaml (session: section) and src/core/cli.py (_warn_if_quality_verifier_frequency_too_low) — configuration
  9. docs/user_guide/features/quality-verifier.md — full documentation (also docs/quality-verifier-fractional-turns.md)

The "external LLM providing advice/steering" part is the verifier returning <steering> XML, and the "inline recall" mechanism (append_quality_verifier_steering_system_message) is how the main model actually gets steered on that same turn.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions