TrackerConfig

TrackerConfig is a Pydantic model that controls all aspects of the tracker. All parameters have sensible defaults.

Store Settings

ParameterTypeDefaultDescription
store_typestr"sqlite"Storage backend: "sqlite" or "redis"
store_kwargsdict{}Extra arguments passed to the store constructor (e.g. {"db_path": "beliefs.db"})

Detection Settings

ParameterTypeDefaultDescription
similarity_thresholdfloat0.82Minimum cosine similarity to consider beliefs related
contradiction_thresholdfloat0.70Minimum NLI score to flag as contradiction
entailment_thresholdfloat0.85Minimum NLI score to detect semantic duplicates

Resilience Settings

ParameterTypeDefaultDescription
retry_max_attemptsint5Maximum retry attempts for LLM API calls
retry_min_waitfloat2.0Minimum wait time between retries (seconds)
retry_max_waitfloat30.0Maximum wait time between retries (seconds)
retry_multiplierfloat2.0Exponential backoff multiplier
enable_circuit_breakerboolTrueEnable circuit breaker protection
circuit_breaker_failure_thresholdint5Failures before tripping the circuit breaker
circuit_breaker_recovery_timeoutfloat30.0Cooldown before recovery attempt (seconds)

Task & Dispatcher Settings

ParameterTypeDefaultDescription
enable_background_tasksboolTrueRun tracking in fire-and-forget background tasks
task_dispatcher_typestr"asyncio"Dispatcher: "asyncio", "sync", "celery", or "rq"
dispatcher_kwargsdict{}Arguments for dispatcher initialization

Belief Storage & Injection

ParameterTypeDefaultDescription
max_beliefsint50Maximum beliefs injected into prompts
belief_sort_strategystr"confidence_recency"Selection strategy: "confidence_recency", "recency", or "confidence"
enable_belief_ttlboolFalseEnable automatic belief pruning by age
belief_max_age_secondsint86400Max age before pruning (default: 24 hours)
enable_staleness_scoringboolTrueDeprioritize old beliefs during session resumption
staleness_thresholdfloat0.1Minimum staleness score to inject a belief
enable_token_aware_injectionboolTrueUse relevance filtering when beliefs exceed token budget
belief_budget_tokensint500Maximum tokens reserved for belief injection

Technical Mechanics & Calculations

1. Threshold Calibration

To avoid querying the expensive NLI judge on every single stored fact, BeliefState uses a two-tiered check:

  • Similarity Threshold (similarity_threshold): Checks the cosine similarity between the vector embeddings of the new fact and existing stored facts. If the similarity is below this value (default 0.82), the facts are deemed conceptually unrelated, and the NLI check is skipped.
  • Contradiction & Entailment Thresholds: The Natural Language Inference (NLI) model scores logical relation on a 0.0 to 1.0 scale:
    • If contradiction_score >= contradiction_threshold, the facts are treated as contradicting (e.g. "lives in London" vs. "lives in Paris").
    • If entailment_score >= entailment_threshold, the facts are duplicates (e.g. "likes Python" vs. "enjoys Python programming") and the new record is ignored or merged.

2. Staleness Decay Formula

When resuming an old conversation session, stale beliefs (e.g., intermediate tasks the user finished days ago) should not clutter the prompt context. If enable_staleness_scoring is active, each belief is rated using:

Staleness Score = Confidence / (Days Since Referenced + 1)

If the calculated score falls below the staleness_threshold (default 0.1), the belief is excluded from prompt context injection. If all beliefs are too stale, the tracker falls back to injecting the top 5 most confident, recent facts as a safety measure.

3. Token-Aware Relevance Filtering

To keep LLM API token consumption low, the tracker estimates the size of the formatted prompt using a fast character-based heuristic: 1 token ≈ 4 characters. If this estimated size exceeds belief_budget_tokens, relevance filtering is triggered:

  1. The current user query is embedded into a vector.
  2. All candidate beliefs for the session are ranked by the cosine similarity between their stored embedding and the query embedding.
  3. Beliefs are filled into the prompt from highest to lowest similarity, stopping as soon as the token budget is reached.

Custom Prompts

Override the built-in extraction or judge prompts via TrackerConfig:

pythonconfig = TrackerConfig(
    extract_prompt_template="""Extract beliefs from this text as JSON.
Return [{"subject": "...", "predicate": "...", "value": "...", "confidence": 0.0-1.0}]
Text: {response}""",

    judge_prompt_template="""Analyze these two claims.
Premise: {premise}
Hypothesis: {hypothesis}
Return {"relationship": "contradiction|entailment|neutral", "score": 0.0-1.0}"""
)

ℹ️ Note: The extraction prompt must include the {response} placeholder. The judge prompt must include {premise} and {hypothesis} placeholders.