Skip to main content

Tri-State Cognitive Engine — Kleene logic × Bayesian confidence × safety gating

Project description

Ternary Engine

Tri-State Cognitive Computing Framework — Kleene logic × Bayesian confidence × safety gating.

from ternary_engine import TernaryEngine

engine = TernaryEngine(max_hesitation=3, min_gain=0.05)

# Step 1: Agent analyzes file
trit, conf, gate, cog = engine.step("analyze", "37 functions, 40 imports")
print(f"[{cog}]→ {engine.trit_display(trit, conf)}")  # [AFFIRM]→ 真 ●●● [0.81]

# Step 2: Replace fails
trit, conf, gate, cog = engine.step("replace_in_file", "未找到")
print(engine.summary())  # 假(0.34)

# Step 3: Fix and retry
trit, conf, gate, cog = engine.step("replace_in_file", "已替换 1 处")
print(engine.trit_display(trit, conf))  # 假 ●●● [0.20]

Quick Start

pip install ternary-engine

How It Works

Event → classify(AFFIRM/NEGATE/UNCERT)
      → map to trit (-1/0/1)
      → Kleene logic propagation (upstream × current)
      → Bayesian confidence decay (upstream_conf × current_conf)
      → protection gating (high risk + uncertain = block)
      → decision

Use Cases

  • AI Agents: gate LLM tool calls with confidence
  • IoT Sensors: accumulate unreliable readings before acting
  • Village NPCs: propagate trust through social networks
  • Risk Assessment: block high-risk operations when uncertain

API

TernaryEngine(max_hesitation=3, min_gain=0.05)

engine.step(tool, result, risk='低')  (trit, conf, gate, cog)
engine.classify(tool, result)          cog_state
engine.propagate(upstream, current)    propagated_trit
engine.confidence(cog, tool)           confidence_score
engine.protect(risk, trit, conf)       gate_action
engine.summary()                       "真(0.81)"
engine.trit_display(trit, conf)        "真 ●●● [0.81]"

MIT License. Zero dependencies.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

ternary_engine-0.1.0.tar.gz (3.9 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

ternary_engine-0.1.0-py3-none-any.whl (4.0 kB view details)

Uploaded Python 3

File details

Details for the file ternary_engine-0.1.0.tar.gz.

File metadata

  • Download URL: ternary_engine-0.1.0.tar.gz
  • Upload date:
  • Size: 3.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.13

File hashes

Hashes for ternary_engine-0.1.0.tar.gz
Algorithm Hash digest
SHA256 ec2826a115a1c2d6237ae7911642813743d147f926a282634d75ab12afef0efd
MD5 8dc3c15ee97918e0f13a39bb7acae4a5
BLAKE2b-256 4440434398f1f2836af7d2e39f1e0c88918eae6a747ad369d61c14e0317a7c20

See more details on using hashes here.

File details

Details for the file ternary_engine-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: ternary_engine-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.13

File hashes

Hashes for ternary_engine-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4d1f6a4dbbe9198d2e56cc3265a8bf7678c1c181147d72b2ad6ea83d54c37feb
MD5 8ebba4fdd72232e2c4dc46ad1fb84555
BLAKE2b-256 1b051887e4803af239a19d46a6488ceecb12d1089b60d7b1de90274a58496acb

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page