fabricatio-context
Branch-based append-only prompt context for prefix-cache hits.
Overview
LLM providers cache prompts by exact token prefix. Composition code that interpolates request-specific content into the middle of a prompt invalidates the cache on every call. This package provides the shared data structure and capability for building prompts as stable heads plus cheap branches:
- [
ContextEntry] — one frozen block of composed context (kind/title/body). - [
ContextLog] — append-only sequence of frozen entries held in an immutable tuple:with_entry/with_entriesappend purely,branchforks history in O(1),clearhands out a fresh log,renderjoins bodies deterministically. - [
AssembleContext] — capability mixin: seed a stable head once, fork a per-request branch, append request-specific entries, render byte-stable text.
Identical logs always render byte-identical strings, so a rendered head is a cache-stable prefix across every request and every retry round.
fabricatio-novel uses this pattern for running manuscript context;
fabricatio-tool uses it to render execution feedback.
Usage
from fabricatio_context.capabilities.context import AssembleContext
from fabricatio_context.models.context import ContextEntry, ContextLog
class MyAgent(AssembleContext):
def context_head(self) -> ContextLog:
return ContextLog(entries=(
ContextEntry(kind="rules", title="Rules", body="You SHALL ..."),
))
agent = MyAgent()
branch = agent.branch_context()
branch = branch.with_entry(agent.make_entry("request", "Req", "Count the lines"))
prompt_tail = agent.render_context(branch)
License
MIT — see LICENSE
Metadata
Release files for fabricatio-context 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| fabricatio_context-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for fabricatio_context-0.1.0-py3-none-any.whl |
Release files / fabricatio_context-0.1.0-py3-none-any.whl
| Download URL | fabricatio_context-0.1.0-py3-none-any.whl |
|---|---|
| Size | 8.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2fd55e07b3dff089aa7cf2e0bb68706de012c3750f16db1d6b164e8187e10b8b
|
|
BLAKE2b-256 checksum How to use checksums |
be433fe98685c3029e9ab36a957a7efcf8dee05722b35793570ea9fab1ee6137
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for fabricatio-context 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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
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.
To learn more about protecting yourself from malicious actors, visit our package security documentation.