Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Environment:42 evey Hermes plugins Langfuse

From Leeroopedia
Knowledge Sources
Domains Observability, Cost_Monitoring, Trace_Retrieval
Last Updated 2026-10-29 00:00 GMT

Overview

Langfuse observability platform providing LLM trace queries via REST API with Basic auth, used for cost tracking, budget enforcement, and memory consolidation.

Description

This environment provides access to a self-hosted or cloud Langfuse instance. The plugins query two API endpoints: /api/public/traces for trace-level cost data and /api/public/observations (type=GENERATION) for observation-level analytics. Authentication uses HTTP Basic with base64-encoded public/secret key pairs. The cost-guard plugin queries traces for per-model cost breakdowns and budget comparison, the digest plugin queries traces for overnight cost summaries, and the memory-consolidate plugin queries traces to extract facts from yesterday's conversations.

= Usage

Use this environment for cost tracking (cost_check, cost_analytics, cost_set_budget), morning digest cost aggregation (daily_digest), and memory consolidation trace retrieval (consolidate_daily_memory). All three require LANGFUSE_HOST, LANGFUSE_PUBLIC_KEY, and LANGFUSE_SECRET_KEY to be set.

System Requirements

Category Requirement Notes
OS Any (HTTP client) Uses urllib.request from stdlib
Hardware Network access to Langfuse server Local or cloud-hosted
Network HTTP/HTTPS to Langfuse host 10-15 second timeout per query
Python 3.10+ urllib, base64 from stdlib

Dependencies

System Packages

  • None — uses only Python stdlib (urllib.request, base64, json)

Python Packages

  • Python stdlib only: urllib.request, urllib.error, base64, json, time

External Services

  • Langfuse instance (self-hosted or cloud) accessible via HTTP/HTTPS

Credentials

The following environment variables must be set:

  • LANGFUSE_HOST: Base URL of the Langfuse server (e.g., http://localhost:3000)
  • LANGFUSE_PUBLIC_KEY: Langfuse public API key (Basic auth username)
  • LANGFUSE_SECRET_KEY: Langfuse secret API key (Basic auth password)

Never hardcode or log these values. The plugins read them at module-load time via os.environ.get().

Quick Install

# Self-host Langfuse (Docker) or use cloud — then set env vars:
export LANGFUSE_HOST="http://localhost:3000"
export LANGFUSE_PUBLIC_KEY="pk-lf-..."
export LANGFUSE_SECRET_KEY="sk-lf-..."

# Add to docker-compose.yml hermes-agent environment block
# Test connectivity:
python -c "import urllib.request,base64,os; \
  auth=base64.b64encode(f'{os.environ[\"LANGFUSE_PUBLIC_KEY\"]}:{os.environ[\"LANGFUSE_SECRET_KEY\"]}'.encode()).decode(); \
  req=urllib.request.Request(f'{os.environ[\"LANGFUSE_HOST\"]}/api/public/traces?limit=1', headers={'Authorization':f'Basic {auth}'}); \
  print(urllib.request.urlopen(req,timeout=10).read()[:200])"

Code Evidence

Configuration check from evey-cost-guard/__init__.py:77-95:

def _check_langfuse_config():
    """Return an error dict if Langfuse is not configured, else None."""
    missing = []
    if not LANGFUSE_HOST:
        missing.append("LANGFUSE_HOST")
    if not LANGFUSE_PUBLIC:
        missing.append("LANGFUSE_PUBLIC_KEY")
    if not LANGFUSE_SECRET:
        missing.append("LANGFUSE_SECRET_KEY")
    if missing:
        return {
            "error": (
                f"Langfuse not configured — missing env vars: {', '.join(missing)}. "
                "Add them to the hermes-agent environment in docker-compose.yml."
            ),
            "total_cost": 0,
            "models": {},
        }
    return None

Basic auth header from evey-cost-guard/__init__.py:98-101:

def _get_auth_header():
    """Base64 auth for Langfuse API."""
    creds = f"{LANGFUSE_PUBLIC}:{LANGFUSE_SECRET}"
    return b64encode(creds.encode()).decode()

Trace query from evey-memory-consolidate/__init__.py:95-117:

def _langfuse_query(hours_back=24):
    from_ts = time.strftime("%Y-%m-%dT%H:%M:%SZ", time.gmtime(time.time() - hours_back * 3600))
    lf_pub = os.environ.get("LANGFUSE_PUBLIC_KEY", "")
    lf_sec = os.environ.get("LANGFUSE_SECRET_KEY", "")
    auth = b64encode(f"{lf_pub}:{lf_sec}".encode()).decode()
    url = f"{LANGFUSE_HOST}/api/public/traces?fromTimestamp={from_ts}"
    try:
        req = urllib.request.Request(url, headers={"Authorization": f"Basic {auth}"})
        with urllib.request.urlopen(req, timeout=10) as resp:
            data = json.loads(resp.read())
        traces = data.get("data", [])
        # ... extract summaries
    except Exception:
        return ["Memory consolidation unavailable"]

Common Errors

Error Message Cause Solution
Langfuse not configured — missing env vars One or more env vars not set Set LANGFUSE_HOST, LANGFUSE_PUBLIC_KEY, LANGFUSE_SECRET_KEY in docker-compose.yml
Langfuse query failed: URLError(...) Network unreachable or Langfuse server down Check Langfuse container is running and LANGFUSE_HOST is correct
Memory consolidation unavailable Trace query failed (wrapped in except) Verify Langfuse is accessible and credentials are valid
total_cost: 0 with no error No traces in the time period Normal when no LLM calls have been made yet

Compatibility Notes

  • Self-hosted vs cloud: Works with both; only the LANGFUSE_HOST URL differs.
  • API endpoints: Uses /api/public/traces and /api/public/observations (public REST API).
  • Timeout: 10 seconds for trace queries, 15 seconds for observation queries.
  • Graceful degradation: All plugins fail-safe — if Langfuse is unconfigured or unreachable, they return error messages or zero-cost defaults rather than crashing.

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment