# Festinger Proxy Configuration

# Where the real Ollama is running (for /api/chat, /api/generate, /api/*)
upstream_ollama: "http://host.docker.internal:11434"

# Where the real Anthropic API is running (for /v1/messages)
# Override via UPSTREAM_ANTHROPIC env var if needed
upstream_anthropic: "https://api.anthropic.com"

# Where the real OpenAI-compatible API is running (for /v1/chat/completions).
# For LM Studio set this to its local address, e.g. "http://host.docker.internal:1234"
# Override via UPSTREAM_OPENAI env var if needed
upstream_openai: "http://host.docker.internal:1234"

# Port this proxy listens on inside the container (exposed as 11434 on the docker network)
proxy_port: 11434

# Postgres connection string (overridable via POSTGRES_DSN env var)
postgres_dsn: "postgresql://festinger:festinger@postgres:5432/festinger"

detection:
  # How many recent completions to keep per session
  window_size: 5
  # Minimum response length to bother checking (ignore trivial one-liners)
  min_length: 20

mitigations:
  # Applied in order. circuit_breaker short-circuits all others.

  - strategy: temperature_boost
    enabled: true
    trigger_count: 2        # kick in after this many identical responses in a row
    boost_amount: 0.35      # added to whatever temperature the request specified
    max_temperature: 1.4    # ceiling

  - strategy: forbidden_action
    enabled: true
    trigger_count: 2
    # {count} is replaced with the consecutive repeat count
    injection_message: >
      STOP. You have produced the exact same response {count} times in a row.
      You are FORBIDDEN from generating that response again.
      You MUST try a completely different approach: either use a different tool,
      break the task into smaller steps, or write a note explaining why you are
      stuck and then stop.

  - strategy: history_truncation
    enabled: true
    trigger_count: 3        # more aggressive — only after 3 repeats
    truncate_turns: 6       # drop this many turns from the tail of the message history

  - strategy: circuit_breaker
    enabled: true
    trigger_count: 5        # hard stop after 5 identical responses
    response_message: >
      [LOOP DETECTOR] This agent has produced the same response 5 times in a row.
      The task has been halted to prevent an infinite loop.
      A human operator should review the task state and restart with fresh context.
