Files
webber/webber-api/src/shared/config.py
T
jpmschweitzerandClaude Fable 5 1769ec2803 feat(backend): adapt every completion to the detected backend (workspace T-137)
One choke point in the sanitized client: the flavor is probed once
(the boilerroom wrapper names itself on /health, a bare llama-server
serves /props, Ollama answers neither) and every completion adapts.
The agents' tool_choice "required" survives only on Ollama — advisory
there, enforced by llama-server, an unbreakable tool loop through the
wrapper. Through the wrapper every completion carries webber's session
identity: session webber, eviction_order 20 in the decided ranking,
configurable via settings. The wrapper's balancing and compaction
signals are read from the response body's extra fields — an httpx
event-hook variant was tried and never fires under the openai SDK.

The enabling fix: the sanitized client was never in the request path.
The provider assigned self._openai_client, an attribute nobody reads —
OllamaProvider.client serves self._client — so every completion has
bypassed the null-content sanitizer since the class was introduced.
Exposed when the wrapper 503'd a session-less request the choke point
should have named; the client now goes through the constructor's
official openai_client parameter, and a wiring test pins
provider.client to the sanitized type. The same bug exists in tatlock
(its T-6, filed).

Verified against the live wrapper from the dev server: flavor
boilerroom detected, a tool-using explore run answered in 4.8 s with
no tool loop, webber resident at rank 20, and the wrapper parked
librarian and tatlock-experts to seat it — the ranking doing exactly
its job. Six new tests (227 green), five mutation-checked: the rank
default, the strip condition, the session-add condition, the
no-cache-on-failure rule, and the client wiring.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-09-13 10:02:14 +02:00

122 lines
3.8 KiB
Python

"""
Application configuration via Pydantic Settings.
All settings loaded from environment variables or .env file.
Project metadata (name, version, description) sourced from pyproject.toml.
"""
import tomllib
from dataclasses import dataclass
from functools import lru_cache
from pathlib import Path
from pydantic_settings import BaseSettings, SettingsConfigDict
@dataclass(frozen=True)
class ProjectMeta:
"""Project metadata from pyproject.toml (single source of truth)."""
name: str
version: str
description: str
def _load_project_meta() -> ProjectMeta:
"""Load project metadata from pyproject.toml."""
pyproject_path = Path(__file__).parent.parent.parent / "pyproject.toml"
try:
with open(pyproject_path, "rb") as f:
data = tomllib.load(f)
project = data.get("project", {})
return ProjectMeta(
name=str(project.get("name", "webber")).title(),
version=str(project.get("version", "0.0.0")),
description=str(project.get("description", "")),
)
except FileNotFoundError:
return ProjectMeta(name="Webber", version="0.0.0", description="")
PROJECT = _load_project_meta()
__version__ = PROJECT.version
class Settings(BaseSettings):
"""Application settings loaded from environment."""
# Application (from pyproject.toml)
app_name: str = PROJECT.name
app_version: str = PROJECT.version
app_description: str = PROJECT.description
debug: bool = False
# Server
host: str = "0.0.0.0"
port: int = 8086
# Logging
log_level: str = "INFO"
# CORS
cors_origins: list[str] = ["http://localhost:3000", "http://localhost:8080"]
cors_credentials: bool = True
cors_methods: list[str] = ["*"]
cors_headers: list[str] = ["*"]
# LLM - Ollama (always hot in VRAM on tower-of-joy)
ollama_url: str = "http://192.168.86.149:11434"
ollama_agent_model: str = "gemma4:e2b"
ollama_embed_model: str = "nomic-embed-text:latest"
# Session identity through the boilerroom wrapper (workspace T-137):
# rank 20 in the decided ordering — tatlock phases 40, experts 35,
# librarian 30, webber 20; lower parks sooner. The fields only mean
# something to the wrapper; Ollama and a bare llama-server ignore them.
backend_session_name: str = "webber"
backend_session_rank: int = 20
# Auth - Tatlock integration
tatlock_api_url: str | None = "http://tatlock:8000"
internal_api_key: str | None = None
# Web search - SearXNG (use SEARXNG_URL env var to override)
searxng_url: str = "http://searxng:8080"
searxng_timeout: int = 10
# Tool execution
tool_timeout_seconds: int = 120
sandbox_enabled: bool = True
allowed_paths: list[str] | None = None
# Database
database_url: str = "sqlite+aiosqlite:///./webber.db"
# Sessions & Context
session_ttl_hours: int = 24
max_context_tokens: int = 128000
summarization_threshold: float = 0.8 # Summarize at 80% of max tokens
summarization_target_tokens: int = 500 # Target summary size
keep_recent_messages: int = 6 # Messages to keep unsummarized (3 turns)
# Retry logic
retry_max_attempts: int = 3 # Max retry attempts for transient failures
retry_base_delay: float = 1.0 # Base delay in seconds
retry_max_delay: float = 30.0 # Maximum delay in seconds
model_config = SettingsConfigDict(
env_file=".env",
case_sensitive=False,
extra="ignore",
env_parse_none_str="", # Treat empty string as None
)
@property
def effective_allowed_paths(self) -> list[str]:
"""Return allowed_paths or empty list if None."""
return self.allowed_paths or []
@lru_cache
def get_settings() -> Settings:
"""Cached settings singleton."""
return Settings()