Skip to main content

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_entries append purely, branch forks history in O(1), clear hands out a fresh log, render joins 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)

Table of built distributions (wheels) for fabricatio-context 0.1.0
File Interpreter ABI Platform
fabricatio_context-0.1.0-py3-none-any.whl Python 3 none any Details

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}

Release history Release notifications | RSS feed

This release

0.1.0 This release

1 release file

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