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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a7b8145cfbc215baca33d09ce0380e0eea89511f60b5dfeec10f0615846d8944
|
|
| MD5 |
23dff1743fa22928c4d81004c6e39b17
|
|
| BLAKE2b-256 |
96846ab0b39bcdb394bc6e82e2352903803a5b41976e747a1171bebd8c315a3e
|
Provenance
The following attestation bundles were made for affect_kernel-0.1.0.tar.gz:
Publisher:
release.yml on kevindechang/affect-kernel
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
affect_kernel-0.1.0.tar.gz -
Subject digest:
a7b8145cfbc215baca33d09ce0380e0eea89511f60b5dfeec10f0615846d8944 - Sigstore transparency entry: 2548787516
- Sigstore integration time:
-
Permalink:
kevindechang/affect-kernel@7552e988326bc45fbf075d8e8b433097f40b8fab -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/kevindechang
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@7552e988326bc45fbf075d8e8b433097f40b8fab -
Trigger Event:
push
-
Statement type:
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
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bb48ae31d492c595846b755388bf7bae14c75b051b5fde74789610e731d82b4d
|
|
| MD5 |
52380f8113d3902aaecbf970d479b389
|
|
| BLAKE2b-256 |
339c3c65eb47e3e41d31853490ab14bf344b0a5ddec8a97420252e27f748a095
|
Provenance
The following attestation bundles were made for affect_kernel-0.1.0-py3-none-any.whl:
Publisher:
release.yml on kevindechang/affect-kernel
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
affect_kernel-0.1.0-py3-none-any.whl -
Subject digest:
bb48ae31d492c595846b755388bf7bae14c75b051b5fde74789610e731d82b4d - Sigstore transparency entry: 2548787537
- Sigstore integration time:
-
Permalink:
kevindechang/affect-kernel@7552e988326bc45fbf075d8e8b433097f40b8fab -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/kevindechang
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@7552e988326bc45fbf075d8e8b433097f40b8fab -
Trigger Event:
push
-
Statement type: