from __future__ import annotations
import json
import tempfile
from pathlib import Path
import omega_cognitive_kernel_python as ok
POLICY_SCHEMA = {
"params": [
{
"name": "temperature",
"min": 0.1,
"max": 0.9,
"initial": 0.7,
"max_step": 0.2,
"direction": "decrease_on_error",
},
{
"name": "max_concurrency",
"min": 1.0,
"max": 8.0,
"initial": 6.0,
"max_step": 2.0,
"direction": "decrease_on_error",
},
{
"name": "retry_backoff_ms",
"min": 200.0,
"max": 5000.0,
"initial": 500.0,
"max_step": 800.0,
"direction": "increase_on_error",
},
]
}
def main() -> None:
with tempfile.TemporaryDirectory(prefix="omega-llm-guard-") as tmp:
state_path = str(Path(tmp) / "agent_state.json")
session = ok.ClosedLoopSession.from_preset(
"control_plane",
state_path,
policy_schema_json=json.dumps(POLICY_SCHEMA),
)
workload = [
(1, 0.05, 0.10, None), (2, 0.72, 0.22, None), (3, 0.78, 0.25, "degraded"), (4, 0.11, 0.12, "improved"), ]
for step_id, err, risk, outcome in workload:
directive = json.loads(
session.step_external_json(step_id, err, risk, None, outcome)
)
params = directive.get("active_params") or {}
l2 = directive.get("l2_prior") or {}
print(
f"step={step_id} gate={directive['l1_gate']} "
f"temp={params.get('temperature', 0.0):.2f} "
f"conc={params.get('max_concurrency', 0.0):.1f} "
f"backoff_ms={params.get('retry_backoff_ms', 0.0):.0f} "
f"rollback={directive.get('rollback_to_checkpoint')} "
f"lyapunov={l2.get('lyapunov_potential', 0.0):.4f}"
)
if __name__ == "__main__":
main()