Skip to content

Self-Improving Guard Loop

The self-improving guard loop turns reviewed feedback into auditable proposals. It does not train, submit jobs, change thresholds, or promote models by itself. Production changes require a separate operator-approved deployment step.

Proposal Gates

SelfImprovingGuardLoop enforces the control boundary:

  • every feedback row must carry an event_id and reviewer_id
  • manifests serialise event references and label counts, not prompt or response text
  • calibration updates require enough feedback and a narrow confidence interval
  • LoRA jobs are proposal-only and require held-out improvement plus rollback ID
  • dataset URIs with embedded credentials are rejected
from director_ai.core.guard_control import RiskEnvelope
from director_ai.core.self_evolving import SelfImprovingGuardLoop

loop = SelfImprovingGuardLoop(
    store=feedback_store,
    risk_envelope=RiskEnvelope(
        action_category="training",
        reversibility="costly",
        domain="regulated",
        calibrated_threshold=0.45,
        no_go_threshold=0.8,
    ),
    policy_id="policy.self_improving.regulated",
)

proposal = loop.propose_calibration_update(
    source_ref="feedback://recent-reviewed",
    current_threshold=0.55,
    candidate_threshold=0.58,
    confidence_low=0.51,
    confidence_high=0.61,
    rollback_id="threshold-profile-20260513-a",
)

approved = loop.approve(proposal, approval_id="review-20260513-002")
payload = loop.release(approved)

release() returns the approved proposal payload for an external deployment controller. It does not mutate runtime configuration.

The production contract is intentionally one-way: reviewed feedback can create calibration or LoRA training proposals, but only a separate human-reviewed deployment controller may apply those payloads. Keep the reviewed feedback dataset, approval record, rollback ID, and released payload together in the operator audit trail.

Full API

director_ai.core.self_evolving.guard_loop.SelfImprovingGuardLoop

SelfImprovingGuardLoop(*, store: FeedbackStore, risk_envelope: RiskEnvelope, policy_id: str)

Create reviewed-feedback proposals without self-applying updates.

build_manifest

build_manifest(*, source_ref: str) -> ReviewedFeedbackManifest

Build a tenant-safe manifest from reviewed feedback events.

propose_calibration_update

propose_calibration_update(*, source_ref: str, current_threshold: float, candidate_threshold: float, confidence_low: float, confidence_high: float, rollback_id: str, min_feedback: int = 32, max_interval_width: float = 0.1) -> GuardLoopProposal

Propose a calibrate-only threshold update for human approval.

propose_lora_job

propose_lora_job(*, source_ref: str, dataset_uri: str, base_model_ref: str, rollback_id: str, heldout_score: float, baseline_score: float, min_improvement: float = 0.0, min_feedback: int = 32) -> GuardLoopProposal

Propose, but do not submit, a LoRA training job.

approve

approve(proposal: GuardLoopProposal, *, approval_id: str) -> GuardLoopProposal

Approve a proposal without applying it.

release

release(proposal: GuardLoopProposal) -> dict[str, Any]

Return proposal payload only after approval; never apply it.

director_ai.core.self_evolving.guard_loop.ReviewedFeedbackManifest dataclass

ReviewedFeedbackManifest(manifest_id: str, source_ref: str, event_count: int, label_counts: Mapping[str, int], reviewer_ids: Sequence[str], event_refs: Sequence[str])

Tenant-safe manifest for reviewed feedback used by improvement proposals.

to_dict

to_dict() -> dict[str, Any]

Serialise without prompt, response, or private evidence text.

director_ai.core.self_evolving.guard_loop.GuardLoopProposal dataclass

GuardLoopProposal(proposal_id: str, proposal_type: ProposalType, manifest: ReviewedFeedbackManifest, rollback_id: str, guard_decision: GuardDecision, payload: Mapping[str, Any], submitted: bool = False, promotion_status: str = 'proposed', approved: bool = False, approval_id: str = '')

Calibration or training proposal that cannot apply itself.

to_dict

to_dict() -> dict[str, Any]

Return a tenant-safe audit payload.

to_safety_event

to_safety_event(*, hook_id: str, hook_scope: str = 'agent', request_id: str = '', tenant_id: str = '', latency_ms: float | None = None) -> SafetyEvent

Convert the proposal guard decision to a tenant-safe event.