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.

Metadata

Release files for affect-kernel 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for affect-kernel 0.1.0
File Size Uploaded Provenance
affect_kernel-0.1.0.tar.gz 94.3 kB With provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for affect-kernel 0.1.0
File Interpreter ABI Platform
affect_kernel-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 131.2 kB

Release files / affect_kernel-0.1.0.tar.gz

Download URL affect_kernel-0.1.0.tar.gz
Size 94.3 kB
Tags Source
SHA-256 checksum
How to use checksums
a7b8145cfbc215baca33d09ce0380e0eea89511f60b5dfeec10f0615846d8944
BLAKE2b-256 checksum
How to use checksums
96846ab0b39bcdb394bc6e82e2352903803a5b41976e747a1171bebd8c315a3e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 21, 2026.

Transparency log

Release files / affect_kernel-0.1.0-py3-none-any.whl

Download URL affect_kernel-0.1.0-py3-none-any.whl
Size 36.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bb48ae31d492c595846b755388bf7bae14c75b051b5fde74789610e731d82b4d
BLAKE2b-256 checksum
How to use checksums
339c3c65eb47e3e41d31853490ab14bf344b0a5ddec8a97420252e27f748a095
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 21, 2026.

Transparency log

Security for affect-kernel 0.1.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 2 files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for affect_kernel-0.1.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 21, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files Full provenance

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