"""Configuration for the agentic extraction loop.

Every tunable lever lives here. Pass AgentConfig to the session runner
to control model choice, iteration limits, scoring thresholds, lint rules, etc.
"""

from __future__ import annotations

from dataclasses import dataclass, field


@dataclass
class AgentConfig:
    # ── Agent LLM ──────────────────────────────────────────────────────────
    model: str = "claude-sonnet-4-6"
    temperature: float = 0.0
    max_tokens: int = 16384

    # ── Gold generation ────────────────────────────────────────────────────
    gold_model: str = "claude-sonnet-4-6"
    gold_mode: str = "vision"  # "vision" or "text"
    gold_temperature: float = 0.0

    # ── Loop control ───────────────────────────────────────────────────────
    max_iterations: int = 8
    target_score: float = 1.0  # stop if score >= this
    approach_shift_after: int = 2  # hint to shift approach after N same-category failures

    # ── Comparison thresholds ──────────────────────────────────────────────
    number_tolerance: float = 0.01  # relative tolerance for numeric comparison
    date_strict: bool = False  # if True, date format must match exactly
    fuzzy_threshold: float = 0.85  # string similarity threshold
    address_jaccard: float = 0.80  # token overlap for address comparison

    # ── Execution ──────────────────────────────────────────────────────────
    timeout_seconds: int = 120
    python_command: str = "python"  # or "uv run python"

    # ── Linting ────────────────────────────────────────────────────────────
    lint_rules: list[str] = field(
        default_factory=lambda: [
            "no_try_except",
            "no_data_values_in_selectors",
            "no_absolute_coordinates",
            "no_forbidden_imports",
            "no_llm_calls",
            "label_likeness",
            "schema_key_match",
        ]
    )
    lint_block_on_error: bool = True  # don't execute scripts with lint errors
    syntax_retries: int = 2  # cheap retries on syntax errors before counting as real iteration

    # ── Telemetry ──────────────────────────────────────────────────────────
    save_all_attempts: bool = True
    output_dir: str = "agentic/output"
