Skip to content
Back to skills

Langfuse Continuous Optimizer

ASecurity

Continuous LangFuse-driven optimization loop for OpenClaw/OpenRouter model routing and prompt usage controls with persistent local memory. Use when Codex needs to ingest LangFuse observations and evaluator scores, generate task-level routing policy JSON, and run scheduled safe promotion cycles that tune cost-quality-latency tradeoffs automatically.

  • 14 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added September 7, 2026
ai-agentspythonbashrailsapi

Works with

  • api

Security analysis

A100/100

Pro scans all 6 files and shows the line behind each finding

Scanned September 7, 2026

npx -y skills add modbender/skill-library-mcp --skill langfuse-continuous-optimizer --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Langfuse Continuous Optimizer?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Langfuse Continuous Optimizer
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/modbender-langfuse-continuous-optimizer/badge)](https://www.skillsdirectory.com/skills/modbender-langfuse-continuous-optimizer)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: langfuse-continuous-optimizer
description: Continuous LangFuse-driven optimization loop for OpenClaw/OpenRouter model routing and prompt usage controls with persistent local memory. Use when Codex needs to ingest LangFuse observations and evaluator scores, generate task-level routing policy JSON, and run scheduled safe promotion cycles that tune cost-quality-latency tradeoffs automatically.
metadata: {"openclaw":{"emoji":"🧠","requires":{"env":["LANGFUSE_PUBLIC_KEY","LANGFUSE_SECRET_KEY"],"anyBins":["python","python3"]},"primaryEnv":"LANGFUSE_SECRET_KEY"}}
---

# Langfuse Continuous Optimizer

## Overview

Run an automated observe -> evaluate -> adapt loop backed by LangFuse data.

This skill is independent and self-contained: it includes both policy builder and continuous optimizer scripts.

## Quick Start

```bash
# Single optimization cycle (LangFuse API -> staged policy -> promoted live policy if gate passes)
python scripts/langfuse_openclaw_optimizer.py run-once \
  --langfuse-host https://us.cloud.langfuse.com \
  --window-hours 24 \
  --out-dir ~/.openclaw/optimizer \
  --live-policy-path ~/.openclaw/llm_routing_policy.json \
  --promote-live-policy \
  --write-memory \
  --save-config

# Continuous daemon
python scripts/langfuse_openclaw_optimizer.py daemon \
  --interval-min 30 \
  --save-config

# Toggle settings later (persisted)
python scripts/langfuse_openclaw_optimizer.py configure --disable-promote-live-policy --show
python scripts/langfuse_openclaw_optimizer.py configure --promote-live-policy --write-memory --show
```

Credentials:

- `LANGFUSE_PUBLIC_KEY`
- `LANGFUSE_SECRET_KEY`

## Workflow

1. Pull LangFuse observations and scores from the configured time window.
2. Normalize telemetry and build staged routing policy artifacts.
3. Compare staged policy against current live policy with switch guardrails.
4. Promote only when gain and quality constraints are met and promotion is explicitly enabled.
5. Persist cycle memory to reduce policy churn and enable rollback reasoning.

## Safety

- Network egress: calls LangFuse Public API.
- Local writes: writes raw snapshots, staged artifacts, and optional memory state under `--out-dir`.
- Live policy overwrite is opt-in via `--promote-live-policy`.
- Without `--promote-live-policy`, cycles are non-destructive (stage/evaluate only).
- Save persisted defaults with `--save-config`; edit/toggle with `configure`.

## Runtime Integration

Use the generated live policy in OpenClaw/LLM runtime via:

```bash
--llm-routing-policy-file ~/.openclaw/llm_routing_policy.json
--llm-policy-reload-sec 300
```

Tag requests with stable task keys (`planning`, `tool-selection`, `retrieval`, `summarization`, `generation`, etc.) so per-task routing converges quickly.

## Resources (optional)

### scripts/

- `scripts/langfuse_openclaw_optimizer.py`: API pull + cycle orchestration + promotion gating + persistent memory.
- `scripts/closed_loop_prompt_ops.py`: normalization and policy generation engine used by the optimizer.

### references/

- `references/data-contracts.md`: input/output schemas and artifacts.
- `references/closed-loop-playbook.md`: guardrails, mutation policy, memory strategy, runtime integration notes.

Files in this skill

  • SKILL.md3.2 KB
  • agents/openai.yaml289 B
  • references/closed-loop-playbook.md3.2 KB
  • references/data-contracts.md2.8 KB
  • scripts/closed_loop_prompt_ops.py46.5 KB
  • scripts/langfuse_openclaw_optimizer.py23.6 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…