Skip to main content

affect-kernel for Python

This directory contains the zero-runtime-dependency Python implementation of the deterministic affect-state kernel for long-lived AI characters.

python -m pip install affect-kernel
from affect_kernel import AffectState, appraise_turn

state = AffectState()
result = appraise_turn(state, "CURIOSITY")
print(result.state.mood)

The repository README contains runnable headless examples, benchmark results, limitations, and the cross-runtime contract. From a source checkout, run ./scripts/setup.sh and ./scripts/check.sh at the repository root.

The package deliberately leaves model inference, persistence, and retrieval I/O behind injected protocols. Its cross-runtime guarantee covers deterministic, non-habituating affect, appraisal, memory scoring, and presence transforms only. Prompt wording is supplied by the caller and is not part of production parity.

Adapter security and transaction contract

AffectEngine sends trusted instructions in GenerateInput.system_prompt and bounded retrieved/carried evidence in GenerateInput.untrusted_context. Model adapters must place untrusted_context in a user/tool-data channel and obey its evidence-only rule; they must never concatenate it, GenerateInput.state, or retriever output into the system prompt. Gate, retrieval, and generation request states have carried_thought=None, so the carried text is available only through the explicit untrusted field on generation.

Gate failures and unsupported intents raise by default. Applications may opt in to gate_error_mode="respond" or "silent". Built-in intents are normalized to uppercase. A caller can register custom_intents; custom labels are also normalized, must match [A-Z][A-Z0-9_]{0,63}, and intentionally receive no built-in appraisal impulse.

Domain kernels can inject a synchronous AppraisalPolicy into AffectEngine. It receives an AppraisalPolicyInput containing the current state, normalized intent/event, message, and expectation, and must return an AppraisalResult. default_appraisal_policy explicitly preserves the reference English conversational mapping implemented by appraise_turn.

EngineLimits bounds each message (16,000 characters), loaded history (200 messages / 128,000 characters), assembled system prompt (128,000 characters), and buffered model output (32,000 characters) by default. Pass a replacement EngineLimits value to tighten those ceilings for your deployment. The engine checks an offending output chunk before invoking its token callback or committing the turn.

Stores implement StateStore.transaction(conversation_id). That context must serialize the complete turn for the conversation across every engine instance, and its ConversationTransaction.commit(...) must atomically persist the state update and message batch. If gate, retrieval, generation, a token callback, or cancellation fails before commit, the store must leave both state and transcript unchanged. InMemoryStateStore is the dependency-free reference implementation.

Download files

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

Source Distribution

affect_kernel-0.1.0.tar.gz (94.3 kB view details)

Uploaded Source

Built Distribution

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

affect_kernel-0.1.0-py3-none-any.whl (36.9 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: affect_kernel-0.1.0.tar.gz
  • Upload date:
  • Size: 94.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for affect_kernel-0.1.0.tar.gz
Algorithm Hash digest
SHA256 a7b8145cfbc215baca33d09ce0380e0eea89511f60b5dfeec10f0615846d8944
MD5 23dff1743fa22928c4d81004c6e39b17
BLAKE2b-256 96846ab0b39bcdb394bc6e82e2352903803a5b41976e747a1171bebd8c315a3e

See more details on using hashes here.

Provenance

The following attestation bundles were made for affect_kernel-0.1.0.tar.gz:

Publisher: release.yml on kevindechang/affect-kernel

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

  • Download URL: affect_kernel-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 36.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for affect_kernel-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 bb48ae31d492c595846b755388bf7bae14c75b051b5fde74789610e731d82b4d
MD5 52380f8113d3902aaecbf970d479b389
BLAKE2b-256 339c3c65eb47e3e41d31853490ab14bf344b0a5ddec8a97420252e27f748a095

See more details on using hashes here.

Provenance

The following attestation bundles were made for affect_kernel-0.1.0-py3-none-any.whl:

Publisher: release.yml on kevindechang/affect-kernel

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page